本文整理汇总了Python中oslo_utils.timeutils.utcnow方法的典型用法代码示例。如果您正苦于以下问题:Python timeutils.utcnow方法的具体用法?Python timeutils.utcnow怎么用?Python timeutils.utcnow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_utils.timeutils
的用法示例。
在下文中一共展示了timeutils.utcnow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_container_start
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def _do_container_start(self, context, container):
LOG.debug('Starting container: %s', container.uuid)
with self._update_task_state(context, container,
consts.CONTAINER_STARTING):
try:
# NOTE(hongbin): capsule shouldn't reach here
container = self.driver.start(context, container)
container.started_at = timeutils.utcnow()
container.save(context)
return container
except exception.DockerError as e:
with excutils.save_and_reraise_exception():
LOG.error("Error occurred while calling Docker start "
"API: %s", str(e))
self._fail_container(context, container, str(e))
except Exception as e:
with excutils.save_and_reraise_exception():
LOG.exception("Unexpected exception: %s",
str(e))
self._fail_container(context, container, str(e))
示例2: test_container_action_event_finish_success
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def test_container_action_event_finish_success(self):
"""Finish a container action event."""
uuid = uuidutils.generate_uuid()
action = dbapi.action_start(self.context,
self._create_action_values(uuid))
dbapi.action_event_start(self.context,
self._create_event_values(uuid))
event_values = {
'finish_time': timeutils.utcnow() + timedelta(seconds=5),
'result': 'Success'
}
event_values = self._create_event_values(uuid, extra=event_values)
event = dbapi.action_event_finish(self.context, event_values)
self._assertActionEventSaved(event, action['id'])
action = dbapi.action_get_by_request_id(self.context, uuid,
self.context.request_id)
self.assertNotEqual('Error', action['message'])
示例3: set_update_time_on_success
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def set_update_time_on_success(function):
"""Set updated time of HostState when consuming succeed."""
@functools.wraps(function)
def decorated_function(self, container):
return_value = None
try:
return_value = function(self, container)
except Exception as e:
# Ignores exception raised from consume_from_request() so that
# booting container would fail in the resource claim of compute
# node, other suitable node may be chosen during scheduling retry.
LOG.warning("Selected host: %(host)s failed to consume from "
"container. Error: %(error)s",
{'host': self.hostname, 'error': e})
else:
self.updated = timeutils.utcnow()
return return_value
return decorated_function
示例4: log_request_completion
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def log_request_completion(self, response, request, start):
apireq = request.environ.get('ec2.request', None)
if apireq:
action = apireq.action
else:
action = None
ctxt = request.environ.get('ec2api.context', None)
delta = timeutils.utcnow() - start
seconds = delta.seconds
microseconds = delta.microseconds
LOG.info(
"%s.%ss %s %s %s %s %s [%s] %s %s",
seconds,
microseconds,
request.remote_addr,
request.method,
"%s%s" % (request.script_name, request.path_info),
action,
response.status_int,
request.user_agent,
request.content_type,
response.content_type,
context=ctxt)
示例5: isotime
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def isotime(at=None, subsecond=False):
"""Stringify time in ISO 8601 format."""
# Python provides a similar instance method for datetime.datetime objects
# called isoformat(). The format of the strings generated by isoformat()
# have a couple of problems:
# 1) The strings generated by isotime are used in tokens and other public
# APIs that we can't change without a deprecation period. The strings
# generated by isoformat are not the same format, so we can't just
# change to it.
# 2) The strings generated by isoformat do not include the microseconds if
# the value happens to be 0. This will likely show up as random failures
# as parsers may be written to always expect microseconds, and it will
# parse correctly most of the time.
if not at:
at = timeutils.utcnow()
st = at.strftime(_ISO8601_TIME_FORMAT
if not subsecond
else _ISO8601_TIME_FORMAT_SUBSECOND)
tz = at.tzinfo.tzname(None) if at.tzinfo else 'UTC'
st += ('Z' if tz == 'UTC' else tz)
return st
示例6: _emit_heartbeat
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def _emit_heartbeat(self):
"""
Returns Status, Stats, Capabilities
"""
status, stats, capabilities = self.get_status()
service_status = objects.ServiceStatus(
service_name=self._service_name,
hostname=self._hostname,
status=status,
stats=stats,
capabilities=capabilities,
heartbeated_at=timeutils.utcnow()
)
LOG.trace('Emitting %s', service_status)
self.transmit(service_status)
示例7: add_pending_ucast_mac_remote
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def add_pending_ucast_mac_remote(context, operation,
ovsdb_identifier,
logical_switch_id,
physical_locator,
mac_remotes):
"""Insert a pending ucast_mac_remote (insert/update/delete)."""
session = context.session
with session.begin(subtransactions=True):
for mac in mac_remotes:
pending_mac = models.PendingUcastMacsRemote(
uuid=mac.get('uuid', None),
mac=mac['mac'],
logical_switch_uuid=logical_switch_id,
vm_ip=mac['ip_address'],
ovsdb_identifier=ovsdb_identifier,
operation=operation,
timestamp=timeutils.utcnow())
if physical_locator:
pending_mac['dst_ip'] = physical_locator.get('dst_ip', None)
pending_mac['locator_uuid'] = physical_locator.get('uuid',
None)
session.add(pending_mac)
示例8: update_magnum_service
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def update_magnum_service(self, magnum_service_id, values):
session = get_session()
with session.begin():
query = model_query(models.MagnumService, session=session)
query = add_identity_filter(query, magnum_service_id)
try:
ref = query.with_lockmode('update').one()
except NoResultFound:
raise exception.MagnumServiceNotFound(
magnum_service_id=magnum_service_id)
if 'report_count' in values:
if values['report_count'] > ref.report_count:
ref.last_seen_up = timeutils.utcnow()
ref.update(values)
return ref
示例9: isotime
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def isotime(at=None, subsecond=False):
"""Stringify time in ISO 8601 format."""
# Python provides a similar instance method for datetime.datetime objects
# called isoformat(). The format of the strings generated by isoformat()
# have a couple of problems:
# 1) The strings generated by isotime are used in tokens and other public
# APIs that we can't change without a deprecation period. The strings
# generated by isoformat are not the same format, so we can't just
# change to it.
# 2) The strings generated by isoformat do not include the microseconds if
# the value happens to be 0. This will likely show up as random failures
# as parsers may be written to always expect microseconds, and it will
# parse correctly most of the time.
if not at:
at = timeutils.utcnow()
st = at.strftime(_ISO8601_TIME_FORMAT
if not subsecond
else _ISO8601_TIME_FORMAT_SUBSECOND)
tz = at.tzinfo.tzname(None) if at.tzinfo else 'UTC'
# Need to handle either iso8601 or python UTC format
st += ('Z' if tz in ['UTC', 'UTC+00:00'] else tz)
return st
示例10: _quota_usage_create
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def _quota_usage_create(context, project_id, user_id, resource, in_use,
reserved, until_refresh, share_type_id=None,
session=None):
quota_usage_ref = models.QuotaUsage()
if share_type_id:
quota_usage_ref.share_type_id = share_type_id
else:
quota_usage_ref.user_id = user_id
quota_usage_ref.project_id = project_id
quota_usage_ref.resource = resource
quota_usage_ref.in_use = in_use
quota_usage_ref.reserved = reserved
quota_usage_ref.until_refresh = until_refresh
# updated_at is needed for judgement of max_age
quota_usage_ref.updated_at = timeutils.utcnow()
quota_usage_ref.save(session=session)
return quota_usage_ref
示例11: reservation_expire
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def reservation_expire(context):
session = get_session()
with session.begin():
current_time = timeutils.utcnow()
reservation_query = (model_query(
context, models.Reservation,
session=session, read_deleted="no").
filter(models.Reservation.expire < current_time))
for reservation in reservation_query.all():
if reservation.delta >= 0:
quota_usage = model_query(context, models.QuotaUsage,
session=session,
read_deleted="no").filter(
models.QuotaUsage.id == reservation.usage_id).first()
quota_usage.reserved -= reservation.delta
session.add(quota_usage)
reservation_query.soft_delete(synchronize_session=False)
################
示例12: backend_info_update
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def backend_info_update(context, host, value=None, delete_existing=False):
"""Remove backend info for host name."""
session = get_session()
with session.begin():
info_ref = _backend_info_query(session, context, host)
if info_ref:
if value:
info_ref.update({"info_hash": value})
elif delete_existing and info_ref['deleted'] != 1:
info_ref.update({"deleted": 1,
"deleted_at": timeutils.utcnow()})
else:
info_ref = models.BackendInfo()
info_ref.update({"host": host,
"info_hash": value})
info_ref.save(session)
return info_ref
示例13: downgrade
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def downgrade():
"""Performs DB downgrade removing support of 'optional snapshots' feature.
Remove 'snapshot_support' extra spec from all share types and
attr 'snapshot_support' from Share model.
"""
connection = op.get_bind().connect()
extra_specs = sa.Table(
'share_type_extra_specs',
sa.MetaData(),
autoload=True,
autoload_with=connection)
# pylint: disable=no-value-for-parameter
update = extra_specs.update().where(
extra_specs.c.spec_key == constants.ExtraSpecs.SNAPSHOT_SUPPORT).where(
extra_specs.c.deleted == 0).values(
deleted=extra_specs.c.id,
deleted_at=timeutils.utcnow(),
)
connection.execute(update)
op.drop_column('shares', 'snapshot_support')
开发者ID:openstack,项目名称:manila,代码行数:25,代码来源:55761e5f59c5_add_snapshot_support_extra_spec_to_share_types.py
示例14: collect_existing_az_from_services_table
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def collect_existing_az_from_services_table(connection, services_table,
az_table):
az_name_to_id_mapping = dict()
existing_az = []
for service in connection.execute(services_table.select()):
if service.availability_zone in az_name_to_id_mapping:
continue
az_id = uuidutils.generate_uuid()
az_name_to_id_mapping[service.availability_zone] = az_id
existing_az.append({
'created_at': timeutils.utcnow(),
'id': az_id,
'name': service.availability_zone
})
op.bulk_insert(az_table, existing_az)
return az_name_to_id_mapping
示例15: downgrade
# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import utcnow [as 别名]
def downgrade():
"""Performs DB downgrade removing create_share_from_snapshot_support.
Remove 'create_share_from_snapshot_support' extra spec from all share types
and attribute 'create_share_from_snapshot_support' from Share model.
"""
connection = op.get_bind().connect()
deleted_at = timeutils.utcnow()
extra_specs = sa.Table(
'share_type_extra_specs',
sa.MetaData(),
autoload=True,
autoload_with=connection)
# pylint: disable=no-value-for-parameter
update = extra_specs.update().where(
extra_specs.c.spec_key ==
constants.ExtraSpecs.CREATE_SHARE_FROM_SNAPSHOT_SUPPORT).where(
extra_specs.c.deleted == 0).values(deleted=extra_specs.c.id,
deleted_at=deleted_at)
connection.execute(update)
op.drop_column('shares', 'create_share_from_snapshot_support')