本文整理汇总了Python中oslo_utils.timeutils.normalize_time方法的典型用法代码示例。如果您正苦于以下问题:Python timeutils.normalize_time方法的具体用法?Python timeutils.normalize_time怎么用?Python timeutils.normalize_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_utils.timeutils
的用法示例。
在下文中一共展示了timeutils.normalize_time方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _extract_expiration
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def _extract_expiration(self, json_data, schema_name):
"""Extracts and returns the expiration date from the JSON data."""
expiration = None
expiration_raw = json_data.get('expiration')
if expiration_raw and expiration_raw.strip():
try:
expiration_tz = timeutils.parse_isotime(expiration_raw.strip())
expiration = timeutils.normalize_time(expiration_tz)
except ValueError:
LOG.exception("Problem parsing expiration date")
raise exception.InvalidObject(
schema=schema_name,
reason=u._("Invalid date for 'expiration'"),
property="expiration")
return expiration
示例2: index
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def index(self, req):
if not req.context.is_admin:
raise exception.Forbidden()
now = timeutils.utcnow(with_timezone=True)
_services = service_obj.Service.get_all(req.context)
svcs = []
for svc in _services:
updated_at = svc.updated_at
delta = now - (svc.updated_at or svc.created_at)
delta_sec = delta.total_seconds()
alive = abs(delta_sec) <= CONF.service_down_time
art = (alive and "up") or "down"
active = 'enabled'
if svc.disabled:
active = 'disabled'
if updated_at:
updated_at = timeutils.normalize_time(updated_at)
ret_fields = {'id': svc.id, 'host': svc.host,
'binary': svc.binary, 'topic': svc.topic,
'disabled_reason': svc.disabled_reason,
'status': active, 'state': art,
'updated_at': updated_at}
svcs.append(ret_fields)
return {'services': svcs}
示例3: _iso_to_datetime
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def _iso_to_datetime(self, expiration):
"""Convert ISO formatted string to datetime."""
if isinstance(expiration, six.string_types):
expiration_iso = timeutils.parse_isotime(expiration.strip())
expiration = timeutils.normalize_time(expiration_iso)
return expiration
示例4: update_entity
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def update_entity(self, old_ca, parsed_ca_in, session=None):
"""Updates CA entry and its sub-entries."""
parsed_ca = dict(parsed_ca_in)
# these fields cannot be modified
parsed_ca.pop('plugin_name', None)
parsed_ca.pop('plugin_ca_id', None)
expiration = parsed_ca.pop('expiration', None)
expiration_iso = timeutils.parse_isotime(expiration.strip())
new_expiration = timeutils.normalize_time(expiration_iso)
session = self.get_session(session)
query = session.query(models.CertificateAuthority).filter_by(
id=old_ca.id, deleted=False)
entity = query.one()
entity.expiration = new_expiration
for k, v in entity.ca_meta.items():
if k not in parsed_ca.keys():
v.delete(session)
for key in parsed_ca:
if key not in entity.ca_meta.keys():
meta = models.CertificateAuthorityMetadatum(
key, parsed_ca[key])
entity.ca_meta[key] = meta
else:
entity.ca_meta[key].value = parsed_ca[key]
entity.save()
return entity
示例5: test_expiration_should_be_normalized_with_new_secret
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def test_expiration_should_be_normalized_with_new_secret(self):
target_expiration = '2114-02-28 12:14:44.180394-05:00'
resp, secret_uuid = create_secret(
self.app,
expiration=target_expiration
)
self.assertEqual(201, resp.status_int)
# Verify that the system normalizes time to UTC
secret = secrets_repo.get(secret_uuid, self.project_id)
local_datetime = timeutils.parse_isotime(target_expiration)
datetime_utc = timeutils.normalize_time(local_datetime)
self.assertEqual(datetime_utc, secret.expiration)
示例6: event_time
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def event_time(data):
event_timestamp = \
dateutil.parser.parse(data.get(ElementProps.UPDATE_TIMESTAMP))
event_timestamp = timeutils.normalize_time(event_timestamp)
return event_timestamp
示例7: _add_time_frame_to_query
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def _add_time_frame_to_query(query, start, end):
start = timeutils.normalize_time(start)
if start and end:
end = timeutils.normalize_time(end)
query = \
query.filter(
or_(and_(models.Alarm.start_timestamp >= start,
models.Alarm.start_timestamp <= end),
and_(models.Alarm.end_timestamp >= start,
models.Alarm.end_timestamp <= end),
and_(models.Alarm.start_timestamp <= start,
models.Alarm.end_timestamp >= end)))
elif start:
query = query.filter(models.Alarm.end_timestamp >= start)
return query
示例8: iso2dt
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def iso2dt(iso_date):
"""iso8601 format to datetime."""
iso_dt = timeutils.parse_isotime(iso_date)
trans_dt = timeutils.normalize_time(iso_dt)
return trans_dt
示例9: _convert_time_string
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def _convert_time_string(date_time_string):
dt = timeutils.parse_isotime(date_time_string)
dt = timeutils.normalize_time(dt)
timestamp = (dt - datetime.datetime(1970, 1, 1)).total_seconds()
return timestamp
示例10: _convert_time_string
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def _convert_time_string(date_time_string):
dt = timeutils.parse_isotime(date_time_string)
dt = timeutils.normalize_time(dt)
return dt
示例11: _parse_time_string
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def _parse_time_string(timestamp):
dt = timeutils.parse_isotime(timestamp)
dt = timeutils.normalize_time(dt)
return dt
示例12: process_bind_param
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def process_bind_param(self, value, dialect):
if value is None:
return None
if dialect.name == 'mysql':
return timeutils.normalize_time(value)
return value
示例13: test_process_bind_param_mysql
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def test_process_bind_param_mysql(self):
dialect = mock.Mock()
dialect.name = 'mysql'
value = timeutils.utcnow(True)
expected_value = timeutils.normalize_time(value)
result = self.sqltype.process_bind_param(value, dialect)
self.assertEqual(expected_value, result)
示例14: _deserialize_schedule
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def _deserialize_schedule(self, sched):
expires = sched.get("expiration_date")
if expires:
sched["expiration_date"] = timeutils.normalize_time(
timeutils.parse_isotime(expires))
tmp = sched["schedule"]
if type(tmp) is str:
sched["schedule"] = json.loads(tmp)
return sched
示例15: _validate_expiration_date
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import normalize_time [as 别名]
def _validate_expiration_date(self, expiration_date):
if expiration_date is None:
return expiration_date
exp = timeutils.normalize_time(
timeutils.parse_isotime(expiration_date))
now = timeutils.utcnow()
if now > exp:
raise exception.InvalidInput(
"expiration_date is in the past")
return exp