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.common import exception
17
from heat.engine import clients
18
from heat.openstack.common import log as logging
19
from heat.engine import resource
20
from heat.engine.resources.quantum import quantum
22
logger = logging.getLogger(__name__)
25
class VPC(resource.Resource):
26
tags_schema = {'Key': {'Type': 'String',
28
'Value': {'Type': 'String',
32
'CidrBlock': {'Type': 'String'},
35
'AllowedValues': ['default',
38
'Implemented': False},
39
'Tags': {'Type': 'List', 'Schema': {
42
'Schema': tags_schema}}
45
def handle_create(self):
46
client = self.quantum()
47
# The VPC's net and router are associated by having identical names.
48
net_props = {'name': self.physical_resource_name()}
49
router_props = {'name': self.physical_resource_name()}
51
net = client.create_network({'network': net_props})['network']
52
client.create_router({'router': router_props})['router']
54
self.resource_id_set(net['id'])
57
def network_for_vpc(client, network_id):
58
return client.show_network(network_id)['network']
61
def router_for_vpc(client, network_id):
62
# first get the quantum net
63
net = VPC.network_for_vpc(client, network_id)
64
# then find a router with the same name
65
routers = client.list_routers(name=net['name'])['routers']
67
# There may be no router if the net was created manually
68
# instead of in another stack.
71
raise exception.Error(
72
_('Multiple routers found with name %s') % net['name'])
75
def check_create_complete(self, *args):
76
net = self.network_for_vpc(self.quantum(), self.resource_id)
77
if not quantum.QuantumResource.is_built(net):
79
router = self.router_for_vpc(self.quantum(), self.resource_id)
80
return quantum.QuantumResource.is_built(router)
82
def handle_delete(self):
83
from quantumclient.common.exceptions import QuantumClientException
84
client = self.quantum()
85
router = self.router_for_vpc(client, self.resource_id)
87
client.delete_router(router['id'])
88
except QuantumClientException as ex:
89
if ex.status_code != 404:
93
client.delete_network(self.resource_id)
94
except QuantumClientException as ex:
95
if ex.status_code != 404:
99
def resource_mapping():
100
if clients.quantumclient is None:
104
'AWS::EC2::VPC': VPC,