Ask Your Question
0

Create Multiple instance with fixed IP and port in openstack using heat template

asked 2019-08-25 14:43:21 -0500

Rajviva gravatar image

Create Multiple instance with fixed IP and port in openstack using heat template

I want to create 3 instance/vm with a specific network and fixed ip. idea is to create more than 100 vm. To make dynamic heat-template i need this so that i can make few changes. I tried making the heat template but facing issue in port and ip-allocation to that port. heat_template_version: '2016-04-08'

ERROR---->{u'fixed_ips': [{u'ip_address': u''}] ERROR: ValueError: : resources.sm_instance_group.resources.0.resources.sm_instance: : "{u'sm_oam_port': {u'type': u'OS::Neutron::Port', u'properties': {u'fixed_ips': [{u'ip_address': u''}], u'network': u'4a4e40f5-1c53-4089-85e6-5fa1d7706530', u'name': u'sm_oam_port0'}}}" is not a list

#ENV file
parameters:
  sm_flavor: sm_capacity
  sm_availability_zone: performance-zone
  sm_image: 042386c6-0230-4a72-9255-ecb52fd0ec1d
  sm_net_oam: 4a4e40f5-1c53-4089-85e6-5fa1d7706530 ### 193.168.11.x
  sm_subnet_oam: 569a78c5f2334da3a7132d3d35cabc44 ### 193.168.11.x
  sm_oam_ip: ["193.168.11.185", "193.168.11.186", "193.168.11.187"]

#Template file
description: for SM cluster test, SM2-Node1,SM2-Node2,SM2-Node3 in one template
heat_template_version: '2016-04-08'
parameters:
  sm_flavor: {description: Flavor to use for servers, type: string}
  sm_availability_zone: {description: Name of availability_zone to use for servers, type: string}
  sm_image: {description: Name of image to use for servers, type: string}
  sm_net_oam: {description: ID of Neutron network into which servers get deployed, type: string}
  sm_subnet_oam: {description: ID of Neutron network into which servers get deployed, type: string}
  sm_oam_ip:
    type: comma_delimited_list
    default: ['193.168.11.185', '193.168.11.186', '193.168.11.187']

resources:
  sm_instance_group:
    type: OS::Heat::ResourceGroup
    properties:
      count: 3
      resource_def:
        type: sm_port.yaml
        properties:
          sm_vm_name: SM-%index%
          sm_oam_port_name: sm_oam_port%index%
          sm_oam_ip_index: { get_param: [sm_oam_ip, index] }
          sm_net_oam: { get_param: sm_net_oam }
          sm_subnet_oam: { get_param: sm_subnet_oam }
          sm_image: {get_param: sm_image}
          sm_availability_zone: {get_param: sm_availability_zone}
          sm_flavor: {get_param: sm_flavor}

#sm_port.yaml
description: for SM cluster test, SM2-Node1,SM2-Node2,SM2-Node3 in one template
heat_template_version: '2016-04-08'

  parameters:
    sm_flavor: {description: Flavor to use for servers, type: string}
    sm_availability_zone: {description: Name of availability_zone to use for servers, type: string}
    sm_image: {description: Name of image to use for servers, type: string}
    sm_vm_name: {type: string}
    sm_oam_port_name: {type: string}
    sm_oam_ip_index: {type: string}

    sm_net_oam: {description: ID of Neutron network into which servers get deployed, type: string}
    sm_subnet_oam: {description: ID of Neutron network into which servers get deployed, type: string}


  resources:
    sm_instance:
      type: OS::Nova::Server
      properties:
        flavor: {get_param: sm_flavor}
        availability_zone: {get_param: sm_availability_zone}
        name: {get_param: sm_vm_name}
        image: {get_param: sm_image}
        networks:
          sm_oam_port:
            type: OS::Neutron::Port
            properties:
              network: { get_param: sm_net_oam }
              name: { get_param: sm_oam_port_name }
              fixed_ips: 
              - { "ip_address": {get_param: sm_oam_ip_index }}
        config_drive: true
        user_data_format: RAW
        user_data:
          str_replace:
            template: {get_file: ud1}
            params:
        name: { get_param: sm_oam_port_name }
edit retag flag offensive close merge delete

Comments

I think you need percent characters around index in this line:

sm_oam_ip_index: { get_param: [sm_oam_ip, index] }
Bernd Bausch gravatar imageBernd Bausch ( 2019-08-25 16:23:54 -0500 )edit

tried that as well

found character '%' that cannot start any token in "<unicode string="">", line 23, column 53: ... index: { get_param: [sm_oam_ip, %index%] }

Rajviva gravatar imageRajviva ( 2019-08-26 13:02:37 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-08-26 16:18:00 -0500

zaneb gravatar image

updated 2019-09-05 10:19:39 -0500

Because intrinsic functions are evaluated before index substitution, you can only select the IP by index inside the sm_port.yaml template. So you need to add another parameter index to sm_port.yaml and pass it along with the full list of IPs like this:

          index: "%index%"
          sm_oam_ip: {get_param: sm_oam_ip}

then inside sm_port.yaml you can select the right IP by doing:

              fixed_ips:
                - {ip_address: {get_param: sm_oam_ip, {get_param: index}}}
edit flag offensive delete link more

Comments

Agree with your approach. But problem i am facing is same. how to avoid this error.What is the correct way to use it.

index: %index%

found character '%' that cannot start any token in "<unicode string="">", line 21, column 21: index: %index%

Rajviva gravatar imageRajviva ( 2019-08-27 12:28:56 -0500 )edit

Sorry, forgot that yaml requires you to quote the string when it begins with %. Fixed now.

zaneb gravatar imagezaneb ( 2019-09-05 10:20:16 -0500 )edit

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: 2019-08-25 14:43:21 -0500

Seen: 517 times

Last updated: Sep 05