本文整理汇总了Python中st2common.persistence.keyvalue.KeyValuePair.get_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python KeyValuePair.get_by_name方法的具体用法?Python KeyValuePair.get_by_name怎么用?Python KeyValuePair.get_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.keyvalue.KeyValuePair
的用法示例。
在下文中一共展示了KeyValuePair.get_by_name方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_kvp_for_name
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import get_by_name [as 别名]
def get_kvp_for_name(name):
try:
kvp_db = KeyValuePair.get_by_name(name)
except ValueError:
kvp_db = None
return kvp_db
示例2: get_required_sensor_refs
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import get_by_name [as 别名]
def get_required_sensor_refs(self):
partition_lookup_key = self._get_partition_lookup_key(self.sensor_node_name)
kvp = KeyValuePair.get_by_name(partition_lookup_key)
sensor_refs_str = kvp.value if kvp.value else ''
self._supported_sensor_refs = set([
sensor_ref.strip() for sensor_ref in sensor_refs_str.split(',')])
return self._supported_sensor_refs
示例3: test_kvp_crud
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import get_by_name [as 别名]
def test_kvp_crud(self):
saved = KeyValuePairModelTest._create_save_kvp()
retrieved = KeyValuePair.get_by_name(saved.name)
self.assertEqual(saved.id, retrieved.id, "Same KeyValuePair was not returned.")
# test update
self.assertEqual(retrieved.value, "0123456789ABCDEF")
retrieved.value = "ABCDEF0123456789"
saved = KeyValuePair.add_or_update(retrieved)
retrieved = KeyValuePair.get_by_name(saved.name)
self.assertEqual(retrieved.value, "ABCDEF0123456789", "Update of key value failed")
# cleanup
KeyValuePairModelTest._delete([retrieved])
try:
retrieved = KeyValuePair.get_by_name(saved.name)
except StackStormDBObjectNotFoundError:
retrieved = None
self.assertIsNone(retrieved, "managed to retrieve after failure.")
示例4: _get_kv
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import get_by_name [as 别名]
def _get_kv(self, key):
kvp = None
try:
kvp = KeyValuePair.get_by_name(key)
except ValueError:
# ValueErrors are expected in case of partial lookups
pass
# A good default value for un-matched value is empty string since that will be used
# for rendering templates.
return kvp.value if kvp else ''
示例5: test_kvp_crud
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import get_by_name [as 别名]
def test_kvp_crud(self):
saved = KeyValuePairModelTest._create_save_kvp()
retrieved = KeyValuePair.get_by_name(saved.name)
self.assertEqual(saved.id, retrieved.id,
'Same KeyValuePair was not returned.')
# test update
self.assertEqual(retrieved.value, '0123456789ABCDEF')
retrieved.value = 'ABCDEF0123456789'
saved = KeyValuePair.add_or_update(retrieved)
retrieved = KeyValuePair.get_by_name(saved.name)
self.assertEqual(retrieved.value, 'ABCDEF0123456789',
'Update of key value failed')
# cleanup
KeyValuePairModelTest._delete([retrieved])
try:
retrieved = KeyValuePair.get_by_name(saved.name)
except ValueError:
retrieved = None
self.assertIsNone(retrieved, 'managed to retrieve after failure.')
示例6: __get_by_name
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import get_by_name [as 别名]
def __get_by_name(name):
try:
return KeyValuePair.get_by_name(name)
except ValueError as e:
LOG.debug('Database lookup for name="%s" resulted in exception : %s.', name, e)
return None