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.openstack.common import log as logging
18
from heat.engine.resources.quantum import quantum
20
if clients.quantumclient is not None:
21
from quantumclient.common.exceptions import QuantumClientException
23
logger = logging.getLogger(__name__)
26
class FloatingIP(quantum.QuantumResource):
27
properties_schema = {'floating_network_id': {'Type': 'String',
29
'value_specs': {'Type': 'Map',
31
'port_id': {'Type': 'String'},
32
'fixed_ip_address': {'Type': 'String'}}
34
def add_dependencies(self, deps):
35
super(FloatingIP, self).add_dependencies(deps)
36
# depend on any RouterGateway in this template with the same
37
# network_id as this floating_network_id
38
for resource in self.stack.resources.itervalues():
39
if (resource.type() == 'OS::Quantum::RouterGateway' and
40
resource.properties.get('network_id') ==
41
self.properties.get('floating_network_id')):
42
deps += (self, resource)
44
def handle_create(self):
45
props = self.prepare_properties(
47
self.physical_resource_name())
48
fip = self.quantum().create_floatingip({
49
'floatingip': props})['floatingip']
50
self.resource_id_set(fip['id'])
52
def handle_delete(self):
53
client = self.quantum()
55
client.delete_floatingip(self.resource_id)
56
except QuantumClientException as ex:
57
if ex.status_code != 404:
60
def FnGetAtt(self, key):
62
attributes = self.quantum().show_floatingip(
63
self.resource_id)['floatingip']
64
except QuantumClientException as ex:
65
logger.warn("failed to fetch resource attributes: %s" % str(ex))
67
return self.handle_get_attributes(self.name, key, attributes)
70
class FloatingIPAssociation(quantum.QuantumResource):
71
properties_schema = {'floatingip_id': {'Type': 'String',
73
'port_id': {'Type': 'String',
75
'fixed_ip_address': {'Type': 'String'}}
77
def handle_create(self):
78
props = self.prepare_properties(self.properties, self.name)
80
floatingip_id = props.pop('floatingip_id')
82
self.quantum().update_floatingip(floatingip_id, {
83
'floatingip': props})['floatingip']
84
self.resource_id_set('%s:%s' % (floatingip_id, props['port_id']))
86
def handle_delete(self):
87
if not self.resource_id:
89
client = self.quantum()
90
(floatingip_id, port_id) = self.resource_id.split(':')
92
client.update_floatingip(
94
{'floatingip': {'port_id': None}})
95
except QuantumClientException as ex:
96
if ex.status_code != 404:
100
def resource_mapping():
101
if clients.quantumclient is None:
105
'OS::Quantum::FloatingIP': FloatingIP,
106
'OS::Quantum::FloatingIPAssociation': FloatingIPAssociation,