本文整理汇总了Python中st2common.models.system.common.ResourceReference.from_string_reference方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceReference.from_string_reference方法的具体用法?Python ResourceReference.from_string_reference怎么用?Python ResourceReference.from_string_reference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.models.system.common.ResourceReference
的用法示例。
在下文中一共展示了ResourceReference.from_string_reference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_trigger_db
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def get_trigger_db(trigger):
# TODO: This method should die in a fire
if isinstance(trigger, str) or isinstance(trigger, unicode):
# Assume reference was passed in
ref_obj = ResourceReference.from_string_reference(ref=trigger)
return _get_trigger_db_by_name_and_pack(name=ref_obj.name,
pack=ref_obj.pack)
if isinstance(trigger, dict):
name = trigger.get('name', None)
pack = trigger.get('pack', None)
if name and pack:
return _get_trigger_db_by_name_and_pack(name=name, pack=pack)
return _get_trigger_db(type=trigger['type'],
parameters=trigger.get('parameters', {}))
if isinstance(trigger, object):
name = getattr(trigger, 'name', None)
pack = getattr(trigger, 'pack', None)
parameters = getattr(trigger, 'parameters', {})
trigger_db = None
if name and pack:
trigger_db = _get_trigger_db_by_name_and_pack(name=name, pack=pack)
else:
trigger_db = _get_trigger_db(type=trigger.type,
parameters=parameters)
return trigger_db
else:
raise Exception('Unrecognized object')
示例2: dispatch
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def dispatch(self, actionexec_db):
action_ref = ResourceReference.from_string_reference(ref=actionexec_db.action)
(action_db, _) = get_action_by_dict(
{'name': action_ref.name, 'pack': action_ref.pack})
runnertype_db = get_runnertype_by_name(action_db.runner_type['name'])
runner_type = runnertype_db.name
LOG.info('Dispatching runner for Action "%s"', actionexec_db)
LOG.debug(' liverunner_type: %s', runner_type)
LOG.debug(' RunnerType: %s', runnertype_db)
LOG.debug(' ActionExecution: %s', actionexec_db)
# Get runner instance.
runner = self._get_runner(runnertype_db)
LOG.debug('Runner instance for RunnerType "%s" is: %s', runnertype_db.name, runner)
# Invoke pre_run, run, post_run cycle.
result, actionexec_db = self._do_run(runner, runnertype_db, action_db, actionexec_db)
LOG.debug('runner do_run result: %s', result)
actionsensor.post_trigger(actionexec_db)
LOG.audit('ActionExecution complete.',
extra={'actionexecution': actionexec_db.to_serializable_dict()})
return result
示例3: user_has_rule_action_permission
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def user_has_rule_action_permission(user_db, action_ref):
"""
Check that the currently logged-in has necessary permissions on the action used / referenced
inside the rule.
Note: Rules can reference actions which don't yet exist in the system.
"""
if not cfg.CONF.rbac.enable:
return True
action_db = action_utils.get_action_by_ref(ref=action_ref)
if not action_db:
# We allow rules to be created for actions which don't yet exist in the
# system
ref = ResourceReference.from_string_reference(ref=action_ref)
action_db = ActionDB(pack=ref.pack, name=ref.name, ref=action_ref)
action_resolver = resolvers.get_resolver_for_resource_type(ResourceType.ACTION)
has_action_permission = action_resolver.user_has_resource_db_permission(
user_db=user_db, resource_db=action_db, permission_type=PermissionType.ACTION_EXECUTE)
if has_action_permission:
return True
return False
示例4: _get_trigger_instance_db_from_file
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def _get_trigger_instance_db_from_file(self, file_path):
data = self._meta_loader.load(file_path=file_path)
instance = TriggerInstanceDB(**data)
trigger_ref = ResourceReference.from_string_reference(instance['trigger'])
trigger_db = TriggerDB(pack=trigger_ref.pack, name=trigger_ref.name, type=trigger_ref.ref)
return instance, trigger_db
示例5: get_by_ref
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def get_by_ref(cls, ref):
if not ref:
return None
ref_obj = ResourceReference.from_string_reference(ref=ref)
result = cls.query(name=ref_obj.name,
pack=ref_obj.pack).first()
return result
示例6: _get_by_ref
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def _get_by_ref(self, resource_ref):
try:
ref = ResourceReference.from_string_reference(ref=resource_ref)
except Exception:
return None
resource_db = self.access.query(name=ref.name, pack=ref.pack).first()
return resource_db
示例7: _get_trigger_dict_given_rule
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def _get_trigger_dict_given_rule(rule):
trigger = rule.trigger
trigger_dict = {}
triggertype_ref = ResourceReference.from_string_reference(trigger.get('type'))
trigger_dict['pack'] = trigger_dict.get('pack', triggertype_ref.pack)
trigger_dict['type'] = triggertype_ref.ref
trigger_dict['parameters'] = rule.trigger.get('parameters', {})
return trigger_dict
示例8: get_action_by_ref
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def get_action_by_ref(action_ref):
if (not isinstance(action_ref, str) and not isinstance(action_ref, unicode)
and not isinstance(action_ref, ResourceReference)):
raise Exception('Action reference has to be either str or ResourceReference.')
if isinstance(action_ref, str) or isinstance(action_ref, unicode):
action_ref = ResourceReference.from_string_reference(ref=action_ref)
return _get_action_by_pack_and_name(name=action_ref.name, pack=action_ref.pack)
示例9: get_reference
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def get_reference(self):
"""
Retrieve referene object for this model.
:rtype: :class:`ResourceReference`
"""
if getattr(self, 'ref', None):
ref = ResourceReference.from_string_reference(ref=self.ref)
else:
ref = ResourceReference(pack=self.pack, name=self.name)
return ref
示例10: test_resource_reference_success
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def test_resource_reference_success(self):
value = 'pack1.name1'
ref = ResourceReference.from_string_reference(ref=value)
self.assertEqual(ref.pack, 'pack1')
self.assertEqual(ref.name, 'name1')
self.assertEqual(ref.ref, value)
ref = ResourceReference(pack='pack1', name='name1')
self.assertEqual(ref.ref, 'pack1.name1')
ref = ResourceReference(pack='pack1', name='name1.name2')
self.assertEqual(ref.ref, 'pack1.name1.name2')
示例11: _get_trigger_api_given_rule
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def _get_trigger_api_given_rule(rule):
trigger = rule.trigger
triggertype_ref = ResourceReference.from_string_reference(trigger.get('type'))
trigger_dict = {}
trigger_name = trigger.get('name', None)
if trigger_name:
trigger_dict['name'] = trigger_name
trigger_dict['pack'] = triggertype_ref.pack
trigger_dict['type'] = triggertype_ref.ref
trigger_dict['parameters'] = rule.trigger.get('parameters', {})
trigger_api = TriggerAPI(**trigger_dict)
return trigger_api
示例12: _to_trigger
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def _to_trigger(self, body):
trigger = body.get('trigger', '')
trigger_ref = None
try:
trigger_ref = ResourceReference.from_string_reference(ref=trigger)
except InvalidResourceReferenceError:
LOG.debug('Unable to parse reference.', exc_info=True)
return {
'name': trigger_ref.name if trigger_ref else None,
'pack': trigger_ref.pack if trigger_ref else None,
'type': body.get('type', ''),
'parameters': {}
}, body['payload']
示例13: _get_by_ref
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def _get_by_ref(self, resource_ref, exclude_fields=None, include_fields=None):
if exclude_fields and include_fields:
msg = ('exclude_fields and include_fields arguments are mutually exclusive. '
'You need to provide either one or another, but not both.')
raise ValueError(msg)
try:
ref = ResourceReference.from_string_reference(ref=resource_ref)
except Exception:
return None
resource_db = self.access.query(name=ref.name, pack=ref.pack,
exclude_fields=exclude_fields,
only_fields=include_fields).first()
return resource_db
示例14: get_model_by_resource_ref
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def get_model_by_resource_ref(db_api, ref):
"""
Retrieve a DB model based on the resource reference.
:param db_api: Class of the object to retrieve.
:type db_api: ``object``
:param ref: Resource reference.
:type ref: ``str``
:return: Retrieved object.
"""
ref_obj = ResourceReference.from_string_reference(ref=ref)
result = db_api.query(name=ref_obj.name, pack=ref_obj.pack).first()
return result
示例15: _get_filters
# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def _get_filters(self, **kwargs):
filters = copy.deepcopy(kwargs)
ref = filters.get('ref', None)
if ref:
try:
ref_obj = ResourceReference.from_string_reference(ref=ref)
except InvalidResourceReferenceError:
raise
filters['name'] = ref_obj.name
filters['pack'] = ref_obj.pack
del filters['ref']
return filters