From 3e8ccb16148963c69b88afd044cbf83a68646de0 Mon Sep 17 00:00:00 2001 From: Hans Lindgren Date: Wed, 1 May 2013 23:28:18 +0200 Subject: Deprecate show_host_resources() in scheduler manager This method does not at all belong in the scheduler. Its only use is from being remotely called by nova-manage to whom it returns data fetched from the db. I think nova-manage is better of fetching this data on its own instead of making this extra round trip to the scheduler. Change-Id: I435300cdd15bdd041cbe5718ae064b98cec4cceb --- nova/cmd/manage.py | 60 ++++++++++++++++++++++++++++++++++--- nova/scheduler/manager.py | 4 +-- nova/scheduler/rpcapi.py | 3 -- nova/tests/scheduler/test_rpcapi.py | 4 --- 4 files changed, 57 insertions(+), 14 deletions(-) diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index ee3c123a9..41b97f26d 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -78,7 +78,6 @@ from nova.openstack.common import log as logging from nova.openstack.common import rpc from nova.openstack.common import timeutils from nova import quota -from nova.scheduler import rpcapi as scheduler_rpcapi from nova import servicegroup from nova import version @@ -700,6 +699,60 @@ class ServiceCommands(object): return(2) print _("Service %(service)s on host %(host)s disabled.") % locals() + def _show_host_resources(self, context, host): + """Shows the physical/usage resource given by hosts. + + :param context: security context + :param host: hostname + :returns: + example format is below:: + + {'resource':D, 'usage':{proj_id1:D, proj_id2:D}} + D: {'vcpus': 3, 'memory_mb': 2048, 'local_gb': 2048, + 'vcpus_used': 12, 'memory_mb_used': 10240, + 'local_gb_used': 64} + + """ + # Getting compute node info and related instances info + service_ref = db.service_get_by_compute_host(context, host) + instance_refs = db.instance_get_all_by_host(context, + service_ref['host']) + + # Getting total available/used resource + compute_ref = service_ref['compute_node'][0] + resource = {'vcpus': compute_ref['vcpus'], + 'memory_mb': compute_ref['memory_mb'], + 'local_gb': compute_ref['local_gb'], + 'vcpus_used': compute_ref['vcpus_used'], + 'memory_mb_used': compute_ref['memory_mb_used'], + 'local_gb_used': compute_ref['local_gb_used']} + usage = dict() + if not instance_refs: + return {'resource': resource, 'usage': usage} + + # Getting usage resource per project + project_ids = [i['project_id'] for i in instance_refs] + project_ids = list(set(project_ids)) + for project_id in project_ids: + vcpus = [i['vcpus'] for i in instance_refs + if i['project_id'] == project_id] + + mem = [i['memory_mb'] for i in instance_refs + if i['project_id'] == project_id] + + root = [i['root_gb'] for i in instance_refs + if i['project_id'] == project_id] + + ephemeral = [i['ephemeral_gb'] for i in instance_refs + if i['project_id'] == project_id] + + usage[project_id] = {'vcpus': sum(vcpus), + 'memory_mb': sum(mem), + 'root_gb': sum(root), + 'ephemeral_gb': sum(ephemeral)} + + return {'resource': resource, 'usage': usage} + @args('--host', metavar='', help='Host') def describe_resource(self, host): """Describes cpu/memory/hdd info for host. @@ -707,9 +760,8 @@ class ServiceCommands(object): :param host: hostname. """ - rpcapi = scheduler_rpcapi.SchedulerAPI() - result = rpcapi.show_host_resources(context.get_admin_context(), - host=host) + result = self._show_host_resources(context.get_admin_context(), + host=host) if not isinstance(result, dict): print _('An unexpected error has occurred.') diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index 65b171eba..ca7cd956f 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -241,9 +241,7 @@ class SchedulerManager(manager.Manager): notifier.notify(context, notifier.publisher_id("scheduler"), 'scheduler.' + method, notifier.ERROR, payload) - # NOTE (masumotok) : This method should be moved to nova.api.ec2.admin. - # Based on bexar design summit discussion, - # just put this here for bexar release. + # NOTE(hanlind): This method can be removed in v3.0 of the RPC API. def show_host_resources(self, context, host): """Shows the physical/usage resource given by hosts. diff --git a/nova/scheduler/rpcapi.py b/nova/scheduler/rpcapi.py index ac2244de4..2cfd5688f 100644 --- a/nova/scheduler/rpcapi.py +++ b/nova/scheduler/rpcapi.py @@ -96,9 +96,6 @@ class SchedulerAPI(nova.openstack.common.rpc.proxy.RpcProxy): filter_properties=filter_properties, reservations=reservations_p)) - def show_host_resources(self, ctxt, host): - return self.call(ctxt, self.make_msg('show_host_resources', host=host)) - def live_migration(self, ctxt, block_migration, disk_over_commit, instance, dest): # NOTE(comstud): Call vs cast so we can get exceptions back, otherwise diff --git a/nova/tests/scheduler/test_rpcapi.py b/nova/tests/scheduler/test_rpcapi.py index 9a7615c86..44e6a91b8 100644 --- a/nova/tests/scheduler/test_rpcapi.py +++ b/nova/tests/scheduler/test_rpcapi.py @@ -69,10 +69,6 @@ class SchedulerRpcAPITestCase(test.TestCase): request_spec='fake_request_spec', filter_properties='fake_props', reservations=list('fake_res')) - def test_show_host_resources(self): - self._test_scheduler_api('show_host_resources', rpc_method='call', - host='fake_host') - def test_live_migration(self): self._test_scheduler_api('live_migration', rpc_method='call', block_migration='fake_block_migration', -- cgit