本文整理汇总了Python中st2common.persistence.policy.PolicyType.get_by_ref方法的典型用法代码示例。如果您正苦于以下问题:Python PolicyType.get_by_ref方法的具体用法?Python PolicyType.get_by_ref怎么用?Python PolicyType.get_by_ref使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.policy.PolicyType
的用法示例。
在下文中一共展示了PolicyType.get_by_ref方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_register_policy_types
# 需要导入模块: from st2common.persistence.policy import PolicyType [as 别名]
# 或者: from st2common.persistence.policy.PolicyType import get_by_ref [as 别名]
def test_register_policy_types(self):
self.assertEqual(register_policy_types(st2tests), 2)
type1 = PolicyType.get_by_ref("action.concurrency")
self.assertEqual(type1.name, "concurrency")
self.assertEqual(type1.resource_type, "action")
type2 = PolicyType.get_by_ref("action.mock_policy_error")
self.assertEqual(type2.name, "mock_policy_error")
self.assertEqual(type2.resource_type, "action")
示例2: register_policy_types
# 需要导入模块: from st2common.persistence.policy import PolicyType [as 别名]
# 或者: from st2common.persistence.policy.PolicyType import get_by_ref [as 别名]
def register_policy_types(module):
registered_count = 0
mod_path = os.path.dirname(os.path.realpath(sys.modules[module.__name__].__file__))
path = '%s/policies/meta' % mod_path
files = []
for ext in ALLOWED_EXTS:
exp = '%s/*%s' % (path, ext)
files += glob.glob(exp)
for f in files:
try:
LOG.debug('Loading policy type from "%s".', f)
content = loader.load_meta_file(f)
policy_type_api = PolicyTypeAPI(**content)
policy_type_db = PolicyTypeAPI.to_model(policy_type_api)
try:
existing_entry = PolicyType.get_by_ref(policy_type_db.ref)
if existing_entry:
policy_type_db.id = existing_entry.id
except ValueError:
LOG.debug('Policy type "%s" is not found. Creating new entry.',
policy_type_db.ref)
policy_type_db = PolicyType.add_or_update(policy_type_db)
extra = {'policy_type_db': policy_type_db}
LOG.audit('Policy type "%s" is updated.', policy_type_db.ref, extra=extra)
registered_count += 1
except:
LOG.exception('Unable to register policy type from "%s".', f)
return registered_count
示例3: test_get_by_ref
# 需要导入模块: from st2common.persistence.policy import PolicyType [as 别名]
# 或者: from st2common.persistence.policy.PolicyType import get_by_ref [as 别名]
def test_get_by_ref(self):
policy_db = Policy.get_by_ref("wolfpack.action-1.concurrency")
self.assertIsNotNone(policy_db)
self.assertEqual(policy_db.pack, "wolfpack")
self.assertEqual(policy_db.name, "action-1.concurrency")
policy_type_db = PolicyType.get_by_ref(policy_db.policy_type)
self.assertIsNotNone(policy_type_db)
self.assertEqual(policy_type_db.resource_type, "action")
self.assertEqual(policy_type_db.name, "concurrency")
示例4: validate
# 需要导入模块: from st2common.persistence.policy import PolicyType [as 别名]
# 或者: from st2common.persistence.policy.PolicyType import get_by_ref [as 别名]
def validate(self):
# Validate policy itself
cleaned = super(PolicyAPI, self).validate()
# Validate policy parameters
policy_type_db = PolicyType.get_by_ref(cleaned.policy_type)
if not policy_type_db:
raise ValueError('Referenced policy_type "%s" doesnt exist' % (cleaned.policy_type))
parameters_schema = policy_type_db.parameters
parameters = getattr(cleaned, 'parameters', {})
schema = util_schema.get_schema_for_resource_parameters(
parameters_schema=parameters_schema)
validator = util_schema.get_validator()
cleaned_parameters = util_schema.validate(parameters, schema, validator, use_default=True,
allow_default_none=True)
cleaned.parameters = cleaned_parameters
return cleaned