本文整理汇总了Python中st2client.models.keyvalue.KeyValuePair.id方法的典型用法代码示例。如果您正苦于以下问题:Python KeyValuePair.id方法的具体用法?Python KeyValuePair.id怎么用?Python KeyValuePair.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2client.models.keyvalue.KeyValuePair
的用法示例。
在下文中一共展示了KeyValuePair.id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_value
# 需要导入模块: from st2client.models.keyvalue import KeyValuePair [as 别名]
# 或者: from st2client.models.keyvalue.KeyValuePair import id [as 别名]
def delete_value(self, name, local=True):
"""
Delete the provided key.
By default, value is deleted from a namespace local to the sensor. If you want to
delete a global value, pass local=False to this method.
:param name: Name of the key to delete.
:type name: ``str``
:param local: Delete a value in a namespace local to the sensor. Defaults to True.
:type: local: ``bool``
:return: ``True`` on success, ``False`` otherwise.
:rtype: ``bool``
"""
if local:
name = self._get_key_name_with_sensor_prefix(name=name)
client = self._get_api_client()
instance = KeyValuePair()
instance.id = name
instance.name = name
self._logger.audit('Deleting value from the datastore (name=%s)', name)
try:
client.keys.delete(instance=instance)
except Exception:
return False
return True
示例2: run
# 需要导入模块: from st2client.models.keyvalue import KeyValuePair [as 别名]
# 或者: from st2client.models.keyvalue.KeyValuePair import id [as 别名]
def run(self, args, **kwargs):
file_path = os.path.normpath(pjoin(os.getcwd(), args.file))
if not os.path.exists(args.file):
raise ValueError('File "%s" doesn\'t exist' % (file_path))
if not os.path.isfile(args.file):
raise ValueError('"%s" is not a file' % (file_path))
with open(file_path, 'r') as f:
kvps = json.loads(f.read())
instances = []
for item in kvps:
name = item['name']
value = item['value']
instance = KeyValuePair()
instance.id = name # TODO: refactor and get rid of id
instance.name = name
instance.value = value
self.manager.update(instance, **kwargs)
instances.append(instance)
return instances
示例3: run
# 需要导入模块: from st2client.models.keyvalue import KeyValuePair [as 别名]
# 或者: from st2client.models.keyvalue.KeyValuePair import id [as 别名]
def run(self, args, **kwargs):
# normalize the file path to allow for relative files to be specified
file_path = os.path.normpath(pjoin(os.getcwd(), args.file))
# load the data (JSON/YAML) from the file
kvps = resource.load_meta_file(file_path)
# if the data is not a list (ie. it's a single entry)
# then make it a list so our process loop is generic
if not isinstance(kvps, list):
kvps = [kvps]
instances = []
for item in kvps:
# parse required KeyValuePair properties
name = item['name']
value = item['value']
# parse optional KeyValuePair properties
scope = item.get('scope', DEFAULT_SCOPE)
user = item.get('user', None)
secret = item.get('secret', False)
ttl = item.get('ttl', None)
# if the value is not a string, convert it to JSON
# all keys in the datastore must strings
if not isinstance(value, six.string_types):
if args.convert:
value = json.dumps(value)
else:
raise ValueError(("Item '%s' has a value that is not a string."
" Either pass in the -c/--convert option to convert"
" non-string types to JSON strings automatically, or"
" convert the data to a string in the file") % name)
# create the KeyValuePair instance
instance = KeyValuePair()
instance.id = name # TODO: refactor and get rid of id
instance.name = name
instance.value = value
instance.scope = scope
if user:
instance.user = user
if secret:
instance.secret = secret
if ttl:
instance.ttl = ttl
# call the API to create/update the KeyValuePair
self.manager.update(instance, **kwargs)
instances.append(instance)
return instances
示例4: set_value
# 需要导入模块: from st2client.models.keyvalue import KeyValuePair [as 别名]
# 或者: from st2client.models.keyvalue.KeyValuePair import id [as 别名]
def set_value(self, name, value, ttl=None, local=True, scope=SYSTEM_SCOPE, encrypt=False):
"""
Store a value in a dictionary which is local to this class.
"""
if ttl:
raise ValueError('MockDatastoreService.set_value doesn\'t support "ttl" argument')
name = self._get_full_key_name(name=name, local=local)
instance = KeyValuePair()
instance.id = name
instance.name = name
instance.value = value
self._datastore_items[name] = instance
return True
示例5: run
# 需要导入模块: from st2client.models.keyvalue import KeyValuePair [as 别名]
# 或者: from st2client.models.keyvalue.KeyValuePair import id [as 别名]
def run(self, args, **kwargs):
instance = KeyValuePair()
instance.id = args.name # TODO: refactor and get rid of id
instance.name = args.name
instance.value = args.value
instance.scope = args.scope
instance.user = args.user
if args.secret:
instance.secret = args.secret
if args.encrypted:
instance.encrypted = args.encrypted
if args.ttl:
instance.ttl = args.ttl
return self.manager.update(instance, **kwargs)
示例6: set_value
# 需要导入模块: from st2client.models.keyvalue import KeyValuePair [as 别名]
# 或者: from st2client.models.keyvalue.KeyValuePair import id [as 别名]
def set_value(self, name, value, ttl=None, local=True):
"""
Set a value for the provided key.
By default, value is set in a namespace local to the sensor. If you want to
set a global value, pass local=False to this method.
:param name: Key name.
:type name: ``str``
:param value: Key value.
:type value: ``str``
:param ttl: Optional TTL (in seconds).
:type ttl: ``int``
:param local: Set value in a namespace local to the sensor. Defaults to True.
:type: local: ``bool``
:return: ``True`` on success, ``False`` otherwise.
:rtype: ``bool``
"""
if local:
name = self._get_key_name_with_sensor_prefix(name=name)
value = str(value)
client = self._get_api_client()
self._logger.audit('Setting value in the datastore (name=%s)', name)
instance = KeyValuePair()
instance.id = name
instance.name = name
instance.value = value
if ttl:
instance.ttl = ttl
client.keys.update(instance=instance)
return True