From e5bec8b913a1f2fb2e15710bc9401e3384470cce Mon Sep 17 00:00:00 2001 From: Tiago Mello Date: Mon, 27 Aug 2012 14:46:48 -0400 Subject: [PATCH] Implements PowerVM get_available_resource method. Implements get_available_resource method in the PowerVM driver to fix the failure when launching nova-compute. Also, it removes the update_available_resource method from PowerVMDriver which is no longer required. Fixes bug 1040789 Change-Id: Ibc7e9b80e6d9b8ef3c1a844783a890c592517f89 --- nova/virt/powervm/command.py | 6 ++++++ nova/virt/powervm/driver.py | 14 +++----------- nova/virt/powervm/operator.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/nova/virt/powervm/command.py b/nova/virt/powervm/command.py index 8cef5b72862d..3e51c933cd41 100644 --- a/nova/virt/powervm/command.py +++ b/nova/virt/powervm/command.py @@ -59,6 +59,9 @@ class BaseCommand(object): def lshwres(self, args=''): return 'lshwres %s' % args + def hostname(self, args=''): + return 'hostname %s' % args + def vhost_by_instance_id(self, instance_id_hex): pass @@ -88,3 +91,6 @@ class IVMCommand(BaseCommand): def mkvdev(self, args=''): return 'ioscli ' + BaseCommand.mkvdev(self, args=args) + + def hostname(self, args=''): + return 'ioscli ' + BaseCommand.hostname(self, args=args) diff --git a/nova/virt/powervm/driver.py b/nova/virt/powervm/driver.py index 577000828175..0ee52105ab7a 100644 --- a/nova/virt/powervm/driver.py +++ b/nova/virt/powervm/driver.py @@ -169,17 +169,9 @@ class PowerVMDriver(driver.ComputeDriver): """Power on the specified instance""" self._powervm.power_on(instance['name']) - def update_available_resource(self, ctxt, host): - """Updates compute manager resource info on ComputeNode table. - - This method is called when nova-compute launches, and - whenever admin executes "nova-manage service update_resource". - - :param ctxt: security context - :param host: hostname that compute manager is currently running - - """ - pass + def get_available_resource(self): + """Retrieve resource info.""" + return self._powervm.get_available_resource() def host_power_action(self, host, action): """Reboots, shuts down or powers up the host.""" diff --git a/nova/virt/powervm/operator.py b/nova/virt/powervm/operator.py index 9503038f2be1..da90af6505ac 100644 --- a/nova/virt/powervm/operator.py +++ b/nova/virt/powervm/operator.py @@ -106,6 +106,32 @@ class PowerVMOperator(object): if re.search(r'^instance-[0-9]{8}$', instance)] return instances + def get_available_resource(self): + """Retrieve resource info. + + :returns: dictionary containing resource info + """ + data = self.get_host_stats() + # Memory data is in MB already. + memory_mb_used = data['host_memory_total'] - data['host_memory_free'] + + # Convert to GB + local_gb = data['disk_total'] / 1024 + local_gb_used = data['disk_used'] / 1024 + + dic = {'vcpus': data['vcpus'], + 'memory_mb': data['host_memory_total'], + 'local_gb': local_gb, + 'vcpus_used': data['vcpus_used'], + 'memory_mb_used': memory_mb_used, + 'local_gb_used': local_gb_used, + 'hypervisor_type': data['hypervisor_type'], + 'hypervisor_version': data['hypervisor_version'], + 'hypervisor_hostname': self._operator.get_hostname(), + 'cpu_info': ','.join(data['cpu_info']), + 'disk_available_least': data['disk_total']} + return dic + def get_host_stats(self, refresh=False): """Return currently known host stats""" if refresh: @@ -401,6 +427,14 @@ class BaseOperator(object): return None + def get_hostname(self): + """Returns the managed system hostname. + + :returns: string -- hostname + """ + output = self.run_command(self.command.hostname()) + return output[0] + def remove_disk(self, disk_name): """Removes a disk.