當前位置: 首頁>>代碼示例>>Python>>正文


Python KeyValuePair.ttl方法代碼示例

本文整理匯總了Python中st2client.models.keyvalue.KeyValuePair.ttl方法的典型用法代碼示例。如果您正苦於以下問題:Python KeyValuePair.ttl方法的具體用法?Python KeyValuePair.ttl怎麽用?Python KeyValuePair.ttl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在st2client.models.keyvalue.KeyValuePair的用法示例。


在下文中一共展示了KeyValuePair.ttl方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from st2client.models.keyvalue import KeyValuePair [as 別名]
# 或者: from st2client.models.keyvalue.KeyValuePair import ttl [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

        if args.ttl:
            instance.ttl = args.ttl

        return self.manager.update(instance, **kwargs)
開發者ID:automotola,項目名稱:st2,代碼行數:12,代碼來源:keyvalue.py

示例2: run

# 需要導入模塊: from st2client.models.keyvalue import KeyValuePair [as 別名]
# 或者: from st2client.models.keyvalue.KeyValuePair import ttl [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
開發者ID:lyandut,項目名稱:st2,代碼行數:55,代碼來源:keyvalue.py

示例3: run

# 需要導入模塊: from st2client.models.keyvalue import KeyValuePair [as 別名]
# 或者: from st2client.models.keyvalue.KeyValuePair import ttl [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)
開發者ID:StackStorm,項目名稱:st2,代碼行數:20,代碼來源:keyvalue.py

示例4: set_value

# 需要導入模塊: from st2client.models.keyvalue import KeyValuePair [as 別名]
# 或者: from st2client.models.keyvalue.KeyValuePair import ttl [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
開發者ID:jonico,項目名稱:st2,代碼行數:42,代碼來源:sensor_wrapper.py


注:本文中的st2client.models.keyvalue.KeyValuePair.ttl方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。