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.engine.resources.quantum import quantum
18
from heat.engine import scheduler
20
if clients.quantumclient is not None:
21
from quantumclient.common.exceptions import QuantumClientException
23
from heat.openstack.common import log as logging
25
logger = logging.getLogger(__name__)
28
class Router(quantum.QuantumResource):
29
properties_schema = {'name': {'Type': 'String'},
30
'value_specs': {'Type': 'Map',
32
'admin_state_up': {'Type': 'Boolean',
35
"status": "the status of the router",
36
"external_gateway_info": "gateway network for the router",
37
"name": "friendly name of the router",
38
"admin_state_up": "administrative state of the router",
39
"tenant_id": "tenant owning the router",
40
"id": "unique identifier for the router"
43
def handle_create(self):
44
props = self.prepare_properties(
46
self.physical_resource_name())
47
router = self.quantum().create_router({'router': props})['router']
48
self.resource_id_set(router['id'])
50
def _show_resource(self):
51
return self.quantum().show_router(
52
self.resource_id)['router']
54
def check_create_complete(self, *args):
55
attributes = self._show_resource()
56
return self.is_built(attributes)
58
def handle_delete(self):
59
client = self.quantum()
61
client.delete_router(self.resource_id)
62
except QuantumClientException as ex:
63
if ex.status_code != 404:
66
return scheduler.TaskRunner(self._confirm_delete)()
69
class RouterInterface(quantum.QuantumResource):
70
properties_schema = {'router_id': {'Type': 'String',
72
'subnet_id': {'Type': 'String',
75
def handle_create(self):
76
router_id = self.properties.get('router_id')
77
subnet_id = self.properties.get('subnet_id')
78
self.quantum().add_interface_router(
80
{'subnet_id': subnet_id})
81
self.resource_id_set('%s:%s' % (router_id, subnet_id))
83
def handle_delete(self):
84
client = self.quantum()
85
(router_id, subnet_id) = self.resource_id.split(':')
87
client.remove_interface_router(
89
{'subnet_id': subnet_id})
90
except QuantumClientException as ex:
91
if ex.status_code != 404:
95
class RouterGateway(quantum.QuantumResource):
96
properties_schema = {'router_id': {'Type': 'String',
98
'network_id': {'Type': 'String',
101
def add_dependencies(self, deps):
102
super(RouterGateway, self).add_dependencies(deps)
103
for resource in self.stack.resources.itervalues():
104
# depend on any RouterInterface in this template with the same
105
# router_id as this router_id
106
if (resource.type() == 'OS::Quantum::RouterInterface' and
107
resource.properties.get('router_id') ==
108
self.properties.get('router_id')):
109
deps += (self, resource)
110
# depend on any subnet in this template with the same network_id
111
# as this network_id, as the gateway implicitly creates a port
113
elif (resource.type() == 'OS::Quantum::Subnet' and
114
resource.properties.get('network_id') ==
115
self.properties.get('network_id')):
116
deps += (self, resource)
118
def handle_create(self):
119
router_id = self.properties.get('router_id')
120
network_id = self.properties.get('network_id')
121
self.quantum().add_gateway_router(
123
{'network_id': network_id})
124
self.resource_id_set('%s:%s' % (router_id, network_id))
126
def handle_delete(self):
127
client = self.quantum()
128
(router_id, network_id) = self.resource_id.split(':')
130
client.remove_gateway_router(router_id)
131
except QuantumClientException as ex:
132
if ex.status_code != 404:
136
def resource_mapping():
137
if clients.quantumclient is None:
141
'OS::Quantum::Router': Router,
142
'OS::Quantum::RouterInterface': RouterInterface,
143
'OS::Quantum::RouterGateway': RouterGateway,