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

« back to all changes in this revision

Viewing changes to heat/engine/resources/quantum/quantum.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 quantumclient.common.exceptions import QuantumClientException
17
 
 
18
 
from heat.common import exception
19
 
from heat.engine import resource
20
 
 
21
 
from heat.openstack.common import log as logging
22
 
 
23
 
logger = logging.getLogger(__name__)
24
 
 
25
 
 
26
 
class QuantumResource(resource.Resource):
27
 
 
28
 
    def validate(self):
29
 
        '''
30
 
        Validate any of the provided params
31
 
        '''
32
 
        res = super(QuantumResource, self).validate()
33
 
        if res:
34
 
            return res
35
 
        return self.validate_properties(self.properties)
36
 
 
37
 
    @staticmethod
38
 
    def validate_properties(properties):
39
 
        '''
40
 
        Validates to ensure nothing in value_specs overwrites
41
 
        any key that exists in the schema.
42
 
 
43
 
        Also ensures that shared and tenant_id is not specified
44
 
        in value_specs.
45
 
        '''
46
 
        if 'value_specs' in properties.keys():
47
 
            vs = properties.get('value_specs')
48
 
            banned_keys = set(['shared', 'tenant_id']).union(
49
 
                properties.keys())
50
 
            for k in banned_keys.intersection(vs.keys()):
51
 
                return '%s not allowed in value_specs' % k
52
 
 
53
 
    @staticmethod
54
 
    def prepare_properties(properties, name):
55
 
        '''
56
 
        Prepares the property values so that they can be passed directly to
57
 
        the Quantum call.
58
 
 
59
 
        Removes None values and value_specs, merges value_specs with the main
60
 
        values.
61
 
        '''
62
 
        props = dict((k, v) for k, v in properties.items()
63
 
                     if v is not None and k != 'value_specs')
64
 
 
65
 
        if 'name' in properties.keys():
66
 
            props.setdefault('name', name)
67
 
 
68
 
        if 'value_specs' in properties.keys():
69
 
            props.update(properties.get('value_specs'))
70
 
 
71
 
        return props
72
 
 
73
 
    @staticmethod
74
 
    def handle_get_attributes(name, key, attributes):
75
 
        '''
76
 
        Support method for responding to FnGetAtt
77
 
        '''
78
 
        if key == 'show':
79
 
            return attributes
80
 
 
81
 
        if key in attributes.keys():
82
 
            return attributes[key]
83
 
 
84
 
        raise exception.InvalidTemplateAttribute(resource=name, key=key)
85
 
 
86
 
    @staticmethod
87
 
    def is_built(attributes):
88
 
        if attributes['status'] == 'BUILD':
89
 
            return False
90
 
        if attributes['status'] in ('ACTIVE', 'DOWN'):
91
 
            return True
92
 
        else:
93
 
            raise exception.Error('%s resource[%s] status[%s]' %
94
 
                                  ('quantum reported unexpected',
95
 
                                   attributes['name'], attributes['status']))
96
 
 
97
 
    def _resolve_attribute(self, name):
98
 
        try:
99
 
            attributes = self._show_resource()
100
 
        except QuantumClientException as ex:
101
 
            logger.warn("failed to fetch resource attributes: %s" % str(ex))
102
 
            return None
103
 
        return self.handle_get_attributes(self.name, name, attributes)
104
 
 
105
 
    def _confirm_delete(self):
106
 
        while True:
107
 
            try:
108
 
                yield
109
 
                self._show_resource()
110
 
            except QuantumClientException as ex:
111
 
                if ex.status_code != 404:
112
 
                    raise ex
113
 
                return
114
 
 
115
 
    def FnGetRefId(self):
116
 
        return unicode(self.resource_id)