SlideShare a Scribd company logo
1 of 18
OpenStack Heat
Virtual Private Cloud (VPC) Resources
1) List of VPC APIs implemented in Heat
a) CreateVPC == Create Virtual Network
b) CreateSubnet == Create Subnet in Virtual Network(VPC)
c) CreateInternetGateway == Get external network defined in the
Project
d) AttachInternetGateway == Connect external network to routers in
the Virtual Network(VPC)
e) CreateRouteTable == Create a router and attach to Virtual
Network(VPC)
f) AssociateRouteTable == Attach subnet to router
g) CreateEIP == Attach floating ip to instance
2) Resource
heat/heat/engine/resource.py
class Resource(object):
@scheduler.wrappertask
def create(self):
'''
Create the resource. Subclasses should provide a handle_create() method
to customise creation.
'''
@scheduler.wrappertask
def update(self, after, before=None, prev_resource=None):
'''
update the resource. Subclasses should provide a handle_update()
method
to customise update, the base-class handle_update will fail by default.
'''
def resource_id_set(self, inst):
self.resource_id = inst
OpenStack Training Videos
Play Training Videos
https://www.youtube.com/user/sajuptpm/videos
Continue ...
def action_handler_task(self, action, args=[], action_prefix=None):
'''
A task to call the Resource subclass's handler methods for an action.
Calls the handle_<ACTION>() method for the given action and then calls
the check_<ACTION>_complete() method with the result in a loop until it
returns True. If the methods are not provided, the call is omitted.
Any args provided are passed to the handler.
If a prefix is supplied, the handler method handle_<PREFIX>_<ACTION>()
is called instead.
'''
def physical_resource_name(self):
name = '%s-%s-%s' % (self.stack.name,
self.name,
short_id.get_id(self.id))
return name
def neutron(self):
return self.client('neutron')
3) VPC Resource
heat/heat/engine/resources/vpc.py
class VPC(resource.Resource):
PROPERTIES = (
CIDR_BLOCK, INSTANCE_TENANCY, TAGS,
) = (
'CidrBlock', 'InstanceTenancy', 'Tags',
)
properties_schema = { .... }
def handle_create(self):
client = self.neutron()
# The VPC's net and router are associated by having identical names.
net_props = {'name': self.physical_resource_name()}
router_props = {'name': self.physical_resource_name()}
net = client.create_network({'network': net_props})['network']
self.resource_id_set(net['id'])
client.create_router({'router': router_props})['router']
Continue ...
def check_create_complete(self, *args):
....
def handle_delete(self):
....
def resource_mapping():
return {
'AWS::EC2::VPC': VPC,
}
4) Subnet Resource
heat/heat/engine/resources/subnet.py
class Subnet(resource.Resource):
PROPERTIES = (
AVAILABILITY_ZONE, CIDR_BLOCK, VPC_ID, TAGS,
) = (
'AvailabilityZone', 'CidrBlock', 'VpcId', 'Tags',
)
properties_schema = { .... }
def handle_delete(self):
....
def resource_mapping():
return {
'AWS::EC2::Subnet': Subnet,
}
Continue ...
def handle_create(self):
client = self.neutron()
# TODO(sbaker) Verify that this CidrBlock is within the vpc CidrBlock
network_id = self.properties.get(self.VPC_ID)
props = {
'network_id': network_id,
'cidr': self.properties.get(self.CIDR_BLOCK),
'name': self.physical_resource_name(),
'ip_version': 4
}
subnet = client.create_subnet({'subnet': props})['subnet']
self.resource_id_set(subnet['id'])
router = vpc.VPC.router_for_vpc(self.neutron(), network_id)
if router:
client.add_interface_router(
router['id'],
{'subnet_id': subnet['id']})
5) RouteTable Resource
heat/heat/engine/resources/route_table.py
class RouteTable(resource.Resource):
PROPERTIES = (
VPC_ID, TAGS,
) = (
'VpcId', 'Tags',
)
properties_schema = { .... }
def handle_create(self):
client = self.client()
props = {'name': self.physical_resource_name()}
router = client.create_router({'router': props})['router']
self.resource_id_set(router['id'])
def resource_mapping():
return {
'AWS::EC2::RouteTable': RouteTable
}
6) SubnetRouteTableAssociation Resource
heat/heat/engine/resources/route_table.py
class SubnetRouteTableAssociation(resource.Resource):
PROPERTIES = (ROUTE_TABLE_ID, SUBNET_ID,) = ( 'RouteTableId', 'SubnetId',)
properties_schema = { .... }
def handle_create(self):
client = self.client()
subnet_id = self.properties.get(self.SUBNET_ID)
router_id = self.properties.get(self.ROUTE_TABLE_ID)
#remove the default router association for this subnet.
try:
previous_router = self._router_for_subnet(subnet_id)
if previous_router:
client.remove_interface_router(
previous_router['id'],
{'subnet_id': subnet_id})
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
client.add_interface_router(
router_id, {'subnet_id': subnet_id})
def resource_mapping():
return {
'AWS::EC2::SubnetRouteTableAssociation': SubnetRouteTableAssociation,
}
7) InternetGateway Resource
heat/heat/engine/resources/internet_gateway.py
class InternetGateway(resource.Resource):
PROPERTIES = (TAGS,) = ('Tags',)
properties_schema = { .... }
def handle_create(self):
self.resource_id_set(self.physical_resource_name())
@staticmethod
def get_external_network_id(client):
ext_filter = {'router:external': True}
ext_nets = client.list_networks(**ext_filter)['networks']
if len(ext_nets) != 1:
raise exception.Error(
_('Expected 1 external network, found %d') % len(ext_nets))
external_network_id = ext_nets[0]['id']
return external_network_id
def resource_mapping():
return {
'AWS::EC2::InternetGateway': InternetGateway,
}
8) VPCGatewayAttachment Resource
heat/heat/engine/resources/internet_gateway.py
class VPCGatewayAttachment(resource.Resource):
PROPERTIES = (
VPC_ID, INTERNET_GATEWAY_ID, VPN_GATEWAY_ID,
) = ( 'VpcId', 'InternetGatewayId', 'VpnGatewayId',)
properties_schema = { .... }
def handle_create(self):
client = self.neutron()
external_network_id = InternetGateway.get_external_network_id(client)
for router in self._vpc_route_tables():
client.add_gateway_router(router.resource_id, {
'network_id': external_network_id})
def resource_mapping():
return {
'AWS::EC2::VPCGatewayAttachment': VPCGatewayAttachment,
}
9) ElasticIp Resource
heat/heat/engine/resources/eip.py
class ElasticIp(resource.Resource):
PROPERTIES = (DOMAIN, INSTANCE_ID,) = ('Domain', 'InstanceId', )
properties_schema = { .... }
def handle_create(self):
"""Allocate a floating IP for the current tenant."""
ips = None
if self.properties[self.DOMAIN]:
from heat.engine.resources import internet_gateway
ext_net = internet_gateway.InternetGateway.get_external_network_id(self.neutron())
props = {'floating_network_id': ext_net}
ips = self.neutron().create_floatingip({
'floatingip': props})['floatingip']
self.ipaddress = ips['floating_ip_address']
self.resource_id_set(ips['id'])
instance_id = self.properties[self.INSTANCE_ID]
if instance_id:
server = self.nova().servers.get(instance_id)
server.add_floating_ip(self._ipaddress())
def resource_mapping():
return {
'AWS::EC2::EIP': ElasticIp,
}
10) ElasticIpAssociation Resource
heat/heat/engine/resources/eip.py
class ElasticIpAssociation(resource.Resource):
PROPERTIES = (
INSTANCE_ID, EIP, ALLOCATION_ID, NETWORK_INTERFACE_ID,
) = (
'InstanceId', 'EIP', 'AllocationId', 'NetworkInterfaceId',
)
properties_schema = { .... }
def handle_create(self):
"""Add a floating IP address to a server."""
if self.properties[self.EIP]:
server = self.nova().servers.get(self.properties[self.INSTANCE_ID])
server.add_floating_ip(self.properties[self.EIP])
self.resource_id_set(self.properties[self.EIP])
def resource_mapping():
return {
'AWS::EC2::EIPAssociation': ElasticIpAssociation,
}
11) VPC UnitTest
heat/heat/tests/test_vpc.py
class VPCTestBase(common.HeatTestCase):
class VPCTest(VPCTestBase):
class SubnetTest(VPCTestBase):
class NetworkInterfaceTest(VPCTestBase):
class InternetGatewayTest(VPCTestBase):
class RouteTableTest(VPCTestBase):
12) ElasticIp UnitTest
heat/heat/tests/test_eip.py
class EIPTest(common.HeatTestCase):
class AllocTest(common.HeatTestCase):
Thanks
● Email: sajuptpm@gmail.com
● Training Videos: https://www.youtube.com/user/sajuptpm/videos
● WebSite: http://fosshelp.blogspot.in
● IRC: saju_m
● Skype: sajuptpm

More Related Content

What's hot

What's hot (20)

OpenStack Architecture
OpenStack ArchitectureOpenStack Architecture
OpenStack Architecture
 
OVN - Basics and deep dive
OVN - Basics and deep diveOVN - Basics and deep dive
OVN - Basics and deep dive
 
Deploying CloudStack and Ceph with flexible VXLAN and BGP networking
Deploying CloudStack and Ceph with flexible VXLAN and BGP networking Deploying CloudStack and Ceph with flexible VXLAN and BGP networking
Deploying CloudStack and Ceph with flexible VXLAN and BGP networking
 
[2018] 오픈스택 5년 운영의 경험
[2018] 오픈스택 5년 운영의 경험[2018] 오픈스택 5년 운영의 경험
[2018] 오픈스택 5년 운영의 경험
 
Routed Fabrics For Ceph
Routed Fabrics For CephRouted Fabrics For Ceph
Routed Fabrics For Ceph
 
OpenShift Virtualization- Technical Overview.pdf
OpenShift Virtualization- Technical Overview.pdfOpenShift Virtualization- Technical Overview.pdf
OpenShift Virtualization- Technical Overview.pdf
 
Kvm and libvirt
Kvm and libvirtKvm and libvirt
Kvm and libvirt
 
OpenStack Quantum Intro (OS Meetup 3-26-12)
OpenStack Quantum Intro (OS Meetup 3-26-12)OpenStack Quantum Intro (OS Meetup 3-26-12)
OpenStack Quantum Intro (OS Meetup 3-26-12)
 
BGP Dynamic Routing and Neutron
BGP Dynamic Routing and NeutronBGP Dynamic Routing and Neutron
BGP Dynamic Routing and Neutron
 
Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...
Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...
Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...
 
Cilium - Bringing the BPF Revolution to Kubernetes Networking and Security
Cilium - Bringing the BPF Revolution to Kubernetes Networking and SecurityCilium - Bringing the BPF Revolution to Kubernetes Networking and Security
Cilium - Bringing the BPF Revolution to Kubernetes Networking and Security
 
Ceph issue 해결 사례
Ceph issue 해결 사례Ceph issue 해결 사례
Ceph issue 해결 사례
 
OpenStack Neutron behind the Scenes
OpenStack Neutron behind the ScenesOpenStack Neutron behind the Scenes
OpenStack Neutron behind the Scenes
 
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교 및 구축 방법
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교  및 구축 방법[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교  및 구축 방법
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교 및 구축 방법
 
Routed Provider Networks on OpenStack
Routed Provider Networks on OpenStack Routed Provider Networks on OpenStack
Routed Provider Networks on OpenStack
 
Contrail Deep-dive - Cloud Network Services at Scale
Contrail Deep-dive - Cloud Network Services at ScaleContrail Deep-dive - Cloud Network Services at Scale
Contrail Deep-dive - Cloud Network Services at Scale
 
Community Openstack 구축 사례
Community Openstack 구축 사례Community Openstack 구축 사례
Community Openstack 구축 사례
 
DPDK in Containers Hands-on Lab
DPDK in Containers Hands-on LabDPDK in Containers Hands-on Lab
DPDK in Containers Hands-on Lab
 
쿠버네티스 ( Kubernetes ) 소개 자료
쿠버네티스 ( Kubernetes ) 소개 자료쿠버네티스 ( Kubernetes ) 소개 자료
쿠버네티스 ( Kubernetes ) 소개 자료
 
TripleO Deep Dive
TripleO Deep DiveTripleO Deep Dive
TripleO Deep Dive
 

Similar to VPC Implementation In OpenStack Heat

What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012
D
 
Puppet and CloudStack
Puppet and CloudStackPuppet and CloudStack
Puppet and CloudStack
ke4qqq
 
Infrastructure as code with Puppet and Apache CloudStack
Infrastructure as code with Puppet and Apache CloudStackInfrastructure as code with Puppet and Apache CloudStack
Infrastructure as code with Puppet and Apache CloudStack
ke4qqq
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
FIWARE
 

Similar to VPC Implementation In OpenStack Heat (20)

10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
 
Microservices DevOps on Google Cloud Platform
Microservices DevOps on Google Cloud PlatformMicroservices DevOps on Google Cloud Platform
Microservices DevOps on Google Cloud Platform
 
Object Oriented Code RE with HexraysCodeXplorer
Object Oriented Code RE with HexraysCodeXplorerObject Oriented Code RE with HexraysCodeXplorer
Object Oriented Code RE with HexraysCodeXplorer
 
A Series of Fortunate Events: Building an Operator in Java
A Series of Fortunate Events: Building an Operator in JavaA Series of Fortunate Events: Building an Operator in Java
A Series of Fortunate Events: Building an Operator in Java
 
Javascript Application Architecture with Backbone.JS
Javascript Application Architecture with Backbone.JSJavascript Application Architecture with Backbone.JS
Javascript Application Architecture with Backbone.JS
 
Interoute Virtual Data Centre api 101
Interoute Virtual Data Centre api 101Interoute Virtual Data Centre api 101
Interoute Virtual Data Centre api 101
 
Serverless
ServerlessServerless
Serverless
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012
 
Working in the multi-cloud with libcloud
Working in the multi-cloud with libcloudWorking in the multi-cloud with libcloud
Working in the multi-cloud with libcloud
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
How to add a new hypervisor to CloudStack:Lessons learned from Hyper-V effort
How to add a new hypervisor to CloudStack:Lessons learned from Hyper-V effortHow to add a new hypervisor to CloudStack:Lessons learned from Hyper-V effort
How to add a new hypervisor to CloudStack:Lessons learned from Hyper-V effort
 
Puppet and CloudStack
Puppet and CloudStackPuppet and CloudStack
Puppet and CloudStack
 
Bring your infrastructure under control with Infrastructor
Bring your infrastructure under control with InfrastructorBring your infrastructure under control with Infrastructor
Bring your infrastructure under control with Infrastructor
 
Puppet and Apache CloudStack
Puppet and Apache CloudStackPuppet and Apache CloudStack
Puppet and Apache CloudStack
 
Infrastructure as code with Puppet and Apache CloudStack
Infrastructure as code with Puppet and Apache CloudStackInfrastructure as code with Puppet and Apache CloudStack
Infrastructure as code with Puppet and Apache CloudStack
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
 
Exploring MySQL Operator for Kubernetes in Python
Exploring MySQL Operator for Kubernetes in PythonExploring MySQL Operator for Kubernetes in Python
Exploring MySQL Operator for Kubernetes in Python
 
How to add a new hypervisor to CloudStack - Lessons learned from Hyper-V effort
How to add a new hypervisor to CloudStack - Lessons learned from Hyper-V effortHow to add a new hypervisor to CloudStack - Lessons learned from Hyper-V effort
How to add a new hypervisor to CloudStack - Lessons learned from Hyper-V effort
 
Crud operations using aws dynamo db with flask ap is and boto3
Crud operations using aws dynamo db with flask ap is and boto3Crud operations using aws dynamo db with flask ap is and boto3
Crud operations using aws dynamo db with flask ap is and boto3
 
Code Igniter 2
Code Igniter 2Code Igniter 2
Code Igniter 2
 

Recently uploaded

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 

VPC Implementation In OpenStack Heat

  • 1. OpenStack Heat Virtual Private Cloud (VPC) Resources
  • 2. 1) List of VPC APIs implemented in Heat a) CreateVPC == Create Virtual Network b) CreateSubnet == Create Subnet in Virtual Network(VPC) c) CreateInternetGateway == Get external network defined in the Project d) AttachInternetGateway == Connect external network to routers in the Virtual Network(VPC) e) CreateRouteTable == Create a router and attach to Virtual Network(VPC) f) AssociateRouteTable == Attach subnet to router g) CreateEIP == Attach floating ip to instance
  • 3. 2) Resource heat/heat/engine/resource.py class Resource(object): @scheduler.wrappertask def create(self): ''' Create the resource. Subclasses should provide a handle_create() method to customise creation. ''' @scheduler.wrappertask def update(self, after, before=None, prev_resource=None): ''' update the resource. Subclasses should provide a handle_update() method to customise update, the base-class handle_update will fail by default. ''' def resource_id_set(self, inst): self.resource_id = inst
  • 4. OpenStack Training Videos Play Training Videos https://www.youtube.com/user/sajuptpm/videos
  • 5. Continue ... def action_handler_task(self, action, args=[], action_prefix=None): ''' A task to call the Resource subclass's handler methods for an action. Calls the handle_<ACTION>() method for the given action and then calls the check_<ACTION>_complete() method with the result in a loop until it returns True. If the methods are not provided, the call is omitted. Any args provided are passed to the handler. If a prefix is supplied, the handler method handle_<PREFIX>_<ACTION>() is called instead. ''' def physical_resource_name(self): name = '%s-%s-%s' % (self.stack.name, self.name, short_id.get_id(self.id)) return name def neutron(self): return self.client('neutron')
  • 6. 3) VPC Resource heat/heat/engine/resources/vpc.py class VPC(resource.Resource): PROPERTIES = ( CIDR_BLOCK, INSTANCE_TENANCY, TAGS, ) = ( 'CidrBlock', 'InstanceTenancy', 'Tags', ) properties_schema = { .... } def handle_create(self): client = self.neutron() # The VPC's net and router are associated by having identical names. net_props = {'name': self.physical_resource_name()} router_props = {'name': self.physical_resource_name()} net = client.create_network({'network': net_props})['network'] self.resource_id_set(net['id']) client.create_router({'router': router_props})['router']
  • 7. Continue ... def check_create_complete(self, *args): .... def handle_delete(self): .... def resource_mapping(): return { 'AWS::EC2::VPC': VPC, }
  • 8. 4) Subnet Resource heat/heat/engine/resources/subnet.py class Subnet(resource.Resource): PROPERTIES = ( AVAILABILITY_ZONE, CIDR_BLOCK, VPC_ID, TAGS, ) = ( 'AvailabilityZone', 'CidrBlock', 'VpcId', 'Tags', ) properties_schema = { .... } def handle_delete(self): .... def resource_mapping(): return { 'AWS::EC2::Subnet': Subnet, }
  • 9. Continue ... def handle_create(self): client = self.neutron() # TODO(sbaker) Verify that this CidrBlock is within the vpc CidrBlock network_id = self.properties.get(self.VPC_ID) props = { 'network_id': network_id, 'cidr': self.properties.get(self.CIDR_BLOCK), 'name': self.physical_resource_name(), 'ip_version': 4 } subnet = client.create_subnet({'subnet': props})['subnet'] self.resource_id_set(subnet['id']) router = vpc.VPC.router_for_vpc(self.neutron(), network_id) if router: client.add_interface_router( router['id'], {'subnet_id': subnet['id']})
  • 10. 5) RouteTable Resource heat/heat/engine/resources/route_table.py class RouteTable(resource.Resource): PROPERTIES = ( VPC_ID, TAGS, ) = ( 'VpcId', 'Tags', ) properties_schema = { .... } def handle_create(self): client = self.client() props = {'name': self.physical_resource_name()} router = client.create_router({'router': props})['router'] self.resource_id_set(router['id']) def resource_mapping(): return { 'AWS::EC2::RouteTable': RouteTable }
  • 11. 6) SubnetRouteTableAssociation Resource heat/heat/engine/resources/route_table.py class SubnetRouteTableAssociation(resource.Resource): PROPERTIES = (ROUTE_TABLE_ID, SUBNET_ID,) = ( 'RouteTableId', 'SubnetId',) properties_schema = { .... } def handle_create(self): client = self.client() subnet_id = self.properties.get(self.SUBNET_ID) router_id = self.properties.get(self.ROUTE_TABLE_ID) #remove the default router association for this subnet. try: previous_router = self._router_for_subnet(subnet_id) if previous_router: client.remove_interface_router( previous_router['id'], {'subnet_id': subnet_id}) except Exception as ex: self.client_plugin().ignore_not_found(ex) client.add_interface_router( router_id, {'subnet_id': subnet_id}) def resource_mapping(): return { 'AWS::EC2::SubnetRouteTableAssociation': SubnetRouteTableAssociation, }
  • 12. 7) InternetGateway Resource heat/heat/engine/resources/internet_gateway.py class InternetGateway(resource.Resource): PROPERTIES = (TAGS,) = ('Tags',) properties_schema = { .... } def handle_create(self): self.resource_id_set(self.physical_resource_name()) @staticmethod def get_external_network_id(client): ext_filter = {'router:external': True} ext_nets = client.list_networks(**ext_filter)['networks'] if len(ext_nets) != 1: raise exception.Error( _('Expected 1 external network, found %d') % len(ext_nets)) external_network_id = ext_nets[0]['id'] return external_network_id def resource_mapping(): return { 'AWS::EC2::InternetGateway': InternetGateway, }
  • 13. 8) VPCGatewayAttachment Resource heat/heat/engine/resources/internet_gateway.py class VPCGatewayAttachment(resource.Resource): PROPERTIES = ( VPC_ID, INTERNET_GATEWAY_ID, VPN_GATEWAY_ID, ) = ( 'VpcId', 'InternetGatewayId', 'VpnGatewayId',) properties_schema = { .... } def handle_create(self): client = self.neutron() external_network_id = InternetGateway.get_external_network_id(client) for router in self._vpc_route_tables(): client.add_gateway_router(router.resource_id, { 'network_id': external_network_id}) def resource_mapping(): return { 'AWS::EC2::VPCGatewayAttachment': VPCGatewayAttachment, }
  • 14. 9) ElasticIp Resource heat/heat/engine/resources/eip.py class ElasticIp(resource.Resource): PROPERTIES = (DOMAIN, INSTANCE_ID,) = ('Domain', 'InstanceId', ) properties_schema = { .... } def handle_create(self): """Allocate a floating IP for the current tenant.""" ips = None if self.properties[self.DOMAIN]: from heat.engine.resources import internet_gateway ext_net = internet_gateway.InternetGateway.get_external_network_id(self.neutron()) props = {'floating_network_id': ext_net} ips = self.neutron().create_floatingip({ 'floatingip': props})['floatingip'] self.ipaddress = ips['floating_ip_address'] self.resource_id_set(ips['id']) instance_id = self.properties[self.INSTANCE_ID] if instance_id: server = self.nova().servers.get(instance_id) server.add_floating_ip(self._ipaddress()) def resource_mapping(): return { 'AWS::EC2::EIP': ElasticIp, }
  • 15. 10) ElasticIpAssociation Resource heat/heat/engine/resources/eip.py class ElasticIpAssociation(resource.Resource): PROPERTIES = ( INSTANCE_ID, EIP, ALLOCATION_ID, NETWORK_INTERFACE_ID, ) = ( 'InstanceId', 'EIP', 'AllocationId', 'NetworkInterfaceId', ) properties_schema = { .... } def handle_create(self): """Add a floating IP address to a server.""" if self.properties[self.EIP]: server = self.nova().servers.get(self.properties[self.INSTANCE_ID]) server.add_floating_ip(self.properties[self.EIP]) self.resource_id_set(self.properties[self.EIP]) def resource_mapping(): return { 'AWS::EC2::EIPAssociation': ElasticIpAssociation, }
  • 16. 11) VPC UnitTest heat/heat/tests/test_vpc.py class VPCTestBase(common.HeatTestCase): class VPCTest(VPCTestBase): class SubnetTest(VPCTestBase): class NetworkInterfaceTest(VPCTestBase): class InternetGatewayTest(VPCTestBase): class RouteTableTest(VPCTestBase):
  • 17. 12) ElasticIp UnitTest heat/heat/tests/test_eip.py class EIPTest(common.HeatTestCase): class AllocTest(common.HeatTestCase):
  • 18. Thanks ● Email: sajuptpm@gmail.com ● Training Videos: https://www.youtube.com/user/sajuptpm/videos ● WebSite: http://fosshelp.blogspot.in ● IRC: saju_m ● Skype: sajuptpm