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
19
from heat.engine import scheduler
21
if clients.quantumclient is not None:
22
from quantumclient.common.exceptions import QuantumClientException
24
logger = logging.getLogger(__name__)
27
class Port(quantum.QuantumResource):
29
fixed_ip_schema = {'subnet_id': {'Type': 'String',
31
'ip_address': {'Type': 'String'}}
33
properties_schema = {'network_id': {'Type': 'String',
35
'name': {'Type': 'String'},
36
'value_specs': {'Type': 'Map',
38
'admin_state_up': {'Default': True,
40
'fixed_ips': {'Type': 'List',
41
'Schema': {'Type': 'Map',
42
'Schema': fixed_ip_schema}},
43
'mac_address': {'Type': 'String'},
44
'device_id': {'Type': 'String'},
45
'security_groups': {'Type': 'List'}}
47
"admin_state_up": "the administrative state of this port",
48
"device_id": "unique identifier for the device",
49
"device_owner": "name of the network owning the port",
50
"fixed_ips": "fixed ip addresses",
51
"id": "the unique identifier for the port",
52
"mac_address": "mac address of the port",
53
"name": "friendly name of the port",
54
"network_id": "unique identifier for the network owning the port",
55
"security_groups": "a list of security groups for the port",
56
"status": "the status of the port",
57
"tenant_id": "tenant owning the port"
60
def add_dependencies(self, deps):
61
super(Port, self).add_dependencies(deps)
62
# Depend on any Subnet in this template with the same
63
# network_id as this network_id.
64
# It is not known which subnet a port might be assigned
65
# to so all subnets in a network should be created before
66
# the ports in that network.
67
for resource in self.stack.resources.itervalues():
68
if (resource.type() == 'OS::Quantum::Subnet' and
69
resource.properties.get('network_id') ==
70
self.properties.get('network_id')):
71
deps += (self, resource)
73
def handle_create(self):
74
props = self.prepare_properties(
76
self.physical_resource_name())
77
port = self.quantum().create_port({'port': props})['port']
78
self.resource_id_set(port['id'])
80
def _show_resource(self):
81
return self.quantum().show_port(
82
self.resource_id)['port']
84
def check_create_complete(self, *args):
85
attributes = self._show_resource()
86
return self.is_built(attributes)
88
def handle_delete(self):
89
client = self.quantum()
91
client.delete_port(self.resource_id)
92
except QuantumClientException as ex:
93
if ex.status_code != 404:
96
return scheduler.TaskRunner(self._confirm_delete)()
99
def resource_mapping():
100
if clients.quantumclient is None:
104
'OS::Quantum::Port': Port,