Description

This article shows a configuration example of creating a VN using a heat template.

Solution

A simple example of creating a virtual network by utilizing a customized heat template is shown below. The VN to be created is named " contrail_net1 ", with a single subnet of 10.1.1.0/24 , in project " admin ". The Contrail version used in this example is from 2011.  

A customized heat template is first created. The input parameters and resources to be created are defined in this yaml file.
In this example, " vn.yaml " is defined to create a VN with a single subnet.

heat_template_version: 2015-04-30

description: >
  HOT template to creates a virtual network with one subnet each. 
  set allow-transit, forwarding_mode and route-targets
parameters:
  private_net_1_name:
    type: string
    description: Name of private network to be created
  private_net_1_prefix:
    type: string
    description: Private network address prefix
  private_net_1_prefix_len:
    type: string
    description: Private network address prefix len
  allow_transit:
    type: boolean
    description: Private network allow transit
  forwarding_mode:
    type: string
    description: Private network forwarding_mode
  route_target_1:
    type: string
    description: Private network route-target
  route_target_2:
    type: string
    description: Private network route-target

resources:
  template_NetworkIpam_1:
    type: OS::ContrailV2::NetworkIpam
    properties:
      name: { get_param: private_net_1_name }

  template_VirtualNetwork_1:
    type: OS::ContrailV2::VirtualNetwork
    depends_on: [ template_NetworkIpam_1 ]
    properties:
      name: { get_param: private_net_1_name }
      virtual_network_properties:
        {
          virtual_network_properties_allow_transit: { get_param: allow_transit },
          virtual_network_properties_forwarding_mode: { get_param: forwarding_mode },
        }
      route_target_list:
        {
          route_target_list_route_target: [{ get_param: route_target_1 }, { get_param: route_target_2 }],
        }
      network_ipam_refs: [{ get_resource: template_NetworkIpam_1 }]
      network_ipam_refs_data:
        [{
          network_ipam_refs_data_ipam_subnets:
            [{
              network_ipam_refs_data_ipam_subnets_subnet:
                {
                  network_ipam_refs_data_ipam_subnets_subnet_ip_prefix: { get_param: private_net_1_prefix },
                  network_ipam_refs_data_ipam_subnets_subnet_ip_prefix_len: { get_param: private_net_1_prefix_len },
                },
            }]
         }]

The input parameters specific to the to-be-created VN can be defined in a .env file. Below is an example of a sample environment file named as " vn.env "

parameters:
  private_net_1_name: contrail_net1
  private_net_1_prefix: 10.1.1.0
  private_net_1_prefix_len: 24
  allow_transit: True
  forwarding_mode: l2_l3
  route_target_1: "target:55:12345"
  route_target_2: "target:66:23456"

The commands to create and verify contrail_net1 are as follows. The outputs show that contrail_net1  is successfully created.
Note: The following commands need to be run from overcloud (In Case of RHOSP).

  1. Create the stack using the openstack command which will create the Virtual network defined in template file and environment file as below:

    (overcloud) [stack@queensa ~]$ openstack stack create -e vn.env -t vn.yaml VN-stack
    +---------------------+-----------------------------------------------------------------------------------------------------------------------+
    | Field               | Value                                                                                                                 |
    +---------------------+-----------------------------------------------------------------------------------------------------------------------+
    | id                  | 0f2312e5-7357-459f-adf8-3c37338c164c                                                                                  |
    | stack_name          | VN-stack                                                                                                              |
    | description         | HOT template to creates a virtual network with one subnet each.  set allow-transit, forwarding_mode and route-targets |
    |                     |                                                                                                                       |
    | creation_time       | 2022-03-10T11:55:22Z                                                                                                  |
    | updated_time        | None                                                                                                                  |
    | stack_status        | CREATE_IN_PROGRESS                                                                                                    |
    | stack_status_reason | Stack CREATE started                                                                                                  |
    +---------------------+-----------------------------------------------------------------------------------------------------------------------+
    (overcloud) [stack@queensa ~]$ 
  2. Verify if the stack is created successfully.

    (overcloud) [stack@queensa ~]$ openstack stack list
    +--------------------------------------+------------+----------------------------------+-----------------+----------------------+--------------+
    | ID                                   | Stack Name | Project                          | Stack Status    | Creation Time        | Updated Time |
    +--------------------------------------+------------+----------------------------------+-----------------+----------------------+--------------+
    | 0f2312e5-7357-459f-adf8-3c37338c164c | VN-stack   | e8008fa5a9294ab7881cf9137120a647 | CREATE_COMPLETE | 2022-03-10T11:55:22Z | None         |
    +--------------------------------------+------------+----------------------------------+-----------------+----------------------+--------------+
    (overcloud) [stack@queensa ~]$ 
  3. Verify the details of the stack created.

    (overcloud) [stack@queensa ~]$ openstack stack show 0f2312e5-7357-459f-adf8-3c37338c164c
    +-----------------------+-------------------------------------------------------------------------------------------------------------------------+
    | Field                 | Value                                                                                                                   |
    +-----------------------+-------------------------------------------------------------------------------------------------------------------------+
    | id                    | 0f2312e5-7357-459f-adf8-3c37338c164c                                                                                    |
    | stack_name            | VN-stack                                                                                                                |
    | description           | HOT template to creates a virtual network with one subnet each.  set allow-transit, forwarding_mode and route-targets   |
    |                       |                                                                                                                         |
    | creation_time         | 2022-03-10T11:55:22Z                                                                                                    |
    | updated_time          | None                                                                                                                    |
    | stack_status          | CREATE_COMPLETE                                                                                                         |
    | stack_status_reason   | Stack CREATE completed successfully                                                                                     |
    | parameters            | OS::project_id: e8008fa5a9294ab7881cf9137120a647                                                                        |
    |                       | OS::stack_id: 0f2312e5-7357-459f-adf8-3c37338c164c                                                                      |
    |                       | OS::stack_name: VN-stack                                                                                                |
    |                       | allow_transit: 'True'                                                                                                   |
    |                       | forwarding_mode: l2_l3                                                                                                  |
    |                       | private_net_1_name: contrail_net1                                                                                       |
    |                       | private_net_1_prefix: 10.1.1.0                                                                                          |
    |                       | private_net_1_prefix_len: '24'                                                                                          |
    |                       | route_target_1: target:55:12345                                                                                         |
    |                       | route_target_2: target:66:23456                                                                                         |
    |                       |                                                                                                                         |
    | outputs               | []                                                                                                                      |
    |                       |                                                                                                                         |
    | links                 | - href: http://10.2.0.164:8004/v1/e8008fa5a9294ab7881cf9137120a647/stacks/VN-stack/0f2312e5-7357-459f-adf8-3c37338c164c |
    |                       |   rel: self                                                                                                             |
    |                       |                                                                                                                         |
    | parent                | None                                                                                                                    |
    | disable_rollback      | True                                                                                                                    |
    | deletion_time         | None                                                                                                                    |
    | stack_user_project_id | d15ebbc8e0d847f2899586a2d66f11b8                                                                                        |
    | capabilities          | []                                                                                                                      |
    | notification_topics   | []                                                                                                                      |
    | stack_owner           | None                                                                                                                    |
    | timeout_mins          | None                                                                                                                    |
    | tags                  | None                                                                                                                    |
    +-----------------------+-------------------------------------------------------------------------------------------------------------------------+
    (overcloud) [stack@queensa ~]$
  4. Verify if the virtual network defined in the environment file is created.

    (overcloud) [stack@queensa ~]$ openstack network show contrail_net1
    +---------------------------+--------------------------------------+
    | Field                     | Value                                |
    +---------------------------+--------------------------------------+
    | admin_state_up            | UP                                   |
    | availability_zone_hints   | None                                 |
    | availability_zones        | None                                 |
    | created_at                | None                                 |
    | description               | None                                 |
    | dns_domain                | None                                 |
    | id                        | 61aa93a0-40e0-4f73-b106-3eb3c80a880c |
    | ipv4_address_scope        | None                                 |
    | ipv6_address_scope        | None                                 |
    | is_default                | None                                 |
    | is_vlan_transparent       | None                                 |
    | mtu                       | None                                 |
    | name                      | contrail_net1                        |
    | port_security_enabled     | True                                 |
    | project_id                | e8008fa5a9294ab7881cf9137120a647     |
    | provider:network_type     | None                                 |
    | provider:physical_network | None                                 |
    | provider:segmentation_id  | None                                 |
    | qos_policy_id             | None                                 |
    | revision_number           | None                                 |
    | router:external           | Internal                             |
    | segments                  | None                                 |
    | shared                    | False                                |
    | status                    | ACTIVE                               |
    | subnets                   | 81cb2287-ec92-4ad2-99cf-e8e19ace570b |
    | tags                      |                                      |
    | updated_at                | None                                 |
    +---------------------------+--------------------------------------+
    (overcloud) [stack@queensa ~]$ 


Required Virtual network is successfully created using the heat templates.