什么是多个fixed_ips的OpenStack HEAT语法作为参数

时间:2016-08-02 22:54:28

标签: openstack openstack-neutron

我正在尝试创建一个HEAT模板,该模板将使用'allowed_address_pairs'和中子端口来支持类似于VRRP的应用程序在实例之间共享的虚拟IP地址的概念。

我已经按照http://superuser.openstack.org/articles/implementing-high-availability-instances-with-neutron-using-vrrphttps://github.com/nvpnathan/heat/blob/master/allowed-address-pairs.yaml中的示例来提供我自己的模板来实现这一点,它适用于单个虚拟IP地址。

以下是该模板的样子:

heat_template_version: 2013-05-23

description: Simple template using allowed_address_pairs for a virtual IP

parameters:
  image:
    type: string
    label: Image name or ID
    description: Image to be used for compute instance
    default: "cirros"
  flavor:
    type: string
    label: Flavor
    description: Type of instance (flavor) to be used
    default: "t1.small"
  key:
    type: string
    label: Key name
    description: Name of key-pair to be used for compute instance
    default: "mykey"
  ext_network:
    type: string
    label: External network name or ID
    description: External network that can assign a floating IP
    default: "provider"
  test_virtual_ip:
    type: string
    label: Virtual IP address 
    description: Virtual IP address that can be used on different instances
    default: "192.168.10.101"


resources:
  # Create the internal test network
  test_net:
    type: OS::Neutron::Net
    properties:
      admin_state_up: true
      name: test_net

  # Create a subnet on the test network
  test_subnet:
    type: OS::Neutron::Subnet
    properties:
      name: test_subnet
      cidr: 192.168.10.2/24
      enable_dhcp: true
      allocation_pools: [{end: 192.168.10.99, start: 192.168.10.10}]
      gateway_ip: 192.168.10.1
      network_id: { get_resource: test_net }

  # Create router for the test network
  test_router:
    type: OS::Neutron::Router
    properties:
      admin_state_up: true
      name: test_router
      external_gateway_info: { "network": { get_param: ext_network }}

  # Create router interface and attach to subnet
  test_router_itf:
    type: OS::Neutron::RouterInterface
    properties:
      router_id: { get_resource: test_router }
      subnet_id: { get_resource: test_subnet }


  # Create extra port for a virtual IP address
  test_vip_port:
    type: OS::Neutron::Port
    properties:
      network_id: { get_resource: test_net }
      fixed_ips:
        - ip_address: { get_param: test_virtual_ip }


  # Create instance ports that have an internal IP and the virtual IP
  instance1_test_vip_port:
    type: OS::Neutron::Port
    properties:
      admin_state_up: true
      network_id: { get_resource: test_net }
      allowed_address_pairs:
        - ip_address: { get_param: test_virtual_ip}
      security_groups:
        - default

  # Create instances
  test_instance_1:
    type: OS::Nova::Server
    properties:
      name: instance1
      image: { get_param: image }
      flavor: { get_param: flavor }
      key_name: { get_param: key }
      networks:
        - port: { get_resource: instance1_test_vip_port }
      user_data_format: RAW
      user_data: |
        #cloud-config
        password: mysecret
        chpasswd: { expire: False }
        ssh_pwauth: True
        final_message: "The system is up after $UPTIME sec"

outputs:
  instance1_ip:
    description: IP address of the first instance
    value: { get_attr: [test_instance_1, first_address] }

到目前为止一切顺利。现在,我需要将其提升到一个新的水平,并分配多个IP地址,这些IP地址可用作实例中的虚拟IP。问题是事先不知道实例启动时需要多少,所以它需要是一个参数,不能简单地硬编码为

- ip_address: {get_param: ip1}
- ip_address: {get_param: ip2}
and so on

换句话说,参数 test_virtual_ip 需要是IP地址列表而不是单个IP​​地址,例如“191.168.10.101,192.168.10.102,192.168.10.103”

这会影响 test_vip_port instance1_test_vip_port 的定义,但我无法弄清楚正确的语法。

我试过了:

# Create extra port for a virtual IP address
  test_vip_port:
    type: OS::Neutron::Port
    properties:
      network_id: { get_resource: test_net }
      fixed_ips: [{ get_param: test_virtual_ip }]

  # Create instance ports that have an internal IP and the virtual IP
  instance1_test_vip_port:
    type: OS::Neutron::Port
    properties:
      admin_state_up: true
      network_id: { get_resource: test_net }
      allowed_address_pairs: [{ get_param: test_virtual_ip}]
      security_groups:
        - default

但是当我尝试启动堆栈时,得到错误“unicode对象没有属性获取”。

OS :: Neutron :: Port :: fixed_ips OS :: Neutron :: Port ::提供IP地址列表作为参数的正确语法是什么? allowed_address_pairs

1 个答案:

答案 0 :(得分:0)

我能够使用的唯一解决方案是使用repeat / for_each构造并将参数定义为comma_delimited_list,如下所示:

  test_virtual_ip:
    type: comma_delimited_list
    label: Virtual IP address
    description: Virtual IP address that can be used on different instances
    default: "192.168.10.101,192.168.10.102"

  test_vip_port:
    type: OS::Neutron::Port
    properties:
      network_id: { get_resource: test_net }
      fixed_ips:
        repeat:
          for_each:
            <%ipaddr%>: {get_param: test_virtual_ip}
          template:
            ip_address: <%ipaddr%>

有关此方法的一些细节:

  • 您的加热模板版本必须支持repeat / for_each结构,我使用的是heat_template_version:2016-04-08
  • 不要在IP地址列表中包含任何空格,否则您将收到验证错误。