Python oslo_utils.timeutils.normalize_time() Examples
The following are 30
code examples of oslo_utils.timeutils.normalize_time().
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: services.py From senlin with Apache License 2.0 | 6 votes |
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}
Example #2
Source File: validators.py From sgx-kms with Apache License 2.0 | 6 votes |
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
Example #3
Source File: validators.py From sgx-kms with Apache License 2.0 | 6 votes |
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', None) if expiration_raw and expiration_raw.strip(): try: expiration_tz = timeutils.parse_isotime(expiration_raw) 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
Example #4
Source File: validators.py From barbican with Apache License 2.0 | 6 votes |
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', None) if expiration_raw and expiration_raw.strip(): try: expiration_tz = timeutils.parse_isotime(expiration_raw) 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
Example #5
Source File: validators.py From barbican with Apache License 2.0 | 6 votes |
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
Example #6
Source File: __init__.py From karbor with Apache License 2.0 | 5 votes |
def _compare(test, db, obj): for field, value in db.items(): if not hasattr(obj, field): continue if (isinstance(obj.fields[field], fields.DateTimeField) and db[field]): test.assertEqual(db[field], timeutils.normalize_time(obj[field])) elif isinstance(obj[field], obj_base.ObjectListBase): test.assertEqual(db[field], obj[field].objects) else: test.assertEqual(db[field], obj[field])
Example #7
Source File: types.py From senlin with Apache License 2.0 | 5 votes |
def process_bind_param(self, value, dialect): if value is None: return None if dialect.name == 'mysql': return timeutils.normalize_time(value) return value
Example #8
Source File: test_sqlalchemy_types.py From senlin with Apache License 2.0 | 5 votes |
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)
Example #9
Source File: server.py From coriolis with GNU Affero General Public License v3.0 | 5 votes |
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
Example #10
Source File: replica_schedules.py From coriolis with GNU Affero General Public License v3.0 | 5 votes |
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
Example #11
Source File: event.py From aodh with Apache License 2.0 | 5 votes |
def _sanitize_trait_value(value, trait_type): if trait_type in (2, 'integer'): return int(value) elif trait_type in (3, 'float'): return float(value) elif trait_type in (4, 'datetime'): return timeutils.normalize_time(timeutils.parse_isotime(value)) else: return six.text_type(value)
Example #12
Source File: __init__.py From aodh with Apache License 2.0 | 5 votes |
def sanitize_timestamp(timestamp): """Return a naive utc datetime object.""" if not timestamp: return timestamp if not isinstance(timestamp, datetime.datetime): timestamp = timeutils.parse_isotime(timestamp) return timeutils.normalize_time(timestamp)
Example #13
Source File: test_repositories.py From monasca-api with Apache License 2.0 | 5 votes |
def _convert_time_string(date_time_string): dt = timeutils.parse_isotime(date_time_string) dt = timeutils.normalize_time(dt) return dt
Example #14
Source File: test_timeutils.py From oslo.utils with Apache License 2.0 | 5 votes |
def test_zulu_normalize(self): time_str = '2012-02-14T20:53:07Z' zulu = timeutils.parse_isotime(time_str) normed = timeutils.normalize_time(zulu) self._instaneous(normed, 2012, 2, 14, 20, 53, 7, 0)
Example #15
Source File: test_timeutils.py From oslo.utils with Apache License 2.0 | 5 votes |
def test_east_normalize(self): time_str = '2012-02-14T20:53:07-07:00' east = timeutils.parse_isotime(time_str) normed = timeutils.normalize_time(east) self._instaneous(normed, 2012, 2, 15, 3, 53, 7, 0)
Example #16
Source File: test_timeutils.py From oslo.utils with Apache License 2.0 | 5 votes |
def test_west_normalize(self): time_str = '2012-02-14T20:53:07+21:00' west = timeutils.parse_isotime(time_str) normed = timeutils.normalize_time(west) self._instaneous(normed, 2012, 2, 13, 23, 53, 7, 0)
Example #17
Source File: test_timeutils.py From oslo.utils with Apache License 2.0 | 5 votes |
def test_normalize_aware_to_naive(self): dt = datetime.datetime(2011, 2, 14, 20, 53, 7) time_str = '2011-02-14T20:53:07+21:00' aware = timeutils.parse_isotime(time_str) naive = timeutils.normalize_time(aware) self.assertTrue(naive < dt)
Example #18
Source File: test_timeutils.py From oslo.utils with Apache License 2.0 | 5 votes |
def test_normalize_zulu_aware_to_naive(self): dt = datetime.datetime(2011, 2, 14, 20, 53, 7) time_str = '2011-02-14T19:53:07Z' aware = timeutils.parse_isotime(time_str) naive = timeutils.normalize_time(aware) self.assertTrue(naive < dt)
Example #19
Source File: utils.py From python-cloudkittyclient with Apache License 2.0 | 5 votes |
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
Example #20
Source File: metrics_repository.py From monasca-api with Apache License 2.0 | 5 votes |
def _parse_time_string(timestamp): dt = timeutils.parse_isotime(timestamp) dt = timeutils.normalize_time(dt) return dt
Example #21
Source File: helpers.py From monasca-api with Apache License 2.0 | 5 votes |
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
Example #22
Source File: test_secrets.py From barbican with Apache License 2.0 | 5 votes |
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)
Example #23
Source File: repositories.py From barbican with Apache License 2.0 | 5 votes |
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
Example #24
Source File: models.py From barbican with Apache License 2.0 | 5 votes |
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
Example #25
Source File: __init__.py From cloudkitty with Apache License 2.0 | 5 votes |
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
Example #26
Source File: history_facade.py From vitrage with Apache License 2.0 | 5 votes |
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
Example #27
Source File: service.py From vitrage with Apache License 2.0 | 5 votes |
def event_time(data): event_timestamp = \ dateutil.parser.parse(data.get(ElementProps.UPDATE_TIMESTAMP)) event_timestamp = timeutils.normalize_time(event_timestamp) return event_timestamp
Example #28
Source File: test_secrets.py From sgx-kms with Apache License 2.0 | 5 votes |
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)
Example #29
Source File: repositories.py From sgx-kms with Apache License 2.0 | 5 votes |
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
Example #30
Source File: models.py From sgx-kms with Apache License 2.0 | 5 votes |
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