~ubuntu-branches/ubuntu/wily/heat/wily

« back to all changes in this revision

Viewing changes to heat/engine/api.py

  • Committer: Package Import Robot
  • Author(s): Corey Bryant
  • Date: 2015-08-19 08:11:50 UTC
  • mfrom: (1.1.27)
  • Revision ID: package-import@ubuntu.com-20150819081150-m969fd35xn8bdmfu
Tags: 1:5.0.0~b2-0ubuntu1
* New upstream milestone for OpenStack Liberty.
* d/control: Align (build-)depends with upstream.
* d/p/fix-requirements.patch: Dropped. No longer needed.
* d/p/fixup-assert-regex.patch: Rebased.
* d/rules: Remove .eggs directory in override_dh_auto_clean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
#    License for the specific language governing permissions and limitations
12
12
#    under the License.
13
13
 
14
 
import collections
15
 
 
16
14
from oslo_log import log as logging
17
15
from oslo_utils import timeutils
18
16
import six
19
17
 
 
18
from heat.common import exception
20
19
from heat.common.i18n import _
21
20
from heat.common.i18n import _LE
22
21
from heat.common import param_utils
146
145
 
147
146
 
148
147
def format_resource_attributes(resource, with_attr=None):
 
148
    resolver = resource.attributes
 
149
    if not with_attr:
 
150
        with_attr = []
 
151
 
149
152
    def resolve(attr, resolver):
150
153
        try:
151
 
            return resolver[attr]
 
154
            return resolver._resolver(attr)
152
155
        except Exception:
153
156
            return None
154
 
 
155
 
    resolver = resource.attributes
 
157
    # if 'show' in attribute_schema, will resolve all attributes of resource
 
158
    # including the ones are not represented in response of show API, such as
 
159
    # 'console_urls' for nova server, user can view it by taking with_attr
 
160
    # parameter
156
161
    if 'show' in six.iterkeys(resolver):
157
162
        show_attr = resolver['show']
158
 
        if isinstance(show_attr, collections.Mapping):
159
 
            resolver = show_attr
160
 
 
161
 
    if not with_attr:
162
 
        with_attr = []
163
 
 
164
 
    attributes = set(list(six.iterkeys(resolver)) + with_attr)
165
 
    return dict((attr, resolve(attr, resolver))
166
 
                for attr in attributes)
 
163
        for a in with_attr:
 
164
            if a not in show_attr:
 
165
                show_attr[a] = resolve(a, resolver)
 
166
        return show_attr
 
167
    else:
 
168
        attributes = set(list(six.iterkeys(resolver)) + with_attr)
 
169
        return dict((attr, resolve(attr, resolver))
 
170
                    for attr in attributes)
167
171
 
168
172
 
169
173
def format_resource_properties(resource):
200
204
        rpc_api.RES_REQUIRED_BY: resource.required_by(),
201
205
    }
202
206
 
203
 
    if (hasattr(resource, 'nested') and callable(resource.nested) and
204
 
            resource.nested() is not None):
205
 
        res[rpc_api.RES_NESTED_STACK_ID] = dict(resource.nested().identifier())
 
207
    try:
 
208
        if (hasattr(resource, 'nested') and callable(resource.nested) and
 
209
                resource.nested() is not None):
 
210
            res[rpc_api.RES_NESTED_STACK_ID] = dict(
 
211
                resource.nested().identifier())
 
212
    except exception.NotFound:
 
213
        pass
206
214
 
207
215
    if resource.stack.parent_resource_name:
208
216
        res[rpc_api.RES_PARENT_RESOURCE] = resource.stack.parent_resource_name
266
274
    result = {
267
275
        rpc_api.NOTIFY_TENANT_ID: stack.context.tenant_id,
268
276
        rpc_api.NOTIFY_USER_ID: stack.context.user,
269
 
        rpc_api.NOTIFY_STACK_ID: stack.identifier().arn(),
 
277
        rpc_api.NOTIFY_STACK_ID: stack.id,
270
278
        rpc_api.NOTIFY_STACK_NAME: stack.name,
271
279
        rpc_api.NOTIFY_STATE: state,
272
280
        rpc_api.NOTIFY_STATE_REASON: stack.status_reason,
403
411
    return res
404
412
 
405
413
 
406
 
def format_software_config(sc):
 
414
def format_software_config(sc, detail=True):
407
415
    if sc is None:
408
416
        return
409
417
    result = {
410
418
        rpc_api.SOFTWARE_CONFIG_ID: sc.id,
411
419
        rpc_api.SOFTWARE_CONFIG_NAME: sc.name,
412
420
        rpc_api.SOFTWARE_CONFIG_GROUP: sc.group,
413
 
        rpc_api.SOFTWARE_CONFIG_CONFIG: sc.config['config'],
414
 
        rpc_api.SOFTWARE_CONFIG_INPUTS: sc.config['inputs'],
415
 
        rpc_api.SOFTWARE_CONFIG_OUTPUTS: sc.config['outputs'],
416
 
        rpc_api.SOFTWARE_CONFIG_OPTIONS: sc.config['options'],
417
 
        rpc_api.SOFTWARE_CONFIG_CREATION_TIME: sc.created_at.isoformat(),
 
421
        rpc_api.SOFTWARE_CONFIG_CREATION_TIME: sc.created_at.isoformat()
418
422
    }
 
423
    if detail:
 
424
        result[rpc_api.SOFTWARE_CONFIG_CONFIG] = sc.config['config']
 
425
        result[rpc_api.SOFTWARE_CONFIG_INPUTS] = sc.config['inputs']
 
426
        result[rpc_api.SOFTWARE_CONFIG_OUTPUTS] = sc.config['outputs']
 
427
        result[rpc_api.SOFTWARE_CONFIG_OPTIONS] = sc.config['options']
419
428
    return result
420
429
 
421
430