Showing posts with label Subnet. Show all posts
Showing posts with label Subnet. Show all posts

Thursday, October 19, 2017

OpenStack Orchestration Heat to create a Subnet in a given Network OpenStack Newton


OpenStack Orchestration Heat to create a Subnet in a given Network 


Here is how to have a subnet using the heat stack.


---

Creation of the subnet using the heat stack 


Here is the stack to create the subnet



[root@newtonallinone HeatOrchestrationTemplates(keystone_admin)]# cat 05subnet.yml
---
# for Newton release of OpenStack
#
heat_template_version: 2016-10-14

description:  having a private subnet in a private network

resources:
  subnet:
    type: OS::Neutron::Subnet
    properties:
      cidr: '192.168.201.0/24'
      name: internalsubnet1
      enable_dhcp: true
      ip_version: 4
      allocation_pools:
        - { start: 192.168.201.5, end: 192.168.201.254 }
      network: internal1

outputs:
  subnet_info:
    value: { get_attr: [subnet]}
[root@newtonallinone HeatOrchestrationTemplates(keystone_admin)]#

  
----



  • Create the stack using the above YAML file to create a subnet in the network 'internal1'.
  • The subnet will be named as 'internalsubnet1'
  • The Subnet name is 'internalsubnet1'
  • The Subnet CIDR is 192.168.201.0/24
  • The Allocation Pool range start:ebdis 192.168.201.5-192.168.205.254


---


Create the stack


[root@newtonallinone HeatOrchestrationTemplates(keystone_admin)]# openstack stack create -t 05subnet.yml internalsubnet_1
+---------------------+----------------------------------------------+
| Field               | Value                                        |
+---------------------+----------------------------------------------+
| id                  | b1fe49e0-01d1-4df8-9a15-9243f31b7055         |
| stack_name          | internalsubnet_1                             |
| description         | having a private subnet in a private network |
| creation_time       | 2017-10-19T21:01:47Z                         |
| updated_time        | None                                         |
| stack_status        | CREATE_IN_PROGRESS                           |
| stack_status_reason | Stack CREATE started                         |
+---------------------+----------------------------------------------+
[root@newtonallinone HeatOrchestrationTemplates(keystone_admin)]#


---

See that the stack is created 


[root@newtonallinone HeatOrchestrationTemplates(keystone_admin)]# openstack stack list | grep -i internalsubnet_1
| b1fe49e0-01d1-4df8-9a15-9243f31b7055 | internalsubnet_1  | CREATE_COMPLETE | 2017-10-19T21:01:47Z | None         |
[root@newtonallinone HeatOrchestrationTemplates(keystone_admin)]#


--

Confirm that the subnet has been created also see the subnet using openstack subnet show


[root@newtonallinone HeatOrchestrationTemplates(keystone_admin)]# openstack subnet show internalsubnet1
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| allocation_pools  | 192.168.201.5-192.168.201.254        |
| cidr              | 192.168.201.0/24                     |
| created_at        | 2017-10-19T21:01:48Z                 |
| description       |                                      |
| dns_nameservers   |                                      |
| enable_dhcp       | True                                 |
| gateway_ip        | 192.168.201.1                        |
| host_routes       |                                      |
| id                | 9480b504-db1f-4f05-97b6-4058c7b168c9 |
| ip_version | 4                            |
| ipv6_address_mode | None                                 |
| ipv6_ra_mode      | None                                 |
| name              | internalsubnet1                      |
| network_id        | 216e5f0c-e0ed-4c04-b912-37c6967a0038 |
| project_id        | 49b25ce4022c492fa0c1eab4fc6c7419     |
| project_id        | 49b25ce4022c492fa0c1eab4fc6c7419     |
| revision_number   | 2                                    |
| service_types     | []                                   |
| subnetpool_id     | None                                 |
| updated_at        | 2017-10-19T21:01:48Z                 |
+-------------------+--------------------------------------+

OpenStack Orchestration to Add the subnet created to the Router interface.

OpenStack Orchestration to Add the subnet created to the Router interface.


  • Please note that there is already a router that hasbeen there as 'router'
  • This adds the subnet to the router so that the router 'router' can be used to route the traffic from the VMs in this network to the external network



---

The Stack file to add an interface to the router 'router' is as follows 

[root@newtonallinone HeatOrchestrationTemplates(keystone_admin)]# cat 06Routerinterfaceadd.yml
---
# for Newton release of OpenStack
#
heat_template_version: 2016-10-14

description: put the subnet to the router

resources:
  router_interface:
    type: OS::Neutron::RouterInterface
    properties:
      router: router
      subnet: internalsubnet1

outputs:
  subnet_info:
    value: { get_attr: [router_interface]}
[root@newtonallinone HeatOrchestrationTemplates(keystone_admin)]#


---

The above stack definition will add the subnet 'internalsubnet1' to the router 'router'.

--

Stack 


openstak stack create -t 06Routerinterfaceadd.yml routerinterfaceaddinternalsubnet1

[root@newtonallinone HeatOrchestrationTemplates(keystone_admin)]# openstack stack create -t 06Routerinterfaceadd.yml routerinterfaceaddinternalsubnet1
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| id                  | 164f98d6-57da-4a59-a863-0c29bae587c1 |
| stack_name          | routerinterfaceaddinternalsubnet1    |
| description         | put the subnet to the router         |
| creation_time       | 2017-10-19T21:08:27Z                 |
| updated_time        | None                                 |
| stack_status        | CREATE_IN_PROGRESS                   |
| stack_status_reason | Stack CREATE started                 |
+---------------------+--------------------------------------+
[root@newtonallinone HeatOrchestrationTemplates(keystone_admin)]#


--


the stack creation shows complete 

Lets ensure that the Router has now an interface added from the 'internalsubnet1' subnet



---


[root@newtonallinone HeatOrchestrationTemplates(keystone_admin)]# neutron router-port-list router
+--------------------------------------+------+-------------------+--------------------------------------------------------------------------------------+
| id                                   | name | mac_address       | fixed_ips                                                                            |
+--------------------------------------+------+-------------------+--------------------------------------------------------------------------------------+
| 28c89ce2-4861-4dfc-bbf3-fae2bd0bf0d7 |      | fa:16:3e:91:54:0e | {"subnet_id": "9480b504-db1f-4f05-97b6-4058c7b168c9", "ip_address": "192.168.201.1"} |
| e035d8d8-de23-420b-a655-1d3afc0f1bb5 |      | fa:16:3e:fa:73:3c | {"subnet_id": "d8e83610-7b77-4683-abc5-0cf3b6186395", "ip_address": "172.16.101.9"}  |
| e69fe0ef-9535-418c-b60b-138abd9bc899 |      | fa:16:3e:9d:c2:d5 | {"subnet_id": "7206c8e9-64ca-4ba1-abef-12639820fd37", "ip_address": "192.168.11.1"}  |
+--------------------------------------+------+-------------------+--------------------------------------------------------------------------------------+
[root@newtonallinone HeatOrchestrationTemplates(keystone_admin)]#


---

This shows that a port from the internal Subnet internalsubnet1 with the IP address 192.168.202.1 has been added to the router