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

« back to all changes in this revision

Viewing changes to .pc/rename-quantumclient.patch/heat/engine/resources/subnet.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
from heat.engine.resources.vpc import VPC
 
21
 
 
22
logger = logging.getLogger(__name__)
 
23
 
 
24
 
 
25
class Subnet(resource.Resource):
 
26
    tags_schema = {'Key': {'Type': 'String',
 
27
                           'Required': True},
 
28
                   'Value': {'Type': 'String',
 
29
                             'Required': True}}
 
30
 
 
31
    properties_schema = {
 
32
        'AvailabilityZone': {'Type': 'String'},
 
33
        'CidrBlock': {
 
34
            'Type': 'String',
 
35
            'Required': True},
 
36
        'VpcId': {
 
37
            'Type': 'String',
 
38
            'Required': True},
 
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
        # TODO(sbaker) Verify that this CidrBlock is within the vpc CidrBlock
 
48
        network_id = self.properties.get('VpcId')
 
49
 
 
50
        props = {
 
51
            'network_id': network_id,
 
52
            'cidr': self.properties.get('CidrBlock'),
 
53
            'name': self.physical_resource_name(),
 
54
            'ip_version': 4
 
55
        }
 
56
        subnet = client.create_subnet({'subnet': props})['subnet']
 
57
 
 
58
        router = VPC.router_for_vpc(self.quantum(), network_id)
 
59
        if router:
 
60
            client.add_interface_router(
 
61
                router['id'],
 
62
                {'subnet_id': subnet['id']})
 
63
        self.resource_id_set(subnet['id'])
 
64
 
 
65
    def handle_delete(self):
 
66
        from quantumclient.common.exceptions import QuantumClientException
 
67
 
 
68
        client = self.quantum()
 
69
        network_id = self.properties.get('VpcId')
 
70
        subnet_id = self.resource_id
 
71
 
 
72
        try:
 
73
            router = VPC.router_for_vpc(self.quantum(), network_id)
 
74
            if router:
 
75
                client.remove_interface_router(
 
76
                    router['id'],
 
77
                    {'subnet_id': subnet_id})
 
78
        except QuantumClientException as ex:
 
79
            if ex.status_code != 404:
 
80
                raise ex
 
81
 
 
82
        try:
 
83
            client.delete_subnet(subnet_id)
 
84
        except QuantumClientException as ex:
 
85
            if ex.status_code != 404:
 
86
                raise ex
 
87
 
 
88
    def FnGetAtt(self, key):
 
89
        if key == 'AvailabilityZone':
 
90
            return self.properties.get(key, '')
 
91
        raise exception.InvalidTemplateAttribute(resource=self.name, key=key)
 
92
 
 
93
 
 
94
def resource_mapping():
 
95
    if clients.quantumclient is None:
 
96
        return {}
 
97
 
 
98
    return {
 
99
        'AWS::EC2::Subnet': Subnet,
 
100
    }