~ubuntu-branches/ubuntu/trusty/heat/trusty-security

« back to all changes in this revision

Viewing changes to .pc/rename-quantumclient.patch/heat/engine/resources/quantum/port.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short
  • Date: 2013-08-08 01:08:42 UTC
  • Revision ID: package-import@ubuntu.com-20130808010842-77cni2v4vlib7rus
Tags: 2013.2~b2-0ubuntu4
[ Chuck Short ]
* debian/rules: Enable testsuite during builds.
* debian/patches/fix-sqlalchemy-0.8.patch: Build against sqlalchemy 0.8.
* debian/patches/rename-quantumclient.patch: quantumclient -> neutronclient.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
#
 
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
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
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
 
14
#    under the License.
 
15
 
 
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
 
20
 
 
21
if clients.quantumclient is not None:
 
22
    from quantumclient.common.exceptions import QuantumClientException
 
23
 
 
24
logger = logging.getLogger(__name__)
 
25
 
 
26
 
 
27
class Port(quantum.QuantumResource):
 
28
 
 
29
    fixed_ip_schema = {'subnet_id': {'Type': 'String',
 
30
                                     'Required': True},
 
31
                       'ip_address': {'Type': 'String'}}
 
32
 
 
33
    properties_schema = {'network_id': {'Type': 'String',
 
34
                                        'Required': True},
 
35
                         'name': {'Type': 'String'},
 
36
                         'value_specs': {'Type': 'Map',
 
37
                                         'Default': {}},
 
38
                         'admin_state_up': {'Default': True,
 
39
                                            'Type': 'Boolean'},
 
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'}}
 
46
    attributes_schema = {
 
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"
 
58
    }
 
59
 
 
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)
 
72
 
 
73
    def handle_create(self):
 
74
        props = self.prepare_properties(
 
75
            self.properties,
 
76
            self.physical_resource_name())
 
77
        port = self.quantum().create_port({'port': props})['port']
 
78
        self.resource_id_set(port['id'])
 
79
 
 
80
    def _show_resource(self):
 
81
        return self.quantum().show_port(
 
82
            self.resource_id)['port']
 
83
 
 
84
    def check_create_complete(self, *args):
 
85
        attributes = self._show_resource()
 
86
        return self.is_built(attributes)
 
87
 
 
88
    def handle_delete(self):
 
89
        client = self.quantum()
 
90
        try:
 
91
            client.delete_port(self.resource_id)
 
92
        except QuantumClientException as ex:
 
93
            if ex.status_code != 404:
 
94
                raise ex
 
95
        else:
 
96
            return scheduler.TaskRunner(self._confirm_delete)()
 
97
 
 
98
 
 
99
def resource_mapping():
 
100
    if clients.quantumclient is None:
 
101
        return {}
 
102
 
 
103
    return {
 
104
        'OS::Quantum::Port': Port,
 
105
    }