本文整理匯總了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
示例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
示例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)
示例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]
示例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()
示例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)]
示例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]
示例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]
示例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]
示例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
示例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))
示例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)
示例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))