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.neutron import neutron
19
from heat.engine import scheduler
21
if clients.neutronclient is not None:
22
from neutronclient.common.exceptions import NeutronClientException
24
logger = logging.getLogger(__name__)
27
class Port(neutron.NeutronResource):
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::Neutron::Subnet' or
69
resource.type() == 'OS::Quantum::Subnet') and
70
resource.properties.get('network_id') ==
71
self.properties.get('network_id')):
72
deps += (self, resource)
74
def handle_create(self):
75
props = self.prepare_properties(
77
self.physical_resource_name())
78
port = self.neutron().create_port({'port': props})['port']
79
self.resource_id_set(port['id'])
81
def _show_resource(self):
82
return self.neutron().show_port(
83
self.resource_id)['port']
85
def check_create_complete(self, *args):
86
attributes = self._show_resource()
87
return self.is_built(attributes)
89
def handle_delete(self):
90
client = self.neutron()
92
client.delete_port(self.resource_id)
93
except NeutronClientException as ex:
94
if ex.status_code != 404:
97
return scheduler.TaskRunner(self._confirm_delete)()
100
def resource_mapping():
101
if clients.neutronclient is None:
105
'OS::Neutron::Port': Port,
106
'OS::Quantum::Port': Port,