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

« back to all changes in this revision

Viewing changes to heat/api/cfn/v1/stacks.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Yolanda Robla, Chuck Short
  • Date: 2013-07-22 16:22:29 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130722162229-zzvfu40id94ii0hc
Tags: 2013.2~b2-0ubuntu1
[ Yolanda Robla ]
* debian/tests: added autopkg tests

[ Chuck Short ]
* New upstream release
* debian/control:
  - Add python-pbr to build-depends.
  - Add python-d2to to build-depends.
  - Dropped python-argparse.
  - Add python-six to build-depends.
  - Dropped python-sendfile.
  - Dropped python-nose.
  - Added testrepository.
  - Added python-testtools.
* debian/rules: Run testrepository instead of nosetets.
* debian/patches/removes-lxml-version-limitation-from-pip-requires.patch: Dropped
  no longer needed.
* debian/patches/fix-package-version-detection-when-building-doc.patch: Dropped
  no longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
        self.policy = policy.Enforcer(scope='cloudformation')
53
53
 
54
54
    def _enforce(self, req, action):
55
 
        """Authorize an action against the policy.json"""
 
55
        """Authorize an action against the policy.json."""
56
56
        try:
57
57
            self.policy.enforce(req.context, action, {})
58
58
        except heat_exception.Forbidden:
125
125
                engine_api.STACK_UPDATED_TIME: 'LastUpdatedTime',
126
126
                engine_api.STACK_ID: 'StackId',
127
127
                engine_api.STACK_NAME: 'StackName',
128
 
                engine_api.STACK_STATUS: 'StackStatus',
129
128
                engine_api.STACK_STATUS_DATA: 'StackStatusReason',
130
129
                engine_api.STACK_TMPL_DESCRIPTION: 'TemplateDescription',
131
130
            }
132
131
 
133
132
            result = api_utils.reformat_dict_keys(keymap, s)
134
133
 
 
134
            action = s[engine_api.STACK_ACTION]
 
135
            status = s[engine_api.STACK_STATUS]
 
136
            result['StackStatus'] = '_'.join((action, status))
 
137
 
135
138
            # AWS docs indicate DeletionTime is ommitted for current stacks
136
 
            # This is still TODO in the engine, we don't keep data for
 
139
            # This is still TODO(unknown) in the engine, we don't keep data for
137
140
            # stacks after they are deleted
138
141
            if engine_api.STACK_DELETION_TIME in s:
139
142
                result['DeletionTime'] = s[engine_api.STACK_DELETION_TIME]
195
198
                engine_api.STACK_PARAMETERS: 'Parameters',
196
199
                engine_api.STACK_ID: 'StackId',
197
200
                engine_api.STACK_NAME: 'StackName',
198
 
                engine_api.STACK_STATUS: 'StackStatus',
199
201
                engine_api.STACK_STATUS_DATA: 'StackStatusReason',
200
202
                engine_api.STACK_TIMEOUT: 'TimeoutInMinutes',
201
203
            }
202
204
 
203
205
            result = api_utils.reformat_dict_keys(keymap, s)
204
206
 
 
207
            action = s[engine_api.STACK_ACTION]
 
208
            status = s[engine_api.STACK_STATUS]
 
209
            result['StackStatus'] = '_'.join((action, status))
 
210
 
205
211
            # Reformat outputs, these are handled separately as they are
206
212
            # only present in the engine output for a completely created
207
213
            # stack
279
285
            the engine API.  FIXME: we currently only support a subset of
280
286
            the AWS defined parameters (both here and in the engine)
281
287
            """
282
 
            # TODO : Capabilities, NotificationARNs
 
288
            # TODO(shardy) : Capabilities, NotificationARNs
283
289
            keymap = {'TimeoutInMinutes': engine_api.PARAM_TIMEOUT,
284
290
                      'DisableRollback': engine_api.PARAM_DISABLE_ROLLBACK}
285
291
 
291
297
            return result
292
298
 
293
299
        if action not in self.CREATE_OR_UPDATE_ACTION:
294
 
            msg = _("Unexpected action %s" % action)
 
300
            msg = _("Unexpected action %(action)s") % ({'action': action})
295
301
            # This should not happen, so return HeatInternalFailureError
296
302
            return exception.HeatInternalFailureError(detail=msg)
297
303
 
324
330
 
325
331
        args = {'template': stack,
326
332
                'params': stack_parms,
 
333
                'files': {},
327
334
                'args': create_args}
328
335
        try:
329
336
            stack_name = req.params['StackName']
403
410
            return exception.HeatInvalidParameterValueError(detail=msg)
404
411
 
405
412
        logger.info('validate_template')
 
413
 
 
414
        def format_validate_parameter(key, value):
 
415
            """
 
416
            Reformat engine output into the AWS "ValidateTemplate" format
 
417
            """
 
418
 
 
419
            return {
 
420
                'ParameterKey': key,
 
421
                'DefaultValue': value.get(engine_api.PARAM_DEFAULT, ''),
 
422
                'Description': value.get(engine_api.PARAM_DESCRIPTION, ''),
 
423
                'NoEcho': value.get(engine_api.PARAM_NO_ECHO, 'false')
 
424
            }
 
425
 
406
426
        try:
407
427
            res = self.engine_rpcapi.validate_template(con, template)
 
428
            res['Parameters'] = [format_validate_parameter(k, v)
 
429
                                 for k, v in res['Parameters'].items()]
408
430
            return api_utils.format_response('ValidateTemplate', res)
409
431
        except rpc_common.RemoteError as ex:
410
432
            return exception.map_remote_error(ex)
445
467
                engine_api.EVENT_RES_NAME: 'LogicalResourceId',
446
468
                engine_api.EVENT_RES_PHYSICAL_ID: 'PhysicalResourceId',
447
469
                engine_api.EVENT_RES_PROPERTIES: 'ResourceProperties',
448
 
                engine_api.EVENT_RES_STATUS: 'ResourceStatus',
449
470
                engine_api.EVENT_RES_STATUS_DATA: 'ResourceStatusReason',
450
471
                engine_api.EVENT_RES_TYPE: 'ResourceType',
451
472
                engine_api.EVENT_STACK_ID: 'StackId',
454
475
            }
455
476
 
456
477
            result = api_utils.reformat_dict_keys(keymap, e)
 
478
            action = e[engine_api.EVENT_RES_ACTION]
 
479
            status = e[engine_api.EVENT_RES_STATUS]
 
480
            result['ResourceStatus'] = '_'.join((action, status))
457
481
            result['ResourceProperties'] = json.dumps(result[
458
482
                                                      'ResourceProperties'])
459
483
 
472
496
        return api_utils.format_response('DescribeStackEvents',
473
497
                                         {'StackEvents': result})
474
498
 
 
499
    @staticmethod
 
500
    def _resource_status(res):
 
501
        action = res[engine_api.RES_ACTION]
 
502
        status = res[engine_api.RES_STATUS]
 
503
        return '_'.join((action, status))
 
504
 
475
505
    def describe_stack_resource(self, req):
476
506
        """
477
507
        Implements the DescribeStackResource API action
489
519
                engine_api.RES_NAME: 'LogicalResourceId',
490
520
                engine_api.RES_METADATA: 'Metadata',
491
521
                engine_api.RES_PHYSICAL_ID: 'PhysicalResourceId',
492
 
                engine_api.RES_STATUS: 'ResourceStatus',
493
522
                engine_api.RES_STATUS_DATA: 'ResourceStatusReason',
494
523
                engine_api.RES_TYPE: 'ResourceType',
495
524
                engine_api.RES_STACK_ID: 'StackId',
498
527
 
499
528
            result = api_utils.reformat_dict_keys(keymap, r)
500
529
 
 
530
            result['ResourceStatus'] = self._resource_status(r)
 
531
 
501
532
            return self._id_format(result)
502
533
 
503
534
        con = req.context
543
574
                engine_api.RES_DESCRIPTION: 'Description',
544
575
                engine_api.RES_NAME: 'LogicalResourceId',
545
576
                engine_api.RES_PHYSICAL_ID: 'PhysicalResourceId',
546
 
                engine_api.RES_STATUS: 'ResourceStatus',
547
577
                engine_api.RES_STATUS_DATA: 'ResourceStatusReason',
548
578
                engine_api.RES_TYPE: 'ResourceType',
549
579
                engine_api.RES_STACK_ID: 'StackId',
553
583
 
554
584
            result = api_utils.reformat_dict_keys(keymap, r)
555
585
 
 
586
            result['ResourceStatus'] = self._resource_status(r)
 
587
 
556
588
            return self._id_format(result)
557
589
 
558
590
        con = req.context
597
629
                engine_api.RES_UPDATED_TIME: 'LastUpdatedTimestamp',
598
630
                engine_api.RES_NAME: 'LogicalResourceId',
599
631
                engine_api.RES_PHYSICAL_ID: 'PhysicalResourceId',
600
 
                engine_api.RES_STATUS: 'ResourceStatus',
601
632
                engine_api.RES_STATUS_DATA: 'ResourceStatusReason',
602
633
                engine_api.RES_TYPE: 'ResourceType',
603
634
            }
604
635
 
605
 
            return api_utils.reformat_dict_keys(keymap, r)
 
636
            result = api_utils.reformat_dict_keys(keymap, r)
 
637
 
 
638
            result['ResourceStatus'] = self._resource_status(r)
 
639
 
 
640
            return result
606
641
 
607
642
        con = req.context
608
643