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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): James Page, Chuck Short, James Page
  • Date: 2013-08-08 15:23:59 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130808152359-9jgqjp23kssvc3x9
Tags: 2013.2~b2.a186.g2b4b248-0ubuntu1
[ Chuck Short ]
* debian/patches/rename-quantumclient.patch: Dropped no longer needed. 
* debian/control: Add python-oslo.sphinx

[ James Page ]
* New upstream snapshot.
* d/watch: Updated to track releases on launchpad.
* d/control: Drop BD in pep8, no longer required.
* d/control,rules: Drop use of openstack-pkg-tools, revert use of xz
  compression for debs.
* d/control,*.config,*.templates,po: Drop use of debconf/dbconfig-common
  to configure heat.
* d/*.upstart: Add upstart configurations for Ubuntu.
* d/p/default-kombu.patch: Switch default messaging from qpid to
  kombu.
* d/p/default-sqlite.patch: Use sqlite as default database option.
* d/control: Add python-ceilometerclient to BD's.
* d/rules: Fail package build for unit test failures.
* d/*.install: Directly install configuration files to /etc/heat.
* d/control: Update VCS locations to ubuntu-server-dev branches.
* d/heat-common.{install,manpages}: Include new binaries and associated
  manpages.

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 import resource
19
 
from heat.engine.resources.quantum import quantum
20
 
from heat.engine.resources.vpc import VPC
21
 
 
22
 
if clients.quantumclient is not None:
23
 
    from quantumclient.common.exceptions import QuantumClientException
24
 
 
25
 
logger = logging.getLogger(__name__)
26
 
 
27
 
 
28
 
class RouteTable(resource.Resource):
29
 
    tags_schema = {'Key': {'Type': 'String',
30
 
                           'Required': True},
31
 
                   'Value': {'Type': 'String',
32
 
                             'Required': True}}
33
 
 
34
 
    properties_schema = {
35
 
        'VpcId': {
36
 
            'Type': 'String',
37
 
            'Required': True},
38
 
        'Tags': {'Type': 'List', 'Schema': {
39
 
            'Type': 'Map',
40
 
            'Implemented': False,
41
 
            'Schema': tags_schema}}
42
 
    }
43
 
 
44
 
    def handle_create(self):
45
 
        client = self.quantum()
46
 
        props = {'name': self.physical_resource_name()}
47
 
        router = client.create_router({'router': props})['router']
48
 
        self.resource_id_set(router['id'])
49
 
 
50
 
    def check_create_complete(self, *args):
51
 
        client = self.quantum()
52
 
        attributes = client.show_router(
53
 
            self.resource_id)['router']
54
 
        if not quantum.QuantumResource.is_built(attributes):
55
 
            return False
56
 
 
57
 
        network_id = self.properties.get('VpcId')
58
 
        default_router = VPC.router_for_vpc(client, network_id)
59
 
        if default_router and default_router.get('external_gateway_info'):
60
 
            # the default router for the VPC is connected
61
 
            # to the external router, so do it for this too.
62
 
            external_network_id = default_router[
63
 
                'external_gateway_info']['network_id']
64
 
            client.add_gateway_router(self.resource_id, {
65
 
                'network_id': external_network_id})
66
 
        return True
67
 
 
68
 
    def handle_delete(self):
69
 
        client = self.quantum()
70
 
 
71
 
        router_id = self.resource_id
72
 
        try:
73
 
            client.delete_router(router_id)
74
 
        except QuantumClientException as ex:
75
 
            if ex.status_code != 404:
76
 
                raise ex
77
 
 
78
 
        # just in case this router has been added to a gateway, remove it
79
 
        try:
80
 
            client.remove_gateway_router(router_id)
81
 
        except QuantumClientException as ex:
82
 
            if ex.status_code != 404:
83
 
                raise ex
84
 
 
85
 
 
86
 
class SubnetRouteTableAssocation(resource.Resource):
87
 
 
88
 
    properties_schema = {
89
 
        'RouteTableId': {
90
 
            'Type': 'String',
91
 
            'Required': True},
92
 
        'SubnetId': {
93
 
            'Type': 'String',
94
 
            'Required': True}
95
 
    }
96
 
 
97
 
    def handle_create(self):
98
 
        client = self.quantum()
99
 
        subnet_id = self.properties.get('SubnetId')
100
 
 
101
 
        router_id = self.properties.get('RouteTableId')
102
 
 
103
 
        #remove the default router association for this subnet.
104
 
        try:
105
 
            previous_router = self._router_for_subnet(subnet_id)
106
 
            if previous_router:
107
 
                client.remove_interface_router(
108
 
                    previous_router['id'],
109
 
                    {'subnet_id': subnet_id})
110
 
        except QuantumClientException as ex:
111
 
            if ex.status_code != 404:
112
 
                raise ex
113
 
 
114
 
        client.add_interface_router(
115
 
            router_id, {'subnet_id': subnet_id})
116
 
 
117
 
    def _router_for_subnet(self, subnet_id):
118
 
        client = self.quantum()
119
 
        subnet = client.show_subnet(
120
 
            subnet_id)['subnet']
121
 
        network_id = subnet['network_id']
122
 
        return VPC.router_for_vpc(client, network_id)
123
 
 
124
 
    def handle_delete(self):
125
 
        client = self.quantum()
126
 
        subnet_id = self.properties.get('SubnetId')
127
 
 
128
 
        router_id = self.properties.get('RouteTableId')
129
 
 
130
 
        try:
131
 
            client.remove_interface_router(router_id, {
132
 
                'subnet_id': subnet_id})
133
 
        except QuantumClientException as ex:
134
 
            if ex.status_code != 404:
135
 
                raise ex
136
 
 
137
 
        # add back the default router
138
 
        try:
139
 
            default_router = self._router_for_subnet(subnet_id)
140
 
            if default_router:
141
 
                client.add_interface_router(
142
 
                    default_router['id'], {'subnet_id': subnet_id})
143
 
        except QuantumClientException as ex:
144
 
            if ex.status_code != 404:
145
 
                raise ex
146
 
 
147
 
 
148
 
def resource_mapping():
149
 
    if clients.quantumclient is None:
150
 
        return {}
151
 
 
152
 
    return {
153
 
        'AWS::EC2::RouteTable': RouteTable,
154
 
        'AWS::EC2::SubnetRouteTableAssocation': SubnetRouteTableAssocation,
155
 
    }