1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
16
from heat.engine import clients
17
from heat.common import exception
18
from heat.openstack.common import log as logging
19
from heat.engine import resource
20
from heat.engine.resources.vpc import VPC
22
logger = logging.getLogger(__name__)
25
class Subnet(resource.Resource):
26
tags_schema = {'Key': {'Type': 'String',
28
'Value': {'Type': 'String',
32
'AvailabilityZone': {'Type': 'String'},
39
'Tags': {'Type': 'List', 'Schema': {
42
'Schema': tags_schema}}
45
def handle_create(self):
46
client = self.quantum()
47
# TODO(sbaker) Verify that this CidrBlock is within the vpc CidrBlock
48
network_id = self.properties.get('VpcId')
51
'network_id': network_id,
52
'cidr': self.properties.get('CidrBlock'),
53
'name': self.physical_resource_name(),
56
subnet = client.create_subnet({'subnet': props})['subnet']
58
router = VPC.router_for_vpc(self.quantum(), network_id)
60
client.add_interface_router(
62
{'subnet_id': subnet['id']})
63
self.resource_id_set(subnet['id'])
65
def handle_delete(self):
66
from quantumclient.common.exceptions import QuantumClientException
68
client = self.quantum()
69
network_id = self.properties.get('VpcId')
70
subnet_id = self.resource_id
73
router = VPC.router_for_vpc(self.quantum(), network_id)
75
client.remove_interface_router(
77
{'subnet_id': subnet_id})
78
except QuantumClientException as ex:
79
if ex.status_code != 404:
83
client.delete_subnet(subnet_id)
84
except QuantumClientException as ex:
85
if ex.status_code != 404:
88
def FnGetAtt(self, key):
89
if key == 'AvailabilityZone':
90
return self.properties.get(key, '')
91
raise exception.InvalidTemplateAttribute(resource=self.name, key=key)
94
def resource_mapping():
95
if clients.quantumclient is None:
99
'AWS::EC2::Subnet': Subnet,