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.neutron import neutron
18
from heat.engine import scheduler
20
if clients.neutronclient is not None:
21
from neutronclient.common.exceptions import NeutronClientException
23
from heat.openstack.common import log as logging
25
logger = logging.getLogger(__name__)
28
class Router(neutron.NeutronResource):
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.neutron().create_router({'router': props})['router']
48
self.resource_id_set(router['id'])
50
def _show_resource(self):
51
return self.neutron().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.neutron()
61
client.delete_router(self.resource_id)
62
except NeutronClientException as ex:
63
if ex.status_code != 404:
66
return scheduler.TaskRunner(self._confirm_delete)()
69
class RouterInterface(neutron.NeutronResource):
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.neutron().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.neutron()
85
(router_id, subnet_id) = self.resource_id.split(':')
87
client.remove_interface_router(
89
{'subnet_id': subnet_id})
90
except NeutronClientException as ex:
91
if ex.status_code != 404:
95
class RouterGateway(neutron.NeutronResource):
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::Neutron::RouterInterface' or
107
resource.type() == 'OS::Quantum::RouterInterface') and
108
resource.properties.get('router_id') ==
109
self.properties.get('router_id')):
110
deps += (self, resource)
111
# depend on any subnet in this template with the same network_id
112
# as this network_id, as the gateway implicitly creates a port
114
elif ((resource.type() == 'OS::Neutron::Subnet' or
115
resource.type() == 'OS::Quantum::Subnet') and
116
resource.properties.get('network_id') ==
117
self.properties.get('network_id')):
118
deps += (self, resource)
120
def handle_create(self):
121
router_id = self.properties.get('router_id')
122
network_id = self.properties.get('network_id')
123
self.neutron().add_gateway_router(
125
{'network_id': network_id})
126
self.resource_id_set('%s:%s' % (router_id, network_id))
128
def handle_delete(self):
129
client = self.neutron()
130
(router_id, network_id) = self.resource_id.split(':')
132
client.remove_gateway_router(router_id)
133
except NeutronClientException as ex:
134
if ex.status_code != 404:
138
def resource_mapping():
139
if clients.neutronclient is None:
143
'OS::Neutron::Router': Router,
144
'OS::Neutron::RouterInterface': RouterInterface,
145
'OS::Neutron::RouterGateway': RouterGateway,
146
'OS::Quantum::Router': Router,
147
'OS::Quantum::RouterInterface': RouterInterface,
148
'OS::Quantum::RouterGateway': RouterGateway,