1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
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
8
# http://www.apache.org/licenses/LICENSE-2.0
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
16
from quantumclient.common.exceptions import QuantumClientException
18
from heat.common import exception
19
from heat.engine import resource
21
from heat.openstack.common import log as logging
23
logger = logging.getLogger(__name__)
26
class QuantumResource(resource.Resource):
30
Validate any of the provided params
32
res = super(QuantumResource, self).validate()
35
return self.validate_properties(self.properties)
38
def validate_properties(properties):
40
Validates to ensure nothing in value_specs overwrites
41
any key that exists in the schema.
43
Also ensures that shared and tenant_id is not specified
46
if 'value_specs' in properties.keys():
47
vs = properties.get('value_specs')
48
banned_keys = set(['shared', 'tenant_id']).union(
50
for k in banned_keys.intersection(vs.keys()):
51
return '%s not allowed in value_specs' % k
54
def prepare_properties(properties, name):
56
Prepares the property values so that they can be passed directly to
59
Removes None values and value_specs, merges value_specs with the main
62
props = dict((k, v) for k, v in properties.items()
63
if v is not None and k != 'value_specs')
65
if 'name' in properties.keys():
66
props.setdefault('name', name)
68
if 'value_specs' in properties.keys():
69
props.update(properties.get('value_specs'))
74
def handle_get_attributes(name, key, attributes):
76
Support method for responding to FnGetAtt
81
if key in attributes.keys():
82
return attributes[key]
84
raise exception.InvalidTemplateAttribute(resource=name, key=key)
87
def is_built(attributes):
88
if attributes['status'] == 'BUILD':
90
if attributes['status'] in ('ACTIVE', 'DOWN'):
93
raise exception.Error('%s resource[%s] status[%s]' %
94
('quantum reported unexpected',
95
attributes['name'], attributes['status']))
97
def _resolve_attribute(self, name):
99
attributes = self._show_resource()
100
except QuantumClientException as ex:
101
logger.warn("failed to fetch resource attributes: %s" % str(ex))
103
return self.handle_get_attributes(self.name, name, attributes)
105
def _confirm_delete(self):
109
self._show_resource()
110
except QuantumClientException as ex:
111
if ex.status_code != 404:
115
def FnGetRefId(self):
116
return unicode(self.resource_id)