~ubuntu-branches/ubuntu/saucy/heat/saucy

« back to all changes in this revision

Viewing changes to .pc/rename-quantumclient.patch/heat/engine/resources/internet_gateway.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.common import exception
 
18
from heat.openstack.common import log as logging
 
19
from heat.engine import resource
 
20
 
 
21
logger = logging.getLogger(__name__)
 
22
 
 
23
 
 
24
class InternetGateway(resource.Resource):
 
25
    tags_schema = {'Key': {'Type': 'String',
 
26
                           'Required': True},
 
27
                   'Value': {'Type': 'String',
 
28
                             'Required': True}}
 
29
 
 
30
    properties_schema = {
 
31
        'Tags': {'Type': 'List', 'Schema': {
 
32
            'Type': 'Map',
 
33
            'Implemented': False,
 
34
            'Schema': tags_schema}}
 
35
    }
 
36
 
 
37
    def handle_create(self):
 
38
        self.resource_id_set(self.physical_resource_name())
 
39
 
 
40
    def handle_delete(self):
 
41
        pass
 
42
 
 
43
    @staticmethod
 
44
    def get_external_network_id(client):
 
45
        ext_filter = {'router:external': True}
 
46
        ext_nets = client.list_networks(**ext_filter)['networks']
 
47
        if len(ext_nets) != 1:
 
48
            # TODO(sbaker) if there is more than one external network
 
49
            # add a heat configuration variable to set the ID of
 
50
            # the default one
 
51
            raise exception.Error(
 
52
                'Expected 1 external network, found %d' % len(ext_nets))
 
53
        external_network_id = ext_nets[0]['id']
 
54
        return external_network_id
 
55
 
 
56
 
 
57
class VPCGatewayAttachment(resource.Resource):
 
58
 
 
59
    properties_schema = {
 
60
        'VpcId': {
 
61
            'Type': 'String',
 
62
            'Required': True},
 
63
        'InternetGatewayId': {'Type': 'String'},
 
64
        'VpnGatewayId': {
 
65
            'Type': 'String',
 
66
            'Implemented': False}
 
67
    }
 
68
 
 
69
    def _vpc_route_tables(self):
 
70
        for resource in self.stack.resources.itervalues():
 
71
            if (resource.type() == 'AWS::EC2::RouteTable' and
 
72
                resource.properties.get('VpcId') ==
 
73
                    self.properties.get('VpcId')):
 
74
                        yield resource
 
75
 
 
76
    def add_dependencies(self, deps):
 
77
        super(VPCGatewayAttachment, self).add_dependencies(deps)
 
78
        # Depend on any route table in this template with the same
 
79
        # VpcId as this VpcId.
 
80
        # All route tables must exist before gateway attachment
 
81
        # as attachment happens to routers (not VPCs)
 
82
        for route_table in self._vpc_route_tables():
 
83
            deps += (self, route_table)
 
84
 
 
85
    def handle_create(self):
 
86
        client = self.quantum()
 
87
        external_network_id = InternetGateway.get_external_network_id(client)
 
88
        for router in self._vpc_route_tables():
 
89
            client.add_gateway_router(router.resource_id, {
 
90
                'network_id': external_network_id})
 
91
 
 
92
    def handle_delete(self):
 
93
        from quantumclient.common.exceptions import QuantumClientException
 
94
 
 
95
        client = self.quantum()
 
96
        for router in self._vpc_route_tables():
 
97
            try:
 
98
                client.remove_gateway_router(router.resource_id)
 
99
            except QuantumClientException as ex:
 
100
                if ex.status_code != 404:
 
101
                    raise ex
 
102
 
 
103
 
 
104
def resource_mapping():
 
105
    if clients.quantumclient is None:
 
106
        return {}
 
107
 
 
108
    return {
 
109
        'AWS::EC2::InternetGateway': InternetGateway,
 
110
        'AWS::EC2::VPCGatewayAttachment': VPCGatewayAttachment,
 
111
    }