Moves usage_from_instance
into nova.compute.utils.
Change-Id: If6ae23847fb6d150f97a538dc37d47279c183243
This commit is contained in:
parent
ca5d8fae4d
commit
e6b4c646b3
@ -606,7 +606,7 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
def _notify_about_instance_usage(self, instance, event_suffix,
|
||||
usage_info=None, network_info=None):
|
||||
if not usage_info:
|
||||
usage_info = utils.usage_from_instance(instance,
|
||||
usage_info = compute_utils.usage_from_instance(instance,
|
||||
network_info=network_info)
|
||||
notifier.notify('compute.%s' % self.host,
|
||||
'compute.instance.%s' % event_suffix,
|
||||
@ -1301,7 +1301,7 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
'migration_id': migration_ref['id'],
|
||||
'image': image}})
|
||||
|
||||
usage_info = utils.usage_from_instance(instance_ref,
|
||||
usage_info = compute_utils.usage_from_instance(instance_ref,
|
||||
new_instance_type=new_instance_type['name'],
|
||||
new_instance_type_id=new_instance_type['id'])
|
||||
self._notify_about_instance_usage(instance_ref, "resize.prep.end",
|
||||
@ -1552,7 +1552,7 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
vm_state=vm_states.SUSPENDED,
|
||||
task_state=None)
|
||||
|
||||
usage_info = utils.usage_from_instance(instance_ref)
|
||||
usage_info = compute_utils.usage_from_instance(instance_ref)
|
||||
notifier.notify('compute.%s' % self.host, 'compute.instance.suspend',
|
||||
notifier.INFO, usage_info)
|
||||
|
||||
@ -1574,7 +1574,7 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
vm_state=vm_states.ACTIVE,
|
||||
task_state=None)
|
||||
|
||||
usage_info = utils.usage_from_instance(instance_ref)
|
||||
usage_info = compute_utils.usage_from_instance(instance_ref)
|
||||
notifier.notify('compute.%s' % self.host, 'compute.instance.resume',
|
||||
notifier.INFO, usage_info)
|
||||
|
||||
|
@ -67,7 +67,7 @@ def notify_usage_exists(instance_ref, current_period=False):
|
||||
break
|
||||
|
||||
bw[label] = dict(bw_in=b.bw_in, bw_out=b.bw_out)
|
||||
usage_info = utils.usage_from_instance(instance_ref,
|
||||
usage_info = usage_from_instance(instance_ref,
|
||||
audit_period_beginning=str(audit_start),
|
||||
audit_period_ending=str(audit_end),
|
||||
bandwidth=bw)
|
||||
@ -190,3 +190,33 @@ def legacy_network_info(network_model):
|
||||
|
||||
network_info.append((network_dict, info_dict))
|
||||
return network_info
|
||||
|
||||
|
||||
def usage_from_instance(instance_ref, network_info=None, **kw):
|
||||
def null_safe_str(s):
|
||||
return str(s) if s else ''
|
||||
|
||||
image_ref_url = "%s/images/%s" % (utils.generate_glance_url(),
|
||||
instance_ref['image_ref'])
|
||||
|
||||
usage_info = dict(
|
||||
tenant_id=instance_ref['project_id'],
|
||||
user_id=instance_ref['user_id'],
|
||||
instance_id=instance_ref['uuid'],
|
||||
instance_type=instance_ref['instance_type']['name'],
|
||||
instance_type_id=instance_ref['instance_type_id'],
|
||||
memory_mb=instance_ref['memory_mb'],
|
||||
disk_gb=instance_ref['root_gb'] + instance_ref['ephemeral_gb'],
|
||||
display_name=instance_ref['display_name'],
|
||||
created_at=str(instance_ref['created_at']),
|
||||
deleted_at=null_safe_str(instance_ref['deleted_at']),
|
||||
launched_at=null_safe_str(instance_ref['launched_at']),
|
||||
image_ref_url=image_ref_url,
|
||||
state=instance_ref['vm_state'],
|
||||
state_description=null_safe_str(instance_ref['task_state']))
|
||||
|
||||
if network_info is not None:
|
||||
usage_info['fixed_ips'] = network_info.fixed_ips()
|
||||
|
||||
usage_info.update(kw)
|
||||
return usage_info
|
||||
|
@ -29,6 +29,7 @@ from nova.api.ec2 import cloud
|
||||
from nova.api.ec2 import ec2utils
|
||||
from nova.api.ec2 import inst_state
|
||||
from nova.compute import power_state
|
||||
from nova.compute import utils as compute_utils
|
||||
from nova.compute import vm_states
|
||||
from nova import context
|
||||
from nova import db
|
||||
@ -94,7 +95,7 @@ class CloudTestCase(test.TestCase):
|
||||
def dumb(*args, **kwargs):
|
||||
pass
|
||||
|
||||
self.stubs.Set(utils, 'usage_from_instance', dumb)
|
||||
self.stubs.Set(compute_utils, 'usage_from_instance', dumb)
|
||||
# set up our cloud
|
||||
self.cloud = cloud.CloudController()
|
||||
self.flags(compute_scheduler_driver='nova.scheduler.'
|
||||
@ -1559,7 +1560,7 @@ class CloudTestCase(test.TestCase):
|
||||
def dumb(*args, **kwargs):
|
||||
pass
|
||||
|
||||
self.stubs.Set(utils, 'usage_from_instance', dumb)
|
||||
self.stubs.Set(compute_utils, 'usage_from_instance', dumb)
|
||||
# NOTE(comstud): Make 'cast' behave like a 'call' which will
|
||||
# ensure that operations complete
|
||||
self.stubs.Set(rpc, 'cast', rpc.call)
|
||||
|
@ -22,6 +22,7 @@ from nova.api.ec2 import cloud
|
||||
from nova.api.ec2 import ec2utils
|
||||
from nova.api.ec2 import inst_state
|
||||
from nova.compute import power_state
|
||||
from nova.compute import utils as compute_utils
|
||||
from nova.compute import vm_states
|
||||
from nova import context
|
||||
from nova import db
|
||||
@ -46,7 +47,7 @@ class EC2ValidateTestCase(test.TestCase):
|
||||
def dumb(*args, **kwargs):
|
||||
pass
|
||||
|
||||
self.stubs.Set(utils, 'usage_from_instance', dumb)
|
||||
self.stubs.Set(compute_utils, 'usage_from_instance', dumb)
|
||||
# set up our cloud
|
||||
self.cloud = cloud.CloudController()
|
||||
|
||||
|
@ -457,36 +457,6 @@ def last_completed_audit_period(unit=None):
|
||||
return (begin, end)
|
||||
|
||||
|
||||
def usage_from_instance(instance_ref, network_info=None, **kw):
|
||||
def null_safe_str(s):
|
||||
return str(s) if s else ''
|
||||
|
||||
image_ref_url = "%s/images/%s" % (generate_glance_url(),
|
||||
instance_ref['image_ref'])
|
||||
|
||||
usage_info = dict(
|
||||
tenant_id=instance_ref['project_id'],
|
||||
user_id=instance_ref['user_id'],
|
||||
instance_id=instance_ref['uuid'],
|
||||
instance_type=instance_ref['instance_type']['name'],
|
||||
instance_type_id=instance_ref['instance_type_id'],
|
||||
memory_mb=instance_ref['memory_mb'],
|
||||
disk_gb=instance_ref['root_gb'] + instance_ref['ephemeral_gb'],
|
||||
display_name=instance_ref['display_name'],
|
||||
created_at=str(instance_ref['created_at']),
|
||||
deleted_at=null_safe_str(instance_ref['deleted_at']),
|
||||
launched_at=null_safe_str(instance_ref['launched_at']),
|
||||
image_ref_url=image_ref_url,
|
||||
state=instance_ref['vm_state'],
|
||||
state_description=null_safe_str(instance_ref['task_state']))
|
||||
|
||||
if network_info is not None:
|
||||
usage_info['fixed_ips'] = network_info.fixed_ips()
|
||||
|
||||
usage_info.update(kw)
|
||||
return usage_info
|
||||
|
||||
|
||||
def generate_password(length=20, symbolgroups=DEFAULT_PASSWORD_SYMBOLS):
|
||||
"""Generate a random password from the supplied symbol groups.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user