Making usage_from_instance
private.
This reduces the surface area of usage notifications down to just `compute_utils.notify_about_instance_usage`, making future refactoring easier. Change-Id: If70aff191c0135c1883c39c9783f5c8433953a4e
This commit is contained in:
parent
8829a3bf7e
commit
cee3e5a207
@ -604,13 +604,15 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
launched_at=utils.utcnow())
|
||||
|
||||
def _notify_about_instance_usage(self, instance, event_suffix,
|
||||
usage_info=None, network_info=None):
|
||||
if not usage_info:
|
||||
usage_info = compute_utils.usage_from_instance(instance,
|
||||
network_info=network_info)
|
||||
notifier.notify('compute.%s' % self.host,
|
||||
'compute.instance.%s' % event_suffix,
|
||||
notifier.INFO, usage_info)
|
||||
network_info=None,
|
||||
extra_usage_info=None):
|
||||
# NOTE(sirp): The only thing this wrapper function does extra is handle
|
||||
# the passing in of `self.host`. Ordinarily this will just be
|
||||
# `FLAGS.host`, but `Manager`'s gets a chance to override this in its
|
||||
# `__init__`.
|
||||
compute_utils.notify_about_instance_usage(
|
||||
instance, event_suffix, network_info=network_info,
|
||||
extra_usage_info=extra_usage_info, host=self.host)
|
||||
|
||||
def _deallocate_network(self, context, instance):
|
||||
if not FLAGS.stub_network:
|
||||
@ -1299,11 +1301,11 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
'migration_id': migration_ref['id'],
|
||||
'image': image}})
|
||||
|
||||
usage_info = compute_utils.usage_from_instance(instance_ref,
|
||||
new_instance_type=new_instance_type['name'],
|
||||
new_instance_type_id=new_instance_type['id'])
|
||||
extra_usage_info = dict(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",
|
||||
usage_info=usage_info)
|
||||
extra_usage_info=extra_usage_info)
|
||||
|
||||
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
|
||||
@checks_instance_lock
|
||||
@ -1548,9 +1550,7 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
vm_state=vm_states.SUSPENDED,
|
||||
task_state=None)
|
||||
|
||||
usage_info = compute_utils.usage_from_instance(instance_ref)
|
||||
notifier.notify('compute.%s' % self.host, 'compute.instance.suspend',
|
||||
notifier.INFO, usage_info)
|
||||
self._notify_about_instance_usage(instance_ref, 'suspend')
|
||||
|
||||
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
|
||||
@checks_instance_lock
|
||||
@ -1570,9 +1570,7 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
vm_state=vm_states.ACTIVE,
|
||||
task_state=None)
|
||||
|
||||
usage_info = compute_utils.usage_from_instance(instance_ref)
|
||||
notifier.notify('compute.%s' % self.host, 'compute.instance.resume',
|
||||
notifier.INFO, usage_info)
|
||||
self._notify_about_instance_usage(instance_ref, 'resume')
|
||||
|
||||
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
|
||||
@wrap_instance_fault
|
||||
|
@ -67,14 +67,13 @@ 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 = usage_from_instance(instance_ref,
|
||||
audit_period_beginning=str(audit_start),
|
||||
audit_period_ending=str(audit_end),
|
||||
bandwidth=bw)
|
||||
notifier_api.notify('compute.%s' % FLAGS.host,
|
||||
'compute.instance.exists',
|
||||
notifier_api.INFO,
|
||||
usage_info)
|
||||
|
||||
extra_usage_info = dict(audit_period_beginning=str(audit_start),
|
||||
audit_period_ending=str(audit_end),
|
||||
bandwidth=bw)
|
||||
|
||||
notify_about_instance_usage(
|
||||
instance_ref, 'exists', extra_usage_info=extra_usage_info)
|
||||
|
||||
|
||||
def legacy_network_info(network_model):
|
||||
@ -192,7 +191,7 @@ def legacy_network_info(network_model):
|
||||
return network_info
|
||||
|
||||
|
||||
def usage_from_instance(instance_ref, network_info=None, **kw):
|
||||
def _usage_from_instance(instance_ref, network_info=None, **kw):
|
||||
def null_safe_str(s):
|
||||
return str(s) if s else ''
|
||||
|
||||
@ -220,3 +219,19 @@ def usage_from_instance(instance_ref, network_info=None, **kw):
|
||||
|
||||
usage_info.update(kw)
|
||||
return usage_info
|
||||
|
||||
|
||||
def notify_about_instance_usage(instance, event_suffix, network_info=None,
|
||||
extra_usage_info=None, host=None):
|
||||
if not host:
|
||||
host = FLAGS.host
|
||||
|
||||
if not extra_usage_info:
|
||||
extra_usage_info = {}
|
||||
|
||||
usage_info = _usage_from_instance(
|
||||
instance, network_info=network_info, **extra_usage_info)
|
||||
|
||||
notifier_api.notify('compute.%s' % host,
|
||||
'compute.instance.%s' % event_suffix,
|
||||
notifier_api.INFO, usage_info)
|
||||
|
@ -95,7 +95,7 @@ class CloudTestCase(test.TestCase):
|
||||
def dumb(*args, **kwargs):
|
||||
pass
|
||||
|
||||
self.stubs.Set(compute_utils, 'usage_from_instance', dumb)
|
||||
self.stubs.Set(compute_utils, 'notify_about_instance_usage', dumb)
|
||||
# set up our cloud
|
||||
self.cloud = cloud.CloudController()
|
||||
self.flags(compute_scheduler_driver='nova.scheduler.'
|
||||
@ -1560,7 +1560,7 @@ class CloudTestCase(test.TestCase):
|
||||
def dumb(*args, **kwargs):
|
||||
pass
|
||||
|
||||
self.stubs.Set(compute_utils, 'usage_from_instance', dumb)
|
||||
self.stubs.Set(compute_utils, 'notify_about_instance_usage', dumb)
|
||||
# NOTE(comstud): Make 'cast' behave like a 'call' which will
|
||||
# ensure that operations complete
|
||||
self.stubs.Set(rpc, 'cast', rpc.call)
|
||||
|
@ -47,7 +47,7 @@ class EC2ValidateTestCase(test.TestCase):
|
||||
def dumb(*args, **kwargs):
|
||||
pass
|
||||
|
||||
self.stubs.Set(compute_utils, 'usage_from_instance', dumb)
|
||||
self.stubs.Set(compute_utils, 'notify_about_instance_usage', dumb)
|
||||
# set up our cloud
|
||||
self.cloud = cloud.CloudController()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user