Ask Your Question
0

How do you get a subnet from a nested template that creates a network?

asked 2014-10-22 08:31:18 -0500

Heather gravatar image

updated 2014-10-22 09:17:35 -0500

I've been struggling with this for a couple of days. It looks like it should be straightforward, but ...

What I am trying to do is create a parent template with two nested templates. The first nested template creates the network, subnet, etc. The second nested template creates a tomcat instance, does the software deployment, creates the port, etc. From the parent I first create the network and I want to back outputs from the nested network template and then pass those outputs to the nested tomcat template.

So here is the relevant parent code:

  NestZone1:
    type: zone_network.template
    properties:
      zone_name: nzone1
      cidr: 192.168.20.0/24
      gateway_ip: 192.168.20.1
      allocation_pools:
        "start": "192.168.20.2"
        "end": "192.168.20.254"
      shared_network: 'False'
      enable_dhcp: 'True'
      ip_version:
        get_param:  ip_ver
      dns_servers:
        get_param: dns_servers
      router_id:
        get_resource: Router
      tenant_network_id:
        get_param: tenant_net_id


  #######################
  # Tomcat Server
  #######################
  wmwcvm1:
    type: sprint9_tomcat_server.template
    properties:
      subnet_id: { get_attr: [ NestZone1, subnet_id, 0 ] }
      network: { get_attr: [ NestZone1, network_uuid ] }
      name: { get_param: tomcat_server_name }
      key_name: widgetco
      image: { get_param: image_id }
      flavor: { get_param: instance_type }
      chef_params: DEBUG
      user_data:
        str_replace:
          template: { get_file:  "http://haasaet.web.att.com/depot/hot-skel.sh" }
          params:
            $HOTSKEL1: { get_file:  "http://haasaet.web.att.com/depot/deploy-chef-client-as3525.sh" }

Here is the relevant portion of the nested network template:

  zone_network:
    type: OS::Neutron::Net
    properties:
      name:
        get_param: zone_name
      shared:
        get_param: shared_network
      tenant_id:
        get_param: tenant_network_id
      value_specs: {}

      zone_subnet:
        type: OS::Neutron::Subnet
        properties:
          name:
            str_replace:
              template:
                $subnet-subnet
              params:
                $subnet: { get_param: zone_name }
          network_id:
            get_resource: zone_network
          allocation_pools:
            - { get_param: allocation_pools }
          cidr:
            get_param: cidr
          dns_nameservers:
            get_param: dns_servers
          enable_dhcp:
            get_param: enable_dhcp
          gateway_ip:
            get_param: gateway_ip
          #host_routes: []
          ip_version:
            get_param: ip_version
          tenant_id:
            get_param: tenant_network_id
          value_specs: {}


      zone_interface:
        type: OS::Neutron::RouterInterface
        properties:
          router_id:
            get_param: router_id
          subnet_id:
            get_resource: zone_subnet

    outputs:
      network_name:
        description: Name of the network
        value: { get_attr: [zone_network, name] }
      subnet_id:
        description: Subnet for network
        value: { get_attr: [zone_network, subnets ] }
      network_uuid:
        description: Network UUID
        value: { get_attr: [zone_subnet, network_id] }

So in the outputs I pass back the subnets attribute of the net I created. From what I have read in the docs it should pass back subnets plain xsd:dict which are the associated subnets.

So if I look at the web services api for show network I assume it should contain something that looks like this example:

{

    "network": {
        "status": "ACTIVE",
        "subnets": [
            "54d6f61d-db07-451c-9ab3-b9609b6b6f0b"
        ],
        "name": "private-network",
        "provider:physical_network": null,
        "admin_state_up": true,
        "tenant_id": "4fd44f30292945e481c7b8a0c8908869",
        "provider:network_type": "local",
        "router:external": true,
        "shared": true,
        "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
        "provider:segmentation_id": null
    }
}

Subnets does not really look like a dict to me. It looks more like a list. I know from a previous question you can't pass lists as parameters. Does that also apply to lists not being able to pass back as outputs?

So the key pieces of the tomcat nested template looks like:

parameters:
  # declaration of input parameters

  network:
    type: string
    description: Network to deploy on

  subnet_id:
    type: string
    description: Subnet to deploy on

resources:

  #############################################################
  # Define the application server (Tomcat)
  #############################################################
  tomcat_server:
    type: OS::Nova::Server
    properties:
      key_name: { get_param:  key_name }
      image: { get_param: image }
      flavor: { get_param: flavor }
      networks:
        - port: { get_resource: server_port }
      user_data_format: RAW
      user_data: { get_param: user_data }

  tomcat_sw_config:
    type: OS::Heat::SoftwareConfig
    properties:
      inputs:
      - name: chefParam
        default: { get_param ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-12-21 00:53:23 -0500

cmyster gravatar image

Hi,

In the nested network template you need to return the net and the subnet ID.

The outputs of the nested_network template:

outputs:
  private_network_id:
    value: {get_resource: private_network}
  private_subnet_id:
    value: {get_resource: private_subnet}

In the parent template you need to pass those on to the nested server template (writing only the relevant parts here)

  type: nested_server.yaml                                              
    properties:                                                           
      private_network: {get_attr: [network, private_network_id]}          
      private_subnet: {get_attr: [network, private_subnet_id]}

And inside nested_server.yaml you need to declare those as parameters:

parameters:
  private_network:
    type: string
  private_subnet:
    type: string

To be used here:

resources:
  server_port:
    type: OS::Neutron::Port
    properties:
      network_id: { get_param: private_network }
      fixed_ips:
        - subnet_id: { get_param: private_subnet }

You would also need to make sure that the network part is created before the server part otherwise the attributes that you are trying to use are empty. To do this you can add in the parent template that the nested server depends_on the nested network.

edit flag offensive delete link more

Comments

Anybody who lands up here can follow this link -> https://developer.rackspace.com/blog/...

AB239 gravatar imageAB239 ( 2017-04-04 01:03:21 -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

2 followers

Stats

Asked: 2014-10-22 08:31:18 -0500

Seen: 2,535 times

Last updated: Dec 21 '14