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

« back to all changes in this revision

Viewing changes to .pc/rename-quantumclient.patch/heat/engine/resources/network_interface.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 import resource
 
19
from heat.common import exception
 
20
 
 
21
logger = logging.getLogger(__name__)
 
22
 
 
23
 
 
24
class NetworkInterface(resource.Resource):
 
25
    tags_schema = {'Key': {'Type': 'String',
 
26
                           'Required': True},
 
27
                   'Value': {'Type': 'String',
 
28
                             'Required': True}}
 
29
 
 
30
    properties_schema = {
 
31
        'Description': {'Type': 'String'},
 
32
        'GroupSet': {'Type': 'List'},
 
33
        'PrivateIpAddress': {'Type': 'String'},
 
34
        'SourceDestCheck': {
 
35
            'Type': 'Boolean',
 
36
            'Implemented': False},
 
37
        'SubnetId': {
 
38
            'Type': 'String',
 
39
            'Required': True},
 
40
        'Tags': {'Type': 'List', 'Schema': {
 
41
            'Type': 'Map',
 
42
            'Implemented': False,
 
43
            'Schema': tags_schema}}
 
44
    }
 
45
 
 
46
    @staticmethod
 
47
    def network_id_from_subnet_id(quantumclient, subnet_id):
 
48
        subnet_info = quantumclient.show_subnet(subnet_id)
 
49
        return subnet_info['subnet']['network_id']
 
50
 
 
51
    def handle_create(self):
 
52
        client = self.quantum()
 
53
 
 
54
        subnet_id = self.properties['SubnetId']
 
55
        network_id = self.network_id_from_subnet_id(client, subnet_id)
 
56
 
 
57
        fixed_ip = {'subnet_id': subnet_id}
 
58
        if self.properties['PrivateIpAddress']:
 
59
            fixed_ip['ip_address'] = self.properties['PrivateIpAddress']
 
60
 
 
61
        props = {
 
62
            'name': self.physical_resource_name(),
 
63
            'admin_state_up': True,
 
64
            'network_id': network_id,
 
65
            'fixed_ips': [fixed_ip]
 
66
        }
 
67
 
 
68
        if self.properties['GroupSet']:
 
69
            props['security_groups'] = []
 
70
 
 
71
            for sg in self.properties.get('GroupSet'):
 
72
                resource = self.stack.resource_by_refid(sg)
 
73
                if resource:
 
74
                    props['security_groups'].append(resource.resource_id)
 
75
                else:
 
76
                    raise exception.InvalidTemplateAttribute(
 
77
                        resource=self.name,
 
78
                        key='GroupSet')
 
79
        port = client.create_port({'port': props})['port']
 
80
        self.resource_id_set(port['id'])
 
81
 
 
82
    def handle_delete(self):
 
83
        from quantumclient.common.exceptions import QuantumClientException
 
84
 
 
85
        client = self.quantum()
 
86
        try:
 
87
            client.delete_port(self.resource_id)
 
88
        except QuantumClientException as ex:
 
89
            if ex.status_code != 404:
 
90
                raise ex
 
91
 
 
92
 
 
93
def resource_mapping():
 
94
    if clients.quantumclient is None:
 
95
        return {}
 
96
 
 
97
    return {
 
98
        'AWS::EC2::NetworkInterface': NetworkInterface,
 
99
    }