def _get_audit_period(): now = timeutils.utcnow() start_time = now - datetime.timedelta( seconds=CONF.exists_notification_interval) audit_start = timeutils.isotime(start_time) audit_end = timeutils.isotime(now) return audit_start, audit_end
def test_isotime(self): dt = timeutils.utcnow_aware() expected = "%04d-%02d-%02dT%02d:%02d:%02dZ" % ( dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second) self.assertEqual(expected, timeutils.isotime(dt))
def test_isotime_unaware_subsecond(self): dt = timeutils.utcnow() expected = "%04d-%02d-%02dT%02d:%02d:%02d.%06dZ" % ( dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond) self.assertEqual(expected, timeutils.isotime(dt, subsecond=True))
def test_bogus_unaware_subsecond(self): dt = datetime.now(bogus_tzinfo()) expected = "%04d-%02d-%02dT%02d:%02d:%02d.%06d+02:00" % ( dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond) self.assertEqual(expected, timeutils.isotime(dt, subsecond=True))
def data(self): get_utc = datetime.datetime.utcfromtimestamp next_avail = get_utc(self.rate_limit.get("resetTime", 0)) return { "limit": { "nextAvailable": timeutils.isotime(next_avail), "remaining": self.rate_limit.get("remaining", 0), "unit": self.rate_limit.get("unit", ""), "value": self.rate_limit.get("value", ""), "verb": self.rate_limit.get("verb", ""), "uri": self.rate_limit.get("URI", ""), "regex": self.rate_limit.get("regex", "") } }
def __init__(self, **kwargs): self.payload = {} instance = kwargs.pop('instance', None) if instance: self.instance = instance self.context = instance.context created_time = timeutils.isotime(instance.db_info.created) self.payload.update({ 'created_at': created_time, 'name': instance.name, 'instance_id': instance.id, 'instance_name': instance.name, 'instance_type_id': instance.flavor_id, 'launched_at': created_time, 'nova_instance_id': instance.server_id, 'region': CONF.region, 'state_description': instance.status.lower(), 'state': instance.status.lower(), 'tenant_id': instance.tenant_id, 'user_id': instance.context.user, }) self.payload.update(kwargs)