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

« back to all changes in this revision

Viewing changes to .pc/rename-quantumclient.patch/heat/engine/resources/quantum/floatingip.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.resources.quantum import quantum
19
 
 
20
 
if clients.quantumclient is not None:
21
 
    from quantumclient.common.exceptions import QuantumClientException
22
 
 
23
 
logger = logging.getLogger(__name__)
24
 
 
25
 
 
26
 
class FloatingIP(quantum.QuantumResource):
27
 
    properties_schema = {'floating_network_id': {'Type': 'String',
28
 
                                                 'Required': True},
29
 
                         'value_specs': {'Type': 'Map',
30
 
                                         'Default': {}},
31
 
                         'port_id': {'Type': 'String'},
32
 
                         'fixed_ip_address': {'Type': 'String'}}
33
 
 
34
 
    def add_dependencies(self, deps):
35
 
        super(FloatingIP, self).add_dependencies(deps)
36
 
        # depend on any RouterGateway in this template with the same
37
 
        # network_id as this floating_network_id
38
 
        for resource in self.stack.resources.itervalues():
39
 
            if (resource.type() == 'OS::Quantum::RouterGateway' and
40
 
                resource.properties.get('network_id') ==
41
 
                    self.properties.get('floating_network_id')):
42
 
                        deps += (self, resource)
43
 
 
44
 
    def handle_create(self):
45
 
        props = self.prepare_properties(
46
 
            self.properties,
47
 
            self.physical_resource_name())
48
 
        fip = self.quantum().create_floatingip({
49
 
            'floatingip': props})['floatingip']
50
 
        self.resource_id_set(fip['id'])
51
 
 
52
 
    def handle_delete(self):
53
 
        client = self.quantum()
54
 
        try:
55
 
            client.delete_floatingip(self.resource_id)
56
 
        except QuantumClientException as ex:
57
 
            if ex.status_code != 404:
58
 
                raise ex
59
 
 
60
 
    def FnGetAtt(self, key):
61
 
        try:
62
 
            attributes = self.quantum().show_floatingip(
63
 
                self.resource_id)['floatingip']
64
 
        except QuantumClientException as ex:
65
 
            logger.warn("failed to fetch resource attributes: %s" % str(ex))
66
 
            return None
67
 
        return self.handle_get_attributes(self.name, key, attributes)
68
 
 
69
 
 
70
 
class FloatingIPAssociation(quantum.QuantumResource):
71
 
    properties_schema = {'floatingip_id': {'Type': 'String',
72
 
                                           'Required': True},
73
 
                         'port_id': {'Type': 'String',
74
 
                                     'Required': True},
75
 
                         'fixed_ip_address': {'Type': 'String'}}
76
 
 
77
 
    def handle_create(self):
78
 
        props = self.prepare_properties(self.properties, self.name)
79
 
 
80
 
        floatingip_id = props.pop('floatingip_id')
81
 
 
82
 
        self.quantum().update_floatingip(floatingip_id, {
83
 
            'floatingip': props})['floatingip']
84
 
        self.resource_id_set('%s:%s' % (floatingip_id, props['port_id']))
85
 
 
86
 
    def handle_delete(self):
87
 
        if not self.resource_id:
88
 
            return
89
 
        client = self.quantum()
90
 
        (floatingip_id, port_id) = self.resource_id.split(':')
91
 
        try:
92
 
            client.update_floatingip(
93
 
                floatingip_id,
94
 
                {'floatingip': {'port_id': None}})
95
 
        except QuantumClientException as ex:
96
 
            if ex.status_code != 404:
97
 
                raise ex
98
 
 
99
 
 
100
 
def resource_mapping():
101
 
    if clients.quantumclient is None:
102
 
        return {}
103
 
 
104
 
    return {
105
 
        'OS::Quantum::FloatingIP': FloatingIP,
106
 
        'OS::Quantum::FloatingIPAssociation': FloatingIPAssociation,
107
 
    }