From fb6aba61ef03032c31196bd58c68fa7b7d4c2769 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Fri, 1 Jul 2011 14:26:05 +0000 Subject: completed api changes. still need plugin changes --- nova/virt/driver.py | 4 ++++ nova/virt/fake.py | 4 ++++ nova/virt/hyperv.py | 4 ++++ nova/virt/libvirt/connection.py | 4 ++++ nova/virt/vmwareapi_conn.py | 4 ++++ nova/virt/xenapi/vmops.py | 18 ++++++++++++++++++ nova/virt/xenapi_conn.py | 4 ++++ 7 files changed, 42 insertions(+) (limited to 'nova/virt') diff --git a/nova/virt/driver.py b/nova/virt/driver.py index 1c9797973..3c4a073bf 100644 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -249,3 +249,7 @@ class ComputeDriver(object): def poll_rescued_instances(self, timeout): """Poll for rescued instances""" raise NotImplementedError() + + def set_host_enabled(self, host, enabled): + """Sets the specified host's ability to accept new instances.""" + raise NotImplementedError() diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 5fe9d674f..ea0a59f21 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -514,3 +514,7 @@ class FakeConnection(driver.ComputeDriver): def get_host_stats(self, refresh=False): """Return fake Host Status of ram, disk, network.""" return self.host_status + + def set_host_enabled(self, host, enabled): + """Sets the specified host's ability to accept new instances.""" + pass diff --git a/nova/virt/hyperv.py b/nova/virt/hyperv.py index f6783f3aa..5c1dc772d 100644 --- a/nova/virt/hyperv.py +++ b/nova/virt/hyperv.py @@ -499,3 +499,7 @@ class HyperVConnection(driver.ComputeDriver): def get_host_stats(self, refresh=False): """See xenapi_conn.py implementation.""" pass + + def set_host_enabled(self, host, enabled): + """Sets the specified host's ability to accept new instances.""" + pass diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 0c6eaab84..b80a3daee 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -1591,3 +1591,7 @@ class LibvirtConnection(driver.ComputeDriver): def get_host_stats(self, refresh=False): """See xenapi_conn.py implementation.""" pass + + def set_host_enabled(self, host, enabled): + """Sets the specified host's ability to accept new instances.""" + pass diff --git a/nova/virt/vmwareapi_conn.py b/nova/virt/vmwareapi_conn.py index 3c6345ec8..d80e14931 100644 --- a/nova/virt/vmwareapi_conn.py +++ b/nova/virt/vmwareapi_conn.py @@ -190,6 +190,10 @@ class VMWareESXConnection(driver.ComputeDriver): """This method is supported only by libvirt.""" return + def set_host_enabled(self, host, enabled): + """Sets the specified host's ability to accept new instances.""" + pass + class VMWareAPISession(object): """ diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index b116c8467..44645840c 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -24,6 +24,7 @@ import json import M2Crypto import os import pickle +import random import subprocess import time import uuid @@ -932,6 +933,23 @@ class VMOps(object): # TODO: implement this! return 'http://fakeajaxconsole/fake_url' + def set_host_enabled(self, host, enabled): + """Sets the specified host's ability to accept new instances.""" + return self._call_xenhost("set_enabled", {"enabled": enabled}) + + def _call_xenhost(self, method, arg_dict): + # Create a task ID as something that won't match any instance ID + task_id = random.randint(-80000, -70000) + try: + task = self._session.async_call_plugin("xenhost", method, + args=arg_dict) + ret = self._session.wait_for_task(task, task_id) + except self.XenAPI.Failure as e: + ret = None + LOG.error(_("The call to %(method)s returned an error: %(e)s.") + % locals()) + return ret + def inject_network_info(self, instance, network_info, vm_ref=None): """ Generate the network info and make calls to place it into the diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py index cd4dc1b60..ec8c44c1c 100644 --- a/nova/virt/xenapi_conn.py +++ b/nova/virt/xenapi_conn.py @@ -336,6 +336,10 @@ class XenAPIConnection(driver.ComputeDriver): True, run the update first.""" return self.HostState.get_host_stats(refresh=refresh) + def set_host_enabled(self, host, enabled): + """Sets the specified host's ability to accept new instances.""" + return self._vmops.set_host_enabled(host, enabled) + class XenAPISession(object): """The session to invoke XenAPI SDK calls""" -- cgit From 42dabbc86e3af49215ced275d76d241b4daf8bdc Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Fri, 1 Jul 2011 19:44:10 +0000 Subject: Updated unit tests --- nova/virt/xenapi/vmops.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 44645840c..535a55ebb 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -935,20 +935,44 @@ class VMOps(object): def set_host_enabled(self, host, enabled): """Sets the specified host's ability to accept new instances.""" - return self._call_xenhost("set_enabled", {"enabled": enabled}) + args = {"enabled": json.dumps(enabled)} + json_resp = self._call_xenhost("set_host_enabled", args) + resp = json.loads(json_resp) + return resp["status"] def _call_xenhost(self, method, arg_dict): + """There will be several methods that will need this general + handling for interacting with the xenhost plugin, so this abstracts + out that behavior. + """ # Create a task ID as something that won't match any instance ID task_id = random.randint(-80000, -70000) try: task = self._session.async_call_plugin("xenhost", method, args=arg_dict) + #args={"params": arg_dict}) ret = self._session.wait_for_task(task, task_id) except self.XenAPI.Failure as e: ret = None LOG.error(_("The call to %(method)s returned an error: %(e)s.") % locals()) return ret +# def set_host_enabled(self, host, enabled): +# """Sets the specified host's ability to accept new instances.""" +# return self._call_xenhost("set_host_enabled", {"enabled": enabled}) +# +# def _call_xenhost(self, method, arg_dict): +# # Create a task ID as something that won't match any instance ID +# task_id = random.randint(-80000, -70000) +# try: +# task = self._session.async_call_plugin("xenhost", method, +# args=arg_dict) +# ret = self._session.wait_for_task(task, task_id) +# except self.XenAPI.Failure as e: +# ret = None +# LOG.error(_("The call to %(method)s returned an error: %(e)s.") +# % locals()) +# return ret def inject_network_info(self, instance, network_info, vm_ref=None): """ -- cgit From 723e5076a414b52e716f5a5cac7667c5b09a36d3 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Fri, 1 Jul 2011 20:39:56 +0000 Subject: removed unneeded old commented code --- nova/virt/xenapi/vmops.py | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 535a55ebb..cb96930c1 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -957,22 +957,6 @@ class VMOps(object): LOG.error(_("The call to %(method)s returned an error: %(e)s.") % locals()) return ret -# def set_host_enabled(self, host, enabled): -# """Sets the specified host's ability to accept new instances.""" -# return self._call_xenhost("set_host_enabled", {"enabled": enabled}) -# -# def _call_xenhost(self, method, arg_dict): -# # Create a task ID as something that won't match any instance ID -# task_id = random.randint(-80000, -70000) -# try: -# task = self._session.async_call_plugin("xenhost", method, -# args=arg_dict) -# ret = self._session.wait_for_task(task, task_id) -# except self.XenAPI.Failure as e: -# ret = None -# LOG.error(_("The call to %(method)s returned an error: %(e)s.") -# % locals()) -# return ret def inject_network_info(self, instance, network_info, vm_ref=None): """ -- cgit