def _register_action_alias(self, pack, action_alias): action_alias_db = self._get_action_alias_db(pack=pack, action_alias=action_alias) try: action_alias_db.id = ActionAlias.get_by_name( action_alias_db.name).id except StackStormDBObjectNotFoundError: LOG.debug('ActionAlias %s not found. Creating new one.', action_alias) action_ref = action_alias_db.action_ref action_db = Action.get_by_ref(action_ref) if not action_db: LOG.warning( 'Action %s not found in DB. Did you forget to register the action?', action_ref) try: action_alias_db = ActionAlias.add_or_update(action_alias_db) extra = {'action_alias_db': action_alias_db} LOG.audit('Action alias updated. Action alias %s from %s.', action_alias_db, action_alias, extra=extra) except Exception: LOG.exception('Failed to create action alias %s.', action_alias_db.name) raise
def _get_runner_ref(self, action_ref): """ Retrieve a runner reference for the provided action. :rtype: ``str`` """ action = Action.get_by_ref(action_ref) return action['runner_type']['name']
def _get_action_by_ref(ref): try: action_db = Action.get_by_ref(ref) if not action_db: raise ValueError('Referenced action "%s" doesnt exist' % (ref)) return action_db except Exception as e: msg = 'Database lookup for ref="%s" resulted in exception. %s' % ( ref, e) LOG.exception(msg) abort(http_client.NOT_FOUND, msg)
def get_action_by_ref(ref): """ Returns the action object from db given a string ref. :param ref: Reference to the trigger type db object. :type ref: ``str`` :rtype action: ``object`` """ try: return Action.get_by_ref(ref) except ValueError as e: LOG.debug('Database lookup for ref="%s" resulted ' + "in exception : %s.", ref, e, exc_info=True) return None
def get_action_by_ref(ref): """ Returns the action object from db given a string ref. :param ref: Reference to the trigger type db object. :type ref: ``str`` :rtype action: ``object`` """ try: return Action.get_by_ref(ref) except ValueError as e: LOG.debug('Database lookup for ref="%s" resulted ' + 'in exception : %s.', ref, e, exc_info=True) return None
def get_action_by_ref(ref, only_fields: Optional[List[str]] = None): """ Returns the action object from db given a string ref. :param ref: Reference to the trigger type db object. :type ref: ``str`` :param: only_field: Optional lists if fields to retrieve. If not specified, it defaults to all fields. :rtype action: ``object`` """ try: return Action.get_by_ref(ref, only_fields=only_fields) except ValueError as e: LOG.debug( 'Database lookup for ref="%s" resulted ' + "in exception : %s.", ref, e, exc_info=True, ) return None
def _register_action_alias(self, pack, action_alias): action_alias_db = self._get_action_alias_db(pack=pack, action_alias=action_alias) try: action_alias_db.id = ActionAlias.get_by_name(action_alias_db.name).id except StackStormDBObjectNotFoundError: LOG.debug('ActionAlias %s not found. Creating new one.', action_alias) action_ref = action_alias_db.action_ref action_db = Action.get_by_ref(action_ref) if not action_db: LOG.warning('Action %s not found in DB. Did you forget to register the action?', action_ref) try: action_alias_db = ActionAlias.add_or_update(action_alias_db) extra = {'action_alias_db': action_alias_db} LOG.audit('Action alias updated. Action alias %s from %s.', action_alias_db, action_alias, extra=extra) except Exception: LOG.exception('Failed to create action alias %s.', action_alias_db.name) raise
def _get_runner(self, action_ref): action = Action.get_by_ref(action_ref) return action['runner_type']['name']