Make notifications properly string-convert instance datetimes
Instance objects use real datetimes for launched_at and terminated_at. This patch makes the notification information function properly handle those. Related to blueprint compute-api-objects Change-Id: I8622662a83ff0bdc75ffc9e267c5485925326f24
This commit is contained in:
@@ -19,6 +19,8 @@
|
|||||||
the system.
|
the system.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from nova.compute import flavors
|
from nova.compute import flavors
|
||||||
@@ -291,6 +293,12 @@ def info_from_instance(context, instance_ref, network_info,
|
|||||||
def null_safe_str(s):
|
def null_safe_str(s):
|
||||||
return str(s) if s else ''
|
return str(s) if s else ''
|
||||||
|
|
||||||
|
def null_safe_isotime(s):
|
||||||
|
if isinstance(s, datetime.datetime):
|
||||||
|
return timeutils.strtime(s)
|
||||||
|
else:
|
||||||
|
return str(s) if s else ''
|
||||||
|
|
||||||
image_ref_url = glance.generate_image_url(instance_ref['image_ref'])
|
image_ref_url = glance.generate_image_url(instance_ref['image_ref'])
|
||||||
|
|
||||||
instance_type = flavors.extract_flavor(instance_ref)
|
instance_type = flavors.extract_flavor(instance_ref)
|
||||||
@@ -335,8 +343,8 @@ def info_from_instance(context, instance_ref, network_info,
|
|||||||
# Nova's deleted vs terminated instance terminology is confusing,
|
# Nova's deleted vs terminated instance terminology is confusing,
|
||||||
# this should be when the instance was deleted (i.e. terminated_at),
|
# this should be when the instance was deleted (i.e. terminated_at),
|
||||||
# not when the db record was deleted. (mdragon)
|
# not when the db record was deleted. (mdragon)
|
||||||
deleted_at=null_safe_str(instance_ref.get('terminated_at')),
|
deleted_at=null_safe_isotime(instance_ref.get('terminated_at')),
|
||||||
launched_at=null_safe_str(instance_ref.get('launched_at')),
|
launched_at=null_safe_isotime(instance_ref.get('launched_at')),
|
||||||
|
|
||||||
# Image properties
|
# Image properties
|
||||||
image_ref_url=image_ref_url,
|
image_ref_url=image_ref_url,
|
||||||
|
|||||||
Reference in New Issue
Block a user