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

« back to all changes in this revision

Viewing changes to .pc/rename-quantumclient.patch/heat/engine/resources/vpc.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.common import exception
 
17
from heat.engine import clients
 
18
from heat.openstack.common import log as logging
 
19
from heat.engine import resource
 
20
from heat.engine.resources.quantum import quantum
 
21
 
 
22
logger = logging.getLogger(__name__)
 
23
 
 
24
 
 
25
class VPC(resource.Resource):
 
26
    tags_schema = {'Key': {'Type': 'String',
 
27
                           'Required': True},
 
28
                   'Value': {'Type': 'String',
 
29
                             'Required': True}}
 
30
 
 
31
    properties_schema = {
 
32
        'CidrBlock': {'Type': 'String'},
 
33
        'InstanceTenancy': {
 
34
            'Type': 'String',
 
35
            'AllowedValues': ['default',
 
36
                              'dedicated'],
 
37
            'Default': 'default',
 
38
            'Implemented': False},
 
39
        'Tags': {'Type': 'List', 'Schema': {
 
40
            'Type': 'Map',
 
41
            'Implemented': False,
 
42
            'Schema': tags_schema}}
 
43
    }
 
44
 
 
45
    def handle_create(self):
 
46
        client = self.quantum()
 
47
        # The VPC's net and router are associated by having identical names.
 
48
        net_props = {'name': self.physical_resource_name()}
 
49
        router_props = {'name': self.physical_resource_name()}
 
50
 
 
51
        net = client.create_network({'network': net_props})['network']
 
52
        client.create_router({'router': router_props})['router']
 
53
 
 
54
        self.resource_id_set(net['id'])
 
55
 
 
56
    @staticmethod
 
57
    def network_for_vpc(client, network_id):
 
58
        return client.show_network(network_id)['network']
 
59
 
 
60
    @staticmethod
 
61
    def router_for_vpc(client, network_id):
 
62
        # first get the quantum net
 
63
        net = VPC.network_for_vpc(client, network_id)
 
64
        # then find a router with the same name
 
65
        routers = client.list_routers(name=net['name'])['routers']
 
66
        if len(routers) == 0:
 
67
            # There may be no router if the net was created manually
 
68
            # instead of in another stack.
 
69
            return None
 
70
        if len(routers) > 1:
 
71
            raise exception.Error(
 
72
                _('Multiple routers found with name %s') % net['name'])
 
73
        return routers[0]
 
74
 
 
75
    def check_create_complete(self, *args):
 
76
        net = self.network_for_vpc(self.quantum(), self.resource_id)
 
77
        if not quantum.QuantumResource.is_built(net):
 
78
            return False
 
79
        router = self.router_for_vpc(self.quantum(), self.resource_id)
 
80
        return quantum.QuantumResource.is_built(router)
 
81
 
 
82
    def handle_delete(self):
 
83
        from quantumclient.common.exceptions import QuantumClientException
 
84
        client = self.quantum()
 
85
        router = self.router_for_vpc(client, self.resource_id)
 
86
        try:
 
87
            client.delete_router(router['id'])
 
88
        except QuantumClientException as ex:
 
89
            if ex.status_code != 404:
 
90
                raise ex
 
91
 
 
92
        try:
 
93
            client.delete_network(self.resource_id)
 
94
        except QuantumClientException as ex:
 
95
            if ex.status_code != 404:
 
96
                raise ex
 
97
 
 
98
 
 
99
def resource_mapping():
 
100
    if clients.quantumclient is None:
 
101
        return {}
 
102
 
 
103
    return {
 
104
        'AWS::EC2::VPC': VPC,
 
105
    }