Ask Your Question
0

HEAT syntax for multiple fixed_ips as a parameter

asked 2016-08-02 18:11:44 -0600

domc gravatar image

I am trying to create a HEAT template that will use 'allowed_address_pairs' and neutron ports to support the concept of a virtual IP address shared between instances for an application similar to VRRP.

I've followed the examples from http://superuser.openstack.org/articles/implementing-high-availability-instances-with-neutron-using-vrrp (http://superuser.openstack.org/articl...) and from https://github.com/nvpnathan/heat/blob/master/allowed-address-pairs.yaml (https://github.com/nvpnathan/heat/blo...) to come up with my own template to achieve this, and it works great for a single virtual IP address.

Here is what that template looks like:

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] }

So far so good. Now I need to take this to the next level and assign multiple IP addresses that can be used as virtual IPs within an instance. The problem is that it is not known in advance how many will be needed when the instance is launched, so it needs to be a parameter and cannot simply be hard-coded as

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

In other words, the parameter test_virtual_ip needs to be a list of IP addresses rather than a single IP address, e.g. "191.168.10.101 ... (more)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-08-03 13:36:12 -0600

domc gravatar image

The approach I was able to get working uses the repeat and for_each defined in the documentation at http://docs.openstack.org/developer/heat/template_guide/hot_spec.html#repeat (http://docs.openstack.org/developer/h...)

The applicable node definitions that need to be changed from the above template are:

  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%>

  instance1_test_vip_port:
    type: OS::Neutron::Port
    properties:
      admin_state_up: true
      network_id: { get_resource: test_net }
      allowed_address_pairs:
        repeat:
          for_each:
            <%ipaddr%>: {get_param: test_virtual_ip}
          template:
            ip_address: <%ipaddr%>
      security_groups:
        - default
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2016-08-02 18:11:44 -0600

Seen: 2,693 times

Last updated: Aug 03 '16