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


Python timeutils.utcnow_ts方法代碼示例

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


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

示例1: increment_serial

# 需要導入模塊: from oslo_utils import timeutils [as 別名]
# 或者: from oslo_utils.timeutils import utcnow_ts [as 別名]
def increment_serial(serial=0):
    # This provides for *roughly* unix timestamp based serial numbers
    new_serial = timeutils.utcnow_ts()

    if new_serial <= serial:
        new_serial = serial + 1

    return new_serial 
開發者ID:openstack,項目名稱:designate,代碼行數:10,代碼來源:utils.py

示例2: get

# 需要導入模塊: from oslo_utils import timeutils [as 別名]
# 或者: from oslo_utils.timeutils import utcnow_ts [as 別名]
def get(self, key):
        """Retrieves the value for a key.

        :param key: dictionary key
        :returns: value for a key or :data:`oslo_cache.core.NO_VALUE`
            for nonexistent or expired keys.
        """
        (value, timeout) = self.cache.get(key, (_NO_VALUE, 0))
        if self.expiration_time > 0 and timeutils.utcnow_ts() >= timeout:
            self.cache.pop(key, None)
            return _NO_VALUE

        return value 
開發者ID:openstack,項目名稱:oslo.cache,代碼行數:15,代碼來源:dictionary.py

示例3: set_multi

# 需要導入模塊: from oslo_utils import timeutils [as 別名]
# 或者: from oslo_utils.timeutils import utcnow_ts [as 別名]
def set_multi(self, mapping):
        """Set multiple values in the cache.
        Expunges expired keys during each set.

        :param mapping: dictionary with key/value pairs
        """
        self._clear()
        timeout = 0
        if self.expiration_time > 0:
            timeout = timeutils.utcnow_ts() + self.expiration_time
        for key, value in mapping.items():
            self.cache[key] = (value, timeout) 
開發者ID:openstack,項目名稱:oslo.cache,代碼行數:14,代碼來源:dictionary.py

示例4: _clear

# 需要導入模塊: from oslo_utils import timeutils [as 別名]
# 或者: from oslo_utils.timeutils import utcnow_ts [as 別名]
def _clear(self):
        """Expunges expired keys."""
        now = timeutils.utcnow_ts()
        for k in list(self.cache):
            (_value, timeout) = self.cache[k]
            if timeout > 0 and now >= timeout:
                del self.cache[k] 
開發者ID:openstack,項目名稱:oslo.cache,代碼行數:9,代碼來源:dictionary.py

示例5: _get_creation_time

# 需要導入模塊: from oslo_utils import timeutils [as 別名]
# 或者: from oslo_utils.timeutils import utcnow_ts [as 別名]
def _get_creation_time():
        return timeutils.utcnow_ts() 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:4,代碼來源:model.py

示例6: transform

# 需要導入模塊: from oslo_utils import timeutils [as 別名]
# 或者: from oslo_utils.timeutils import utcnow_ts [as 別名]
def transform(metrics, tenant_id, region):
    transformed_metric = {'metric': {},
                          'meta': {'tenantId': tenant_id, 'region': region},
                          'creation_time': timeutils.utcnow_ts()}

    if isinstance(metrics, list):
        transformed_metrics = []
        for metric in metrics:
            transformed_metric['metric'] = metric
            transformed_metrics.append(rest_utils.as_json(transformed_metric))
        return transformed_metrics
    else:
        transformed_metric['metric'] = metrics
        return [rest_utils.as_json(transformed_metric)] 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:16,代碼來源:metrics.py

示例7: _get_stats

# 需要導入模塊: from oslo_utils import timeutils [as 別名]
# 或者: from oslo_utils.timeutils import utcnow_ts [as 別名]
def _get_stats(granularity, values):
        now = timeutils.utcnow_ts()
        return [[six.text_type(now - len(values) * granularity),
                 granularity, value] for value in values] 
開發者ID:openstack,項目名稱:aodh,代碼行數:6,代碼來源:test_gnocchi.py

示例8: _get_gnocchi_stats

# 需要導入模塊: from oslo_utils import timeutils [as 別名]
# 或者: from oslo_utils.timeutils import utcnow_ts [as 別名]
def _get_gnocchi_stats(granularity, values):
        now = timeutils.utcnow_ts()
        return [[six.text_type(now - len(values) * granularity),
                 granularity, value] for value in values] 
開發者ID:openstack,項目名稱:aodh,代碼行數:6,代碼來源:test_composite.py

示例9: get

# 需要導入模塊: from oslo_utils import timeutils [as 別名]
# 或者: from oslo_utils.timeutils import utcnow_ts [as 別名]
def get(self, key):
        """Retrieves the value for a key or None."""
        now = timeutils.utcnow_ts()
        for k in list(self._cache):
            (timeout, _value) = self._cache[k]
            if timeout and now >= timeout:
                del self._cache[k]

        return self._cache.get(key, (0, None))[1] 
開發者ID:openstack,項目名稱:oslo.vmware,代碼行數:11,代碼來源:service.py

示例10: put

# 需要導入模塊: from oslo_utils import timeutils [as 別名]
# 或者: from oslo_utils.timeutils import utcnow_ts [as 別名]
def put(self, key, value, time=CACHE_TIMEOUT):
        """Sets the value for a key."""
        timeout = 0
        if time != 0:
            timeout = timeutils.utcnow_ts() + time
        self._cache[key] = (timeout, value)
        return True 
開發者ID:openstack,項目名稱:oslo.vmware,代碼行數:9,代碼來源:service.py

示例11: test_set_time_override_using_default

# 需要導入模塊: from oslo_utils import timeutils [as 別名]
# 或者: from oslo_utils.timeutils import utcnow_ts [as 別名]
def test_set_time_override_using_default(self):
        now = timeutils.utcnow_ts()

        # NOTE(kgriffs): Normally it's bad form to sleep in a unit test,
        # but this is the only way to test that set_time_override defaults
        # to setting the override to the current time.
        time.sleep(1)

        timeutils.set_time_override()
        overriden_now = timeutils.utcnow_ts()
        self.assertThat(now, matchers.LessThan(overriden_now)) 
開發者ID:openstack,項目名稱:oslo.utils,代碼行數:13,代碼來源:test_timeutils.py

示例12: test_utcnow_ts

# 需要導入模塊: from oslo_utils import timeutils [as 別名]
# 或者: from oslo_utils.timeutils import utcnow_ts [as 別名]
def test_utcnow_ts(self):
        skynet_self_aware_ts = 872835240
        skynet_dt = datetime.datetime.utcfromtimestamp(skynet_self_aware_ts)
        self.assertEqual(self.skynet_self_aware_time, skynet_dt)

        # NOTE(kgriffs): timeutils.utcnow_ts() uses time.time()
        # IFF time override is not set.
        with mock.patch('time.time') as time_mock:
            time_mock.return_value = skynet_self_aware_ts
            ts = timeutils.utcnow_ts()
            self.assertEqual(ts, skynet_self_aware_ts)

        timeutils.set_time_override(skynet_dt)
        ts = timeutils.utcnow_ts()
        self.assertEqual(ts, skynet_self_aware_ts) 
開發者ID:openstack,項目名稱:oslo.utils,代碼行數:17,代碼來源:test_timeutils.py

示例13: test_iso8601_from_timestamp_ms

# 需要導入模塊: from oslo_utils import timeutils [as 別名]
# 或者: from oslo_utils.timeutils import utcnow_ts [as 別名]
def test_iso8601_from_timestamp_ms(self):
        ts = timeutils.utcnow_ts(microsecond=True)
        utcnow = datetime.datetime.utcfromtimestamp(ts)
        iso = timeutils.isotime(utcnow, subsecond=True)
        self.assertEqual(iso, timeutils.iso8601_from_timestamp(ts, True)) 
開發者ID:openstack,項目名稱:oslo.utils,代碼行數:7,代碼來源:test_timeutils.py


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