示例#1
0
        def wrapper_inner(**kwargs):
            # Get the context for the current task operation
            ctx = kwargs.pop('ctx', CloudifyContext)

            # Resolve the actual context which need to run operation,
            # the context could be belongs to relationship context or actual
            # node context
            ctx_node = resolve_ctx(ctx)

            # Get the current operation name
            operation_name = get_current_operation()
            try:
                # Prepare the openstack resource that need to execute the
                # current task operation
                # Make sure we cleaned up resource
                # before performing create in heal.
                if 'heal' in ctx.workflow_id and 'create' in operation_name:
                    update_runtime_properties_for_operation_task(
                        CLOUDIFY_DELETE_OPERATION, ctx_node)
                resource = \
                    prepare_resource_instance(class_decl, ctx_node, kwargs)

                if use_external_resource(ctx_node, resource,
                                         existing_resource_handler,
                                         **existing_resource_kwargs):
                    return
                # check resource_id before stop/delete for already cleaned up
                if operation_name in (CLOUDIFY_STOP_OPERATION,
                                      CLOUDIFY_DELETE_OPERATION,
                                      CLOUDIFY_UNLINK_OPERATION):
                    if not ctx_node.instance.runtime_properties.get(
                            RESOURCE_ID):
                        ctx.logger.info('Instance is already uninitialized.')
                        return
                # run action
                kwargs['openstack_resource'] = resource
                func(**kwargs)
                update_runtime_properties_for_operation_task(
                    operation_name, ctx_node, resource)
                # Update "external_resource" runtime property when running
                # any update operation or update project for external resource
                set_external_resource(ctx_node, resource, [
                    CLOUDIFY_UPDATE_PROJECT_OPERATION,
                    CLOUDIFY_UPDATE_OPERATION
                ])

            except EXCEPTIONS as errors:
                _, _, tb = sys.exc_info()
                raise NonRecoverableError(
                    'Failure while trying to run operation:'
                    '{0}: {1}'.format(operation_name, errors.message),
                    causes=[exception_to_error_cause(errors, tb)])
示例#2
0
    def wrapper(**kwargs):
        ctx = kwargs.get('ctx', CloudifyContext)

        # Resolve the actual context which need to run operation,
        # the context could be belongs to relationship context or actual
        # node context
        ctx_node = resolve_ctx(ctx)
        # Check to see if we need to do properties transformation or not
        kwargs_config = {}
        if is_compat_node(ctx_node):
            compat = Compat(context=ctx_node, **kwargs)
            kwargs_config = compat.transform()

        if not kwargs_config:
            kwargs_config = kwargs
        func(**kwargs_config)

        update_runtime_properties_for_node_v2(ctx_node, kwargs_config)