Replace deprecated oslo_utils.timeutils.isotime
The isotime method in oslo_utils.timeutils module was deprecated long ago[1], and remaining usage of the deprecated method causes DeprecationWarning[2]. This change replaces the deprecated method by a new method implemented as part of utility methods. [1] 5cad113739fa906c3901e530fcbfdee3b48961c1 [2] DeprecationWarning: Using function/method 'isotime()' is deprecated in version '1.6' and will be removed in a future version: use datetime.datetime.isoformat() Change-Id: I2371e66d84ce8226700d32c90c0730b7c7e607a0
This commit is contained in:
parent
fe13beaa76
commit
2938ff9d3a
@ -21,13 +21,13 @@ import copy
|
||||
import re
|
||||
|
||||
from oslo_log import log
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from requests import RequestException
|
||||
|
||||
from ceilometer import declarative
|
||||
from ceilometer.polling import plugin_base
|
||||
from ceilometer import sample as ceilometer_sample
|
||||
from ceilometer import utils as ceilometer_utils
|
||||
|
||||
from functools import reduce
|
||||
import operator
|
||||
@ -123,7 +123,7 @@ class PollsterSampleExtractor(object):
|
||||
self.generate_new_metadata_fields(
|
||||
metadata=metadata, pollster_definitions=pollster_definitions)
|
||||
return ceilometer_sample.Sample(
|
||||
timestamp=timeutils.isotime(),
|
||||
timestamp=ceilometer_utils.isotime(),
|
||||
name=pollster_definitions['name'],
|
||||
type=pollster_definitions['sample_type'],
|
||||
unit=pollster_definitions['unit'],
|
||||
|
@ -21,6 +21,7 @@
|
||||
import threading
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import timeutils
|
||||
|
||||
ROOTWRAP_CONF = "/etc/ceilometer/rootwrap.conf"
|
||||
|
||||
@ -47,3 +48,16 @@ def spawn_thread(target, *args, **kwargs):
|
||||
t.daemon = True
|
||||
t.start()
|
||||
return t
|
||||
|
||||
|
||||
def isotime(at=None):
|
||||
"""Current time as ISO string,
|
||||
|
||||
:returns: Current time in ISO format
|
||||
"""
|
||||
if not at:
|
||||
at = timeutils.utcnow()
|
||||
date_string = at.strftime("%Y-%m-%dT%H:%M:%S")
|
||||
tz = at.tzinfo.tzname(None) if at.tzinfo else 'UTC'
|
||||
date_string += ('Z' if tz == 'UTC' else tz)
|
||||
return date_string
|
||||
|
Loading…
x
Reference in New Issue
Block a user