def delete(self, name): """Delete the named environment. :param name: Name of environment to delete """ acl.enforce('environments:delete', context.ctx()) LOG.debug("Delete environment [name=%s]", name) rest_utils.rest_retry_on_db_error(db_api.delete_environment)(name)
def delete(self, name): """Delete the named workbook. :param name: Name of workbook to delete """ acl.enforce('workbooks:delete', context.ctx()) LOG.debug("Delete workbook [name=%s]", name) rest_utils.rest_retry_on_db_error(db_api.delete_workbook)(name)
def delete(self, name): """Delete the named environment. :param name: Name of environment to delete """ acl.enforce('environments:delete', context.ctx()) LOG.debug("Delete environment [name=%s]", name) rest_utils.rest_retry_on_db_error(db_api.delete_environment)(name)
def delete(self, identifier): """Delete cron trigger. :param identifier: Id or name of cron trigger to delete """ acl.enforce('cron_triggers:delete', context.ctx()) LOG.debug("Delete cron trigger [identifier=%s]", identifier) rest_utils.rest_retry_on_db_error( triggers.delete_cron_trigger)(identifier)
def delete(self, member_id): """Deletes a member from the member list of a resource.""" acl.enforce('members:delete', context.ctx()) LOG.debug( "Delete resource member. [resource_id=%s, " "resource_type=%s, member_id=%s].", self.resource_id, self.type, member_id) rest_utils.rest_retry_on_db_error(db_api.delete_resource_member)( self.resource_id, self.type, member_id)
def delete(self, identifier): """Delete cron trigger. :param identifier: Id or name of cron trigger to delete """ acl.enforce('cron_triggers:delete', context.ctx()) LOG.debug("Delete cron trigger [identifier=%s]", identifier) rest_utils.rest_retry_on_db_error( triggers.delete_cron_trigger )(identifier)
def delete(self, identifier, namespace=''): """Delete a code source. :param identifier: Name or ID of Code Source to delete. :param namespace: Optional. Namespace of the Code Source to delete. """ acl.enforce('code_sources:delete', context.ctx()) LOG.debug('Delete code source [identifier=%s, namespace=%s]', identifier, namespace) rest_utils.rest_retry_on_db_error(db_api.delete_code_source)( identifier=identifier, namespace=namespace)
def delete(self, name, namespace=''): """Delete the named workbook. :param name: Name of workbook to delete. :param namespace: Optional. Namespace of workbook to delete. """ acl.enforce('workbooks:delete', context.ctx()) LOG.debug("Delete workbook [name=%s, namespace=%s]", name, namespace) rest_utils.rest_retry_on_db_error(db_api.delete_workbook)( name, namespace )
def delete(self, identifier, namespace=''): """Delete a dynamic action. :param identifier: Name or ID of the action to delete. :param namespace: Optional. Namespace of the action to delete. """ acl.enforce('dynamic_actions:delete', context.ctx()) LOG.debug('Delete dynamic action [identifier=%s, namespace=%s]', identifier, namespace) rest_utils.rest_retry_on_db_error( db_api.delete_dynamic_action_definition)(identifier=identifier, namespace=namespace)
def post(self, event_trigger): """Creates a new event trigger.""" acl.enforce('event_triggers:create', auth_ctx.ctx()) values = event_trigger.to_dict() input_keys = [k for k in values if values[k]] if CREATE_MANDATORY - set(input_keys): raise exc.EventTriggerException( "Params %s must be provided for creating event trigger." % CREATE_MANDATORY) if values.get('scope') == 'public': acl.enforce('event_triggers:create:public', auth_ctx.ctx()) LOG.debug('Create event trigger: %s', values) db_model = rest_utils.rest_retry_on_db_error( triggers.create_event_trigger)( name=values.get('name', ''), exchange=values.get('exchange'), topic=values.get('topic'), event=values.get('event'), workflow_id=values.get('workflow_id'), scope=values.get('scope'), workflow_input=values.get('workflow_input'), workflow_params=values.get('workflow_params'), ) return resources.EventTrigger.from_db_model(db_model)
def post(self, namespace=''): """Create a new workflow. :param namespace: Optional. The namespace to create the workflow in. Workflows with the same name can be added to a given project if they are in two different namespaces. The text is allowed to have definitions of multiple workflows. In such case, they all will be created. """ acl.enforce('workflows:create', context.ctx()) definition = pecan.request.text scope = pecan.request.GET.get('scope', 'private') pecan.response.status = 201 resources.Workflow.validate_scope(scope) if scope == 'public': acl.enforce('workflows:publicize', context.ctx()) LOG.debug("Create workflow(s) [definition=%s]", definition) db_wfs = rest_utils.rest_retry_on_db_error(workflows.create_workflows)( definition, scope=scope, namespace=namespace ) workflow_list = [ resources.Workflow.from_db_model(db_wf) for db_wf in db_wfs ] return resources.Workflows(workflows=workflow_list).to_json()
def post(self, namespace=''): """Create a new workflow. :param namespace: Optional. The namespace to create the workflow in. Workflows with the same name can be added to a given project if they are in two different namespaces. The text is allowed to have definitions of multiple workflows. In such case, they all will be created. """ acl.enforce('workflows:create', context.ctx()) definition = pecan.request.text scope = pecan.request.GET.get('scope', 'private') pecan.response.status = 201 resources.Workflow.validate_scope(scope) if scope == 'public': acl.enforce('workflows:publicize', context.ctx()) LOG.debug("Create workflow(s) [definition=%s]", definition) db_wfs = rest_utils.rest_retry_on_db_error(workflows.create_workflows)( definition, scope=scope, namespace=namespace) workflow_list = [ resources.Workflow.from_db_model(db_wf) for db_wf in db_wfs ] return resources.Workflows(workflows=workflow_list).to_json()
def get(self, identifier, namespace=''): """Return the named action. :param identifier: ID or name of the Action to get. :param namespace: The namespace of the action. """ acl.enforce('actions:get', context.ctx()) LOG.debug("Fetch action [identifier=%s]", identifier) action_provider = action_service.get_system_action_provider() # Here we assume that the action search might involve DB operations # so we need to apply the regular retrying logic as everywhere else. action_desc = rest_utils.rest_retry_on_db_error(action_provider.find)( identifier, namespace=namespace) if action_desc is None: # TODO(rakhmerov): We need to change exception class so that # it's not DB specific. But it should be associated with the # same HTTP code. raise exc.DBEntityNotFoundError( 'Action not found [name=%s, namespace=%s]' % (identifier, namespace)) return _action_descriptor_to_resource(action_desc)
def post(self, cron_trigger): """Creates a new cron trigger. :param cron_trigger: Required. Cron trigger structure. """ acl.enforce('cron_triggers:create', context.ctx()) LOG.debug('Create cron trigger: %s', cron_trigger) values = cron_trigger.to_dict() db_model = rest_utils.rest_retry_on_db_error( triggers.create_cron_trigger )( name=values['name'], workflow_name=values.get('workflow_name'), workflow_input=values.get('workflow_input'), workflow_params=values.get('workflow_params'), pattern=values.get('pattern'), first_time=values.get('first_execution_time'), count=values.get('remaining_executions'), workflow_id=values.get('workflow_id') ) return resources.CronTrigger.from_db_model(db_model)
def put(self, member_id, member_info): """Sets the status for a resource member.""" acl.enforce('members:update', context.ctx()) LOG.debug( "Update resource member status. [resource_id=%s, " "member_id=%s, member_info=%s].", self.resource_id, member_id, member_info ) if not member_info.status: msg = "Status must be provided." raise exc.WorkflowException(msg) db_member = rest_utils.rest_retry_on_db_error( db_api.update_resource_member )( self.resource_id, self.type, member_id, {'status': member_info.status} ) return resources.Member.from_db_model(db_member)
def delete(self, id, force=False): """Delete the specified Execution. :param id: UUID of execution to delete. :param force: Optional. Force the deletion of unfinished executions. Default: false. While the api is backward compatible the behaviour is not the same. The new default is the safer option """ acl.enforce('executions:delete', context.ctx()) LOG.debug("Delete execution [id=%s]", id) if not force: state = db_api.get_workflow_execution( id, fields=(db_models.WorkflowExecution.state, ))[0] if not states.is_completed(state): raise exc.NotAllowedException( "Only completed executions can be deleted. " "Use --force to override this. " "Execution {} is in {} state".format(id, state)) return rest_utils.rest_retry_on_db_error( db_api.delete_workflow_execution)(id)
def post(self, namespace=''): """Create a new workbook. :param namespace: Optional. The namespace to create the workbook in. Workbooks with the same name can be added to a given project if they are in two different namespaces. """ acl.enforce('workbooks:create', context.ctx()) definition = pecan.request.text scope = pecan.request.GET.get('scope', 'private') # If "skip_validation" is present in the query string parameters # then workflow language validation will be disabled. skip_validation = 'skip_validation' in pecan.request.GET resources.Workbook.validate_scope(scope) LOG.debug("Create workbook [definition=%s]", definition) wb_db = rest_utils.rest_retry_on_db_error( workbooks.create_workbook_v2)( definition, namespace=namespace, scope=scope, validate=not skip_validation ) pecan.response.status = 201 return resources.Workbook.from_db_model(wb_db).to_json()
def post(self, name, scope='private', namespace=''): """Creates new code sources. :param name: Code source name (i.e. the name of the module). :param scope: Optional. Scope (private or public). :param namespace: Optional. The namespace to create the code sources in. """ acl.enforce('code_sources:create', context.ctx()) # Extract content directly from the request. content = pecan.request.text LOG.debug('Creating code source [names=%s, scope=%s, namespace=%s]', name, scope, namespace) db_model = rest_utils.rest_retry_on_db_error( db_api.create_code_source)({ 'name': name, 'content': content, 'namespace': namespace, 'scope': scope, 'version': 1, }) pecan.response.status = 201 return resources.CodeSource.from_db_model(db_model).to_json()
def put(self, env): """Update an environment. :param env: Required. Environment structure to update """ acl.enforce('environments:update', context.ctx()) if not env.name: raise exceptions.InputException( 'Name of the environment is not provided.' ) LOG.debug("Update environment [name=%s, env=%s]", env.name, cut(env)) definition = json.loads(wsme_pecan.pecan.request.body.decode()) definition.pop('name') self._validate_environment( definition, ['description', 'variables', 'scope'] ) db_model = rest_utils.rest_retry_on_db_error( db_api.update_environment )(env.name, env.to_dict()) return resources.Environment.from_db_model(db_model)
def put(self, namespace=''): """Update a workbook. :param namespace: Optional. Namespace of workbook to update. """ acl.enforce('workbooks:update', context.ctx()) definition = pecan.request.text scope = pecan.request.GET.get('scope', 'private') # If "skip_validation" is present in the query string parameters # then workflow language validation will be disabled. skip_validation = 'skip_validation' in pecan.request.GET resources.Workbook.validate_scope(scope) LOG.debug("Update workbook [definition=%s]", definition) wb_db = rest_utils.rest_retry_on_db_error( workbooks.update_workbook_v2)( definition, namespace=namespace, scope=scope, validate=not skip_validation ) return resources.Workbook.from_db_model(wb_db).to_json()
def post(self, namespace=''): """Create a new workflow. NOTE: The text is allowed to have definitions of multiple workflows. In this case they all will be created. :param namespace: Optional. The namespace to create the workflow in. Workflows with the same name can be added to a given project if are in two different namespaces. """ acl.enforce('workflows:create', context.ctx()) definition = pecan.request.text scope = pecan.request.GET.get('scope', 'private') pecan.response.status = 201 if scope not in resources.SCOPE_TYPES.values: raise exc.InvalidModelException( "Scope must be one of the following: %s; actual: " "%s" % (resources.SCOPE_TYPES.values, scope)) LOG.debug("Create workflow(s) [definition=%s]", definition) db_wfs = rest_utils.rest_retry_on_db_error(workflows.create_workflows)( definition, scope=scope, namespace=namespace) workflow_list = [ resources.Workflow.from_db_model(db_wf) for db_wf in db_wfs ] return resources.Workflows(workflows=workflow_list).to_json()
def put(self, member_id, member_info): """Sets the status for a resource member.""" acl.enforce('members:update', context.ctx()) LOG.debug( "Update resource member status. [resource_id=%s, " "member_id=%s, member_info=%s].", self.resource_id, member_id, member_info ) if not member_info.status: msg = "Status must be provided." raise exc.WorkflowException(msg) db_member = rest_utils.rest_retry_on_db_error( db_api.update_resource_member )( self.resource_id, self.type, member_id, {'status': member_info.status} ) return resources.Member.from_db_model(db_member)
def post(self, event_trigger): """Creates a new event trigger.""" acl.enforce('event_triggers:create', auth_ctx.ctx()) values = event_trigger.to_dict() input_keys = [k for k in values if values[k]] if CREATE_MANDATORY - set(input_keys): raise exc.EventTriggerException( "Params %s must be provided for creating event trigger." % CREATE_MANDATORY ) if values.get('scope') == 'public': acl.enforce('event_triggers:create:public', auth_ctx.ctx()) LOG.debug('Create event trigger: %s', values) db_model = rest_utils.rest_retry_on_db_error( triggers.create_event_trigger )( name=values.get('name', ''), exchange=values.get('exchange'), topic=values.get('topic'), event=values.get('event'), workflow_id=values.get('workflow_id'), scope=values.get('scope'), workflow_input=values.get('workflow_input'), workflow_params=values.get('workflow_params'), ) return resources.EventTrigger.from_db_model(db_model)
def post(self, namespace=''): """Create a new workbook. :param namespace: Optional. The namespace to create the workbook in. Workbooks with the same name can be added to a given project if they are in two different namespaces. """ acl.enforce('workbooks:create', context.ctx()) definition = pecan.request.text scope = pecan.request.GET.get('scope', 'private') resources.Workbook.validate_scope(scope) LOG.debug("Create workbook [definition=%s]", definition) wb_db = rest_utils.rest_retry_on_db_error( workbooks.create_workbook_v2)( definition, namespace=namespace, scope=scope ) pecan.response.status = 201 return resources.Workbook.from_db_model(wb_db).to_json()
def put(self, identifier=None, namespace=''): """Update one or more workflows. :param identifier: Optional. If provided, it's UUID of a workflow. Only one workflow can be updated with identifier param. :param namespace: Optional. If provided, it's the namespace of the workflow/workflows. Currently, namespace cannot be changed. The text is allowed to have definitions of multiple workflows. In such case, they all will be updated. """ acl.enforce('workflows:update', context.ctx()) definition = pecan.request.text scope = pecan.request.GET.get('scope', 'private') resources.Workflow.validate_scope(scope) if scope == 'public': acl.enforce('workflows:publicize', context.ctx()) LOG.debug("Update workflow(s) [definition=%s]", definition) db_wfs = rest_utils.rest_retry_on_db_error(workflows.update_workflows)( definition, scope=scope, identifier=identifier, namespace=namespace) workflow_list = [ resources.Workflow.from_db_model(db_wf) for db_wf in db_wfs ] return (workflow_list[0].to_json() if identifier else resources.Workflows(workflows=workflow_list).to_json())
def delete(self, id, force=False): """Delete the specified Execution. :param id: UUID of execution to delete. :param force: Optional. Force the deletion of unfinished executions. Default: false. While the api is backward compatible the behaviour is not the same. The new default is the safer option """ acl.enforce('executions:delete', context.ctx()) LOG.debug("Delete execution [id=%s]", id) if not force: state = db_api.get_workflow_execution( id, fields=(db_models.WorkflowExecution.state,) )[0] if not states.is_completed(state): raise exc.NotAllowedException( "Only completed executions can be deleted. " "Use --force to override this. " "Execution {} is in {} state".format(id, state) ) return rest_utils.rest_retry_on_db_error( db_api.delete_workflow_execution )(id)
def delete(self, member_id): """Deletes a member from the member list of a resource.""" acl.enforce('members:delete', context.ctx()) LOG.debug( "Delete resource member. [resource_id=%s, " "resource_type=%s, member_id=%s].", self.resource_id, self.type, member_id ) rest_utils.rest_retry_on_db_error(db_api.delete_resource_member)( self.resource_id, self.type, member_id )
def delete(self, id): """Delete the specified Execution. :param id: UUID of execution to delete. """ acl.enforce('executions:delete', context.ctx()) LOG.debug("Delete execution [id=%s]", id) return rest_utils.rest_retry_on_db_error( db_api.delete_workflow_execution)(id)
def put(self): """Update a workbook.""" acl.enforce('workbooks:update', context.ctx()) definition = pecan.request.text LOG.debug("Update workbook [definition=%s]", definition) wb_db = rest_utils.rest_retry_on_db_error( workbooks.update_workbook_v2)(definition) return resources.Workbook.from_db_model(wb_db).to_json()
def post(self): """Create a new workbook.""" acl.enforce('workbooks:create', context.ctx()) definition = pecan.request.text LOG.debug("Create workbook [definition=%s]", definition) wb_db = rest_utils.rest_retry_on_db_error( workbooks.create_workbook_v2)(definition) pecan.response.status = 201 return resources.Workbook.from_db_model(wb_db).to_json()
def get(self, identifier): """Returns the named cron_trigger. :param identifier: Id or name of cron trigger to retrieve """ acl.enforce('cron_triggers:get', context.ctx()) LOG.debug('Fetch cron trigger [identifier=%s]', identifier) # Use retries to prevent possible failures. db_model = rest_utils.rest_retry_on_db_error( db_api.get_cron_trigger)(identifier) return resources.CronTrigger.from_db_model(db_model)
def get(self, identifier): """Return the named action. :param identifier: ID or name of the Action to get. """ acl.enforce('actions:get', context.ctx()) LOG.debug("Fetch action [identifier=%s]", identifier) # Use retries to prevent possible failures. db_model = rest_utils.rest_retry_on_db_error( db_api.get_action_definition)(identifier) return resources.Action.from_db_model(db_model)
def get(self, identifier): """Returns the named cron_trigger. :param identifier: Id or name of cron trigger to retrieve """ acl.enforce('cron_triggers:get', context.ctx()) LOG.debug('Fetch cron trigger [identifier=%s]', identifier) # Use retries to prevent possible failures. db_model = rest_utils.rest_retry_on_db_error( db_api.get_cron_trigger )(identifier) return resources.CronTrigger.from_db_model(db_model)
def get(self, identifier, namespace=''): """Return the named action. :param identifier: Name or UUID of the action to retrieve. :param namespace: Optional. Namespace of the action to retrieve. """ acl.enforce('dynamic_actions:get', context.ctx()) LOG.debug('Fetch dynamic action [identifier=%s, namespace=%s]', identifier, namespace) db_model = rest_utils.rest_retry_on_db_error( db_api.get_dynamic_action_definition)(identifier=identifier, namespace=namespace) return resources.DynamicAction.from_db_model(db_model)
def get(self, identifier): """Return the named action. :param identifier: ID or name of the Action to get. """ acl.enforce('actions:get', context.ctx()) LOG.debug("Fetch action [identifier=%s]", identifier) # Use retries to prevent possible failures. db_model = rest_utils.rest_retry_on_db_error( db_api.get_action_definition )(identifier) return resources.Action.from_db_model(db_model)
def get(self, identifier, namespace=''): """Return a code source. :param identifier: Name or UUID of the code source to retrieve. :param namespace: Optional. Namespace of the code source to retrieve. """ acl.enforce('code_sources:get', context.ctx()) LOG.debug('Fetch code source [identifier=%s, namespace=%s]', identifier, namespace) db_model = rest_utils.rest_retry_on_db_error(db_api.get_code_source)( identifier=identifier, namespace=namespace) return resources.CodeSource.from_db_model(db_model)
def post(self, env): """Create a new environment. :param env: Required. Environment structure to create """ acl.enforce('environments:create', context.ctx()) LOG.debug("Create environment [env=%s]", cut(env)) self._validate_environment( json.loads(wsme_pecan.pecan.request.body.decode()), ['name', 'description', 'variables']) db_model = rest_utils.rest_retry_on_db_error( db_api.create_environment)(env.to_dict()) return resources.Environment.from_db_model(db_model)
def put(self, identifier=None, namespace=''): """Update one or more workflows. :param identifier: Optional. If provided, it's UUID of a workflow. Only one workflow can be updated with identifier param. :param namespace: Optional. If provided, it's the namespace of the workflow/workflows. Currently, namespace cannot be changed. The text is allowed to have definitions of multiple workflows. In such case, they all will be updated. """ acl.enforce('workflows:update', context.ctx()) # NOTE(rakhmerov): We can't use normal method arguments to access # request data because it will break dynamic sub controller lookup # functionality (see _lookup() above) so we have to get the data # directly from the request object. definition = pecan.request.text scope = pecan.request.GET.get('scope', 'private') # If "skip_validation" is present in the query string parameters # then workflow language validation will be disabled. skip_validation = 'skip_validation' in pecan.request.GET resources.Workflow.validate_scope(scope) if scope == 'public': acl.enforce('workflows:publicize', context.ctx()) LOG.debug("Update workflow(s) [definition=%s]", definition) db_wfs = rest_utils.rest_retry_on_db_error(workflows.update_workflows)( definition, scope=scope, identifier=identifier, namespace=namespace, validate=not skip_validation) workflow_list = [ resources.Workflow.from_db_model(db_wf) for db_wf in db_wfs ] return (workflow_list[0].to_json() if identifier else resources.Workflows(workflows=workflow_list).to_json())
def post(self, namespace=''): """Create a new workflow. :param namespace: Optional. The namespace to create the workflow in. Workflows with the same name can be added to a given project if they are in two different namespaces. The text is allowed to have definitions of multiple workflows. In such case, they all will be created. """ acl.enforce('workflows:create', context.ctx()) # NOTE(rakhmerov): We can't use normal method arguments to access # request data because it will break dynamic sub controller lookup # functionality (see _lookup() above) so we have to get the data # directly from the request object. definition = pecan.request.text scope = pecan.request.GET.get('scope', 'private') # If "skip_validation" is present in the query string parameters # then workflow language validation will be disabled. skip_validation = 'skip_validation' in pecan.request.GET pecan.response.status = 201 resources.Workflow.validate_scope(scope) if scope == 'public': acl.enforce('workflows:publicize', context.ctx()) LOG.debug("Create workflow(s) [definition=%s]", definition) db_wfs = rest_utils.rest_retry_on_db_error(workflows.create_workflows)( definition, scope=scope, namespace=namespace, validate=not skip_validation) workflow_list = [ resources.Workflow.from_db_model(db_wf) for db_wf in db_wfs ] return resources.Workflows(workflows=workflow_list).to_json()
def post(self, env): """Create a new environment. :param env: Required. Environment structure to create """ acl.enforce('environments:create', context.ctx()) LOG.debug("Create environment [env=%s]", cut(env)) self._validate_environment( json.loads(wsme_pecan.pecan.request.body.decode()), ['name', 'description', 'variables'] ) db_model = rest_utils.rest_retry_on_db_error( db_api.create_environment )(env.to_dict()) return resources.Environment.from_db_model(db_model)
def put(self, namespace=''): """Update a workbook. :param namespace: Optional. Namespace of workbook to update. """ acl.enforce('workbooks:update', context.ctx()) definition = pecan.request.text scope = pecan.request.GET.get('scope', 'private') resources.Workbook.validate_scope(scope) LOG.debug("Update workbook [definition=%s]", definition) wb_db = rest_utils.rest_retry_on_db_error( workbooks.update_workbook_v2)(definition, namespace=namespace, scope=scope) return resources.Workbook.from_db_model(wb_db).to_json()
def put(self, namespace=''): """Update a workbook. :param namespace: Optional. Namespace of workbook to update. """ acl.enforce('workbooks:update', context.ctx()) definition = pecan.request.text scope = pecan.request.GET.get('scope', 'private') resources.Workbook.validate_scope(scope) LOG.debug("Update workbook [definition=%s]", definition) wb_db = rest_utils.rest_retry_on_db_error( workbooks.update_workbook_v2)( definition, namespace=namespace, scope=scope ) return resources.Workbook.from_db_model(wb_db).to_json()
def post(self, cron_trigger): """Creates a new cron trigger. :param cron_trigger: Required. Cron trigger structure. """ acl.enforce('cron_triggers:create', context.ctx()) LOG.debug('Create cron trigger: %s', cron_trigger) values = cron_trigger.to_dict() db_model = rest_utils.rest_retry_on_db_error( triggers.create_cron_trigger)( name=values['name'], workflow_name=values.get('workflow_name'), workflow_input=values.get('workflow_input'), workflow_params=values.get('workflow_params'), pattern=values.get('pattern'), first_time=values.get('first_execution_time'), count=values.get('remaining_executions'), workflow_id=values.get('workflow_id')) return resources.CronTrigger.from_db_model(db_model)
def put(self, env): """Update an environment. :param env: Required. Environment structure to update """ acl.enforce('environments:update', context.ctx()) if not env.name: raise exceptions.InputException( 'Name of the environment is not provided.') LOG.debug("Update environment [name=%s, env=%s]", env.name, cut(env)) definition = json.loads(wsme_pecan.pecan.request.body.decode()) definition.pop('name') self._validate_environment(definition, ['description', 'variables', 'scope']) db_model = rest_utils.rest_retry_on_db_error( db_api.update_environment)(env.name, env.to_dict()) return resources.Environment.from_db_model(db_model)
def put(self, dyn_action): """Update dynamic action. :param dyn_action: Dynamic action to create. """ acl.enforce('dynamic_actions:update', context.ctx()) LOG.debug('Updating dynamic action [action=%s]', dyn_action) if not dyn_action.id and not dyn_action.name: raise exc.InputException("Either 'name' or 'id' must be provided.") values = {'class_name': dyn_action.class_name} if dyn_action.scope: values['scope'] = dyn_action.scope # A client may also want to update a source code. if dyn_action.code_source_id or dyn_action.code_source_name: code_source = db_api.get_code_source( dyn_action.code_source_id or dyn_action.code_source_name, namespace=dyn_action.namespace) values['code_source_id'] = code_source.id values['code_source_name'] = code_source.name # TODO(rakhmerov): Ideally we also need to check if the specified # class exists in the specified code source. But probably it's not # a controller responsibility. db_model = rest_utils.rest_retry_on_db_error( db_api.update_dynamic_action_definition)( dyn_action.id or dyn_action.name, values, namespace=dyn_action.namespace) return resources.DynamicAction.from_db_model(db_model)
def put(self, identifier=None, namespace=''): """Update one or more workflows. :param identifier: Optional. If provided, it's UUID of a workflow. Only one workflow can be updated with identifier param. :param namespace: Optional. If provided, it's the namespace of the workflow/workflows. Currently, namespace cannot be changed. The text is allowed to have definitions of multiple workflows. In such case, they all will be updated. """ acl.enforce('workflows:update', context.ctx()) definition = pecan.request.text scope = pecan.request.GET.get('scope', 'private') resources.Workflow.validate_scope(scope) if scope == 'public': acl.enforce('workflows:publicize', context.ctx()) LOG.debug("Update workflow(s) [definition=%s]", definition) db_wfs = rest_utils.rest_retry_on_db_error(workflows.update_workflows)( definition, scope=scope, identifier=identifier, namespace=namespace ) workflow_list = [ resources.Workflow.from_db_model(db_wf) for db_wf in db_wfs ] return (workflow_list[0].to_json() if identifier else resources.Workflows(workflows=workflow_list).to_json())