Ask Your Question
0

Need to get ip of a port in HOT template

asked 2014-09-03 15:46:06 -0600

Heather gravatar image

updated 2014-09-04 07:54:32 -0600

I've tried numerous methods to pull in the IP address from a port on a vm without success.

Here is a snippet of the HOT doc.

The bolded part of the code is part that is not working. If I put a literal in there it will work fine. I'm new to Python so there may be some nuance of that I'm not understanding.

The spec for get_attr is:

get_attr: - <resource id=""> - <attribute name=""> - <key index="" 1=""> (optional) - <key index="" 2=""> (optional) - ...

Is the resource id the resource name in this case? wmwcvm1_port or is it the actual uuid of the resource? If it is the uuid can I use get_resource to pull that in because I won't know that value at run time?

I'm assuming the attribute name to be fixed_ips. I wrote some python code to pull the fixed_ip's out to take a look. This is what the API returns on a neutron list_ports() call:

fixed_ips : [{u'subnet_id': u'd4714185-cab2-4c5a-9d91-69a63f5dc063', u'ip_address': u'192.168.3.2'}]

  #############################################################
  # Define the VM and attach to the network
  #############################################################
  wmwcvm1:
    type: OS::Nova::Server
    metadata: http://haasaet.web.att.com/depot/deploy-chef-client.sh
    properties:
      name: wmwcvm1
      key_name: widgetco
      image: { get_param: image_id }
      flavor: { get_param: instance_type }
      networks:
        - port: { get_resource: wmwcvm1_port }
      user_data:
        str_replace:
          template: { get_file:  "http://haasaet.web.att.com/depot/hot-skel.sh" }
          params:
            $APP_HOST_IP_ENV: **{ get_attr: [ wmwcvm1_port, fixed_ips, ip_address, 0 ] }**
            $HOTSKEL2: { get_file:  "http://haasaet.web.att.com/depot/milestone2-run-recipe.sh" }

  wmwcvm1_port:
    type: OS::Neutron::Port
    properties:
      network_id: { get_param: zone1_id }
      fixed_ips:
        - subnet_id: { get_param: zone1_subnet_id }
      security_groups: [{ get_resource: server_security_group }]
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2014-09-04 08:11:40 -0600

larsks gravatar image

In the context of a Heat template, resource id referes to the name you have assigned the resource.

According to the documentation, a OS::Neutron::Port resource has an attribute fixed_ips that is a list of maps (aka "dictionaries"), each of which has a ip_address key. So, you want the ip_address key of the first item of the fixed_ips list:

$APP_HOST_IP_ENV: {get_attr: [wmwcvm1_port, fixed_ips, 0, ip_address}

Here's a simple working example:

heat_template_version: 2013-05-23

resources:

  my_port:
    type: "OS::Neutron::Port"
    properties:
      network_id: 18fc1b31-9b2c-4b6e-8dea-7e04bfd1eb43
      fixed_ips:
        - subnet_id: 55c6da11-cfbe-4443-bb5f-19c4d0ea041a

outputs:

  my_ip:
    value: {get_attr: [my_port, fixed_ips, 0, ip_address]}
edit flag offensive delete link more

Comments

That fixed it. I had the last two parameters reversed. Thank you.

Heather gravatar imageHeather ( 2014-09-04 09:30:29 -0600 )edit
0

answered 2016-08-22 06:02:23 -0600

NarasimhaSV gravatar image

resources: instance_port: type: OS::Neutron::Port properties: network: private fixed_ips: - subnet_id: "private-subnet"

instance1: type: OS::Nova::Server properties: flavor: m1.small image: ubuntu-trusty-x86_64 networks: - port: { get_resource: instance_port }

instance2: type: OS::Nova::Server properties: flavor: m1.small image: ubuntu-trusty-x86_64 networks: - network: private

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: 2014-09-03 15:46:06 -0600

Seen: 4,206 times

Last updated: Aug 22 '16