Python oslo_utils.timeutils.utcnow_ts() Examples

The following are 14 code examples of oslo_utils.timeutils.utcnow_ts(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oslo_utils.timeutils , or try the search function .
Example #1
Source File: utils.py    From designate with Apache License 2.0 5 votes vote down vote up
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 
Example #2
Source File: dictionary.py    From oslo.cache with Apache License 2.0 5 votes vote down vote up
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 
Example #3
Source File: dictionary.py    From oslo.cache with Apache License 2.0 5 votes vote down vote up
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) 
Example #4
Source File: dictionary.py    From oslo.cache with Apache License 2.0 5 votes vote down vote up
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] 
Example #5
Source File: model.py    From monasca-api with Apache License 2.0 5 votes vote down vote up
def _get_creation_time():
        return timeutils.utcnow_ts() 
Example #6
Source File: metrics.py    From monasca-api with Apache License 2.0 5 votes vote down vote up
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)] 
Example #7
Source File: model.py    From monasca-log-api with Apache License 2.0 5 votes vote down vote up
def _get_creation_time():
        return timeutils.utcnow_ts() 
Example #8
Source File: test_gnocchi.py    From aodh with Apache License 2.0 5 votes vote down vote up
def _get_stats(granularity, values):
        now = timeutils.utcnow_ts()
        return [[six.text_type(now - len(values) * granularity),
                 granularity, value] for value in values] 
Example #9
Source File: test_composite.py    From aodh with Apache License 2.0 5 votes vote down vote up
def _get_gnocchi_stats(granularity, values):
        now = timeutils.utcnow_ts()
        return [[six.text_type(now - len(values) * granularity),
                 granularity, value] for value in values] 
Example #10
Source File: service.py    From oslo.vmware with Apache License 2.0 5 votes vote down vote up
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] 
Example #11
Source File: service.py    From oslo.vmware with Apache License 2.0 5 votes vote down vote up
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 
Example #12
Source File: test_timeutils.py    From oslo.utils with Apache License 2.0 5 votes vote down vote up
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)) 
Example #13
Source File: test_timeutils.py    From oslo.utils with Apache License 2.0 5 votes vote down vote up
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) 
Example #14
Source File: test_timeutils.py    From oslo.utils with Apache License 2.0 5 votes vote down vote up
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))