From 47bc72e5ec27bec349dcfc9468af6325f0a51019 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Wed, 12 Jan 2011 12:10:26 -0600 Subject: Start to add rescue/unrescue support --- nova/api/openstack/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index f96e2af91..a9b01548a 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -95,6 +95,8 @@ class APIRouter(wsgi.Router): server_members["actions"] = "GET" server_members['suspend'] = 'POST' server_members['resume'] = 'POST' + server_members['rescue'] = 'POST' + server_members['unrescue'] = 'POST' mapper.resource("server", "servers", controller=servers.Controller(), collection={'detail': 'GET'}, -- cgit From 7f2a4fdf5e43620081e163fc46f2ca4fdefd18f3 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Wed, 12 Jan 2011 15:07:51 -0600 Subject: Make rescue/unrescue available to API --- nova/api/openstack/servers.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 29af82533..3a6c61a3a 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -283,6 +283,28 @@ class Controller(wsgi.Controller): return faults.Fault(exc.HTTPUnprocessableEntity()) return exc.HTTPAccepted() + def rescue(self, req, id): + """Permit users to rescue the server.""" + context = req.environ["nova.context"] + try: + self.compute_api.rescue(context, id) + except: + readable = traceback.format_exc() + LOG.exception(_("compute.api::rescue %s"), readable) + return faults.Fault(exc.HTTPUnprocessableEntity()) + return exc.HTTPAccepted() + + def unrescue(self, req, id): + """Permit users to unrescue the server.""" + context = req.environ["nova.context"] + try: + self.compute_api.unrescue(context, id) + except: + readable = traceback.format_exc() + LOG.exception(_("compute.api::unrescue %s"), readable) + return faults.Fault(exc.HTTPUnprocessableEntity()) + return exc.HTTPAccepted() + def get_ajax_console(self, req, id): """ Returns a url to an instance's ajaxterm console. """ try: -- cgit From 752bed3311f09e7a43e642231e1638b4252f74a6 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 13 Jan 2011 10:44:29 -0600 Subject: Stubbed out XenServer rescue/unrescue --- nova/virt/xenapi/vmops.py | 8 ++++++++ nova/virt/xenapi_conn.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 7e3585991..8681608e1 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -264,6 +264,14 @@ class VMOps(object): task = self._session.call_xenapi('Async.VM.resume', vm, False, True) self._wait_with_callback(task, callback) + def rescue(self, instance, callback): + """Rescue the specified instance""" + return True + + def unrescue(self, instance, callback): + """Unrescue the specified instance""" + return True + def get_info(self, instance_id): """Return data about VM instance""" vm = VMHelper.lookup(self._session, instance_id) diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py index 45d0738a5..c24ec972b 100644 --- a/nova/virt/xenapi_conn.py +++ b/nova/virt/xenapi_conn.py @@ -169,6 +169,14 @@ class XenAPIConnection(object): """resume the specified instance""" self._vmops.resume(instance, callback) + def rescue(self, instance, callback): + """Rescue the specified instance""" + self._vmops.rescue(instance, callback) + + def unrescue(self, instance, callback): + """Unrescue the specified instance""" + self._vmops.unrescue(instance, callback) + def get_info(self, instance_id): """Return data about VM instance""" return self._vmops.get_info(instance_id) -- cgit From 702d1bd5e58c15e5b7f43e9d56bd591d728ecb71 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 13 Jan 2011 10:47:23 -0600 Subject: Make driver calls compatible --- nova/virt/libvirt_conn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index c03046703..797ac1b60 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -328,7 +328,7 @@ class LibvirtConnection(object): raise exception.APIError("resume not supported for libvirt") @exception.wrap_exception - def rescue(self, instance): + def rescue(self, instance, callback=None): self.destroy(instance, False) xml = self.to_xml(instance, rescue=True) @@ -358,7 +358,7 @@ class LibvirtConnection(object): return timer.start(interval=0.5, now=True) @exception.wrap_exception - def unrescue(self, instance): + def unrescue(self, instance, callback=None): # NOTE(vish): Because reboot destroys and recreates an instance using # the normal xml file, we can just call reboot here self.reboot(instance) -- cgit From ff6606938749ce5f1a8e430b24d279cde7556c1b Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 13 Jan 2011 11:24:11 -0600 Subject: Make libvirt and XenAPI play nice together --- nova/compute/manager.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 6b2fc4adb..f1fdd64e6 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -321,7 +321,11 @@ class ComputeManager(manager.Manager): power_state.NOSTATE, 'rescuing') self.network_manager.setup_compute_network(context, instance_id) - self.driver.rescue(instance_ref) + self.driver.rescue(instance_ref, + lambda result: self._update_state_callback(self, + context, + instance_id, + result)) self._update_state(context, instance_id) @exception.wrap_exception @@ -335,7 +339,11 @@ class ComputeManager(manager.Manager): instance_id, power_state.NOSTATE, 'unrescuing') - self.driver.unrescue(instance_ref) + self.driver.unrescue(instance_ref, + lambda result: self._update_state_callback(self, + context, + instance_id, + result)) self._update_state(context, instance_id) @staticmethod -- cgit From 912e4343cf2622fa42aa4e1c5eac392ce1be96e0 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Fri, 14 Jan 2011 11:49:59 -0600 Subject: Create and use a generic handler for RPC calls to compute. --- nova/compute/api.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/nova/compute/api.py b/nova/compute/api.py index 90273da36..40b9e33e8 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -331,7 +331,7 @@ class API(base.Base): return self.db.instance_get_all(context) def _cast_compute_message(self, method, context, instance_id, host=None): - """Generic handler for RPC calls to compute.""" + """Generic handler for RPC casts to compute.""" if not host: instance = self.get(context, instance_id) host = instance['host'] @@ -339,6 +339,15 @@ class API(base.Base): kwargs = {'method': method, 'args': {'instance_id': instance_id}} rpc.cast(context, queue, kwargs) + def _call_compute_message(self, method, context, instance_id, host=None): + """Generic handler for RPC calls to compute.""" + if not host: + instance = self.get(context, instance_id) + host = instance["host"] + queue = self.db.queue_get_for(context, FLAGS.compute_topic, host) + kwargs = {"method": method, "args": {"instance_id": instance_id}} + return rpc.call(context, queue, kwargs) + def snapshot(self, context, instance_id, name): """Snapshot the given instance.""" self._cast_compute_message('snapshot_instance', context, instance_id) @@ -357,7 +366,10 @@ class API(base.Base): def get_diagnostics(self, context, instance_id): """Retrieve diagnostics for the given instance.""" - self._cast_compute_message('get_diagnostics', context, instance_id) + return self._call_compute_message( + "get_diagnostics", + context, + instance_id) def get_actions(self, context, instance_id): """Retrieve actions for the given instance.""" -- cgit From 3300e692b61dc53ac8ae3bfdbac5bb1019983feb Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Mon, 17 Jan 2011 12:21:08 -0600 Subject: Add Start/Shutdown support to XenAPI --- nova/virt/xenapi/vmops.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 96be17d8c..0e6018973 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -207,6 +207,25 @@ class VMOps(object): logging.debug(_("Finished snapshot and upload for VM %s"), instance) + def start(self, instance): + """Start a VM instance""" + vm = self._get_vm_opaque_ref(instance) + task = self._session.call_xenapi("Async.VM.start", vm, False, False) + self._session.wait_for_task(instance.id, task) + + def shutdown(self, instance, hard=True): + """Shutdown a VM instance""" + vm = self._get_vm_opaque_ref(instance) + if hard: + task = self._session.call_xenapi("Async.VM.hard_shutdown", vm) + else: + # TODO(jk0): clean_shutdown is only supported if XenTools is + # installed and running. What we want to do eventually is try + # this first, and only issue the hard_shutdown if clean_shutdown + # were to fail. + task = self._session.call_xenapi("Async.VM.clean_shutdown", vm) + self._session.wait_for_task(instance.id, task) + def reboot(self, instance): """Reboot VM instance""" vm = self._get_vm_opaque_ref(instance) @@ -320,11 +339,11 @@ class VMOps(object): def rescue(self, instance, callback): """Rescue the specified instance""" - return True + self.shutdown(instance) def unrescue(self, instance, callback): """Unrescue the specified instance""" - return True + self.start(instance) def get_info(self, instance): """Return data about VM instance""" -- cgit From 8c79b0c1995bd9d061c1c379c0034f49cbdb8d05 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Mon, 17 Jan 2011 13:31:05 -0600 Subject: Better shutdown handling --- nova/virt/xenapi/vmops.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 041e2c5bb..f59c1af44 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -213,18 +213,16 @@ class VMOps(object): task = self._session.call_xenapi("Async.VM.start", vm, False, False) self._session.wait_for_task(instance.id, task) - def shutdown(self, instance, hard=True): + def shutdown(self, instance): """Shutdown a VM instance""" vm = self._get_vm_opaque_ref(instance) - if hard: - task = self._session.call_xenapi("Async.VM.hard_shutdown", vm) - else: - # TODO(jk0): clean_shutdown is only supported if XenTools is - # installed and running. What we want to do eventually is try - # this first, and only issue the hard_shutdown if clean_shutdown - # were to fail. + + try: task = self._session.call_xenapi("Async.VM.clean_shutdown", vm) - self._session.wait_for_task(instance.id, task) + self._session.wait_for_task(instance.id, task) + except self.XenAPI.Failure: + task = self._session.call_xenapi("Async.VM.hard_shutdown", vm) + self._session.wait_for_task(instance.id, task) def reboot(self, instance): """Reboot VM instance""" -- cgit From ecc2afda9fed4e9e69edcc470baf254fac448ce7 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Tue, 18 Jan 2011 15:49:42 -0600 Subject: Plug VBD to existing instance and minor cleanup --- nova/tests/xenapi/stubs.py | 2 +- nova/virt/xenapi/fake.py | 2 +- nova/virt/xenapi/vm_utils.py | 12 +++++------- nova/virt/xenapi/vmops.py | 45 +++++++++++++++++++++++++++++++++---------- nova/virt/xenapi/volumeops.py | 2 +- nova/virt/xenapi_conn.py | 15 +++++++++------ 6 files changed, 52 insertions(+), 26 deletions(-) diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 292bd9ba9..313668826 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -37,7 +37,7 @@ def stubout_instance_snapshot(stubs): return self.rv done = FakeEvent() - self._poll_task(id, task, done) + self._poll_task(task, id, done) rv = done.wait() return rv diff --git a/nova/virt/xenapi/fake.py b/nova/virt/xenapi/fake.py index 96d8f5fc8..92ccfd975 100644 --- a/nova/virt/xenapi/fake.py +++ b/nova/virt/xenapi/fake.py @@ -335,7 +335,7 @@ class SessionBase(object): field in _db_content[cls][ref]): return _db_content[cls][ref][field] - LOG.debuug(_('Raising NotImplemented')) + LOG.debug(_('Raising NotImplemented')) raise NotImplementedError( _('xenapi.fake does not have an implementation for %s or it has ' 'been called with the wrong number of arguments') % name) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index eb0393d2a..d5c6a85b4 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -179,9 +179,7 @@ class VMHelper(HelperBase): """Destroy VBD from host database""" try: task = session.call_xenapi('Async.VBD.destroy', vbd_ref) - #FIXME(armando): find a solution to missing instance_id - #with Josh Kearney - session.wait_for_task(0, task) + session.wait_for_task(task) except cls.XenAPI.Failure, exc: LOG.exception(exc) raise StorageError(_('Unable to destroy VBD %s') % vbd_ref) @@ -222,7 +220,7 @@ class VMHelper(HelperBase): original_parent_uuid = get_vhd_parent_uuid(session, vm_vdi_ref) task = session.call_xenapi('Async.VM.snapshot', vm_ref, label) - template_vm_ref = session.wait_for_task(instance_id, task) + template_vm_ref = session.wait_for_task(task, instance_id) template_vdi_rec = get_vdi_for_vm_safely(session, template_vm_ref)[1] template_vdi_uuid = template_vdi_rec["uuid"] @@ -250,7 +248,7 @@ class VMHelper(HelperBase): kwargs = {'params': pickle.dumps(params)} task = session.async_call_plugin('glance', 'put_vdis', kwargs) - session.wait_for_task(instance_id, task) + session.wait_for_task(task, instance_id) @classmethod def fetch_image(cls, session, instance_id, image, user, project, type): @@ -272,7 +270,7 @@ class VMHelper(HelperBase): if type == ImageType.DISK_RAW: args['raw'] = 'true' task = session.async_call_plugin('objectstore', fn, args) - uuid = session.wait_for_task(instance_id, task) + uuid = session.wait_for_task(task, instance_id) return uuid @classmethod @@ -409,7 +407,7 @@ def get_vhd_parent_uuid(session, vdi_ref): def scan_sr(session, instance_id, sr_ref): LOG.debug(_("Re-scanning SR %s"), sr_ref) task = session.call_xenapi('Async.SR.scan', sr_ref) - session.wait_for_task(instance_id, task) + session.wait_for_task(task, instance_id) def wait_for_vhd_coalesce(session, instance_id, sr_ref, vdi_ref, diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index f59c1af44..0de7c8d42 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -211,24 +211,23 @@ class VMOps(object): """Start a VM instance""" vm = self._get_vm_opaque_ref(instance) task = self._session.call_xenapi("Async.VM.start", vm, False, False) - self._session.wait_for_task(instance.id, task) + self._session.wait_for_task(task, instance.id) def shutdown(self, instance): """Shutdown a VM instance""" vm = self._get_vm_opaque_ref(instance) - try: task = self._session.call_xenapi("Async.VM.clean_shutdown", vm) - self._session.wait_for_task(instance.id, task) + self._session.wait_for_task(task, instance.id) except self.XenAPI.Failure: task = self._session.call_xenapi("Async.VM.hard_shutdown", vm) - self._session.wait_for_task(instance.id, task) + self._session.wait_for_task(task, instance.id) def reboot(self, instance): """Reboot VM instance""" vm = self._get_vm_opaque_ref(instance) task = self._session.call_xenapi('Async.VM.clean_reboot', vm) - self._session.wait_for_task(instance.id, task) + self._session.wait_for_task(task, instance.id) def set_admin_password(self, instance, new_pass): """Set the root/admin password on the VM instance. This is done via @@ -284,7 +283,7 @@ class VMOps(object): if shutdown: try: task = self._session.call_xenapi('Async.VM.hard_shutdown', vm) - self._session.wait_for_task(instance.id, task) + self._session.wait_for_task(task, instance.id) except self.XenAPI.Failure, exc: LOG.exception(exc) @@ -293,20 +292,20 @@ class VMOps(object): for vdi in vdis: try: task = self._session.call_xenapi('Async.VDI.destroy', vdi) - self._session.wait_for_task(instance.id, task) + self._session.wait_for_task(task, instance.id) except self.XenAPI.Failure, exc: LOG.exception(exc) # VM Destroy try: task = self._session.call_xenapi('Async.VM.destroy', vm) - self._session.wait_for_task(instance.id, task) + self._session.wait_for_task(task, instance.id) except self.XenAPI.Failure, exc: LOG.exception(exc) def _wait_with_callback(self, instance_id, task, callback): ret = None try: - ret = self._session.wait_for_task(instance_id, task) + ret = self._session.wait_for_task(task, instance_id) except self.XenAPI.Failure, exc: LOG.exception(exc) callback(ret) @@ -337,10 +336,36 @@ class VMOps(object): def rescue(self, instance, callback): """Rescue the specified instance""" + vm = self._get_vm_opaque_ref(instance) + target_vm = VMHelper.lookup(self._session, "instance-00000001") + self.shutdown(instance) + vbd = self._session.get_xenapi().VM.get_VBDs(vm)[0] + vdi_ref = self._session.get_xenapi().VBD.get_record(vbd)["VDI"] + vbd_ref = VMHelper.create_vbd( + self._session, + target_vm, + vdi_ref, + 1, + False) + + # Plug the VBD into the target instance + self._session.call_xenapi("Async.VBD.plug", vbd_ref) + def unrescue(self, instance, callback): """Unrescue the specified instance""" + vm = self._get_vm_opaque_ref(instance) + target_vm = VMHelper.lookup(self._session, "instance-00000001") + + vbds = self._session.get_xenapi().VM.get_VBDs(target_vm) + + for vbd_ref in vbds: + vbd = self._session.get_xenapi().VBD.get_record(vbd_ref) + if vbd["userdevice"] == str(1): + VMHelper.unplug_vbd(self._session, vbd_ref) + VMHelper.destroy_vbd(self._session, vbd_ref) + self.start(instance) def get_info(self, instance): @@ -425,7 +450,7 @@ class VMOps(object): args.update(addl_args) try: task = self._session.async_call_plugin(plugin, method, args) - ret = self._session.wait_for_task(instance_id, task) + ret = self._session.wait_for_task(task, instance_id) except self.XenAPI.Failure, e: ret = None err_trace = e.details[-1] diff --git a/nova/virt/xenapi/volumeops.py b/nova/virt/xenapi/volumeops.py index 189f968c6..0c5f36f6b 100644 --- a/nova/virt/xenapi/volumeops.py +++ b/nova/virt/xenapi/volumeops.py @@ -85,7 +85,7 @@ class VolumeOps(object): try: task = self._session.call_xenapi('Async.VBD.plug', vbd_ref) - self._session.wait_for_task(vol_rec['deviceNumber'], task) + self._session.wait_for_task(task, vol_rec['deviceNumber']) except self.XenAPI.Failure, exc: LOG.exception(exc) VolumeHelper.destroy_iscsi_storage(self._session, diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py index e9793e6a7..07bc0fd84 100644 --- a/nova/virt/xenapi_conn.py +++ b/nova/virt/xenapi_conn.py @@ -290,7 +290,7 @@ class XenAPISession(object): self._session.xenapi.Async.host.call_plugin, self.get_xenapi_host(), plugin, fn, args) - def wait_for_task(self, id, task): + def wait_for_task(self, task, id=None): """Return the result of the given task. The task is polled until it completes. Not re-entrant.""" done = event.Event() @@ -317,10 +317,11 @@ class XenAPISession(object): try: name = self._session.xenapi.task.get_name_label(task) status = self._session.xenapi.task.get_status(task) - action = dict( - instance_id=int(id), - action=name[0:255], # Ensure action is never > 255 - error=None) + if id: + action = dict( + instance_id=int(id), + action=name[0:255], # Ensure action is never > 255 + error=None) if status == "pending": return elif status == "success": @@ -339,7 +340,9 @@ class XenAPISession(object): status, error_info)) done.send_exception(self.XenAPI.Failure(error_info)) - db.instance_action_create(context.get_admin_context(), action) + + if id: + db.instance_action_create(context.get_admin_context(), action) except self.XenAPI.Failure, exc: LOG.warn(exc) done.send_exception(*sys.exc_info()) -- cgit From 2b2f08dc1dfe1b55433c9122d7d42a480cdb5e67 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Tue, 18 Jan 2011 17:57:11 -0600 Subject: Fixed unit tests --- nova/tests/xenapi/stubs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index c1ba25e10..13603717c 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -27,7 +27,7 @@ def stubout_instance_snapshot(stubs): def fake_fetch_image(cls, session, instance_id, image, user, project, type): # Stubout wait_for_task - def fake_wait_for_task(self, id, task): + def fake_wait_for_task(self, task, id=None): class FakeEvent: def send(self, value): @@ -37,7 +37,7 @@ def stubout_instance_snapshot(stubs): return self.rv done = FakeEvent() - self._poll_task(task, id, done) + self._poll_task(id, task, done) rv = done.wait() return rv -- cgit From bb727b7032104d3d3966108d846dd3e5b8a1a37d Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Tue, 18 Jan 2011 17:59:26 -0600 Subject: Fix merge conflict --- nova/virt/xenapi/vm_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 9600584b4..5f5ac254d 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -329,7 +329,7 @@ class VMHelper(HelperBase): #let the plugin copy the correct number of bytes args['image-size'] = str(vdi_size) task = session.async_call_plugin('glance', fn, args) - filename = session.wait_for_task(instance_id, task) + filename = session.wait_for_task(task, instance_id) #remove the VDI as it is not needed anymore session.get_xenapi().VDI.destroy(vdi) LOG.debug(_("Kernel/Ramdisk VDI %s destroyed"), vdi) -- cgit From 4b77a532fd641947c9259327cef9104f689f1127 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Tue, 18 Jan 2011 18:09:58 -0600 Subject: Fixed unit tests --- nova/tests/xenapi/stubs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 13603717c..66d232a7f 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -27,7 +27,7 @@ def stubout_instance_snapshot(stubs): def fake_fetch_image(cls, session, instance_id, image, user, project, type): # Stubout wait_for_task - def fake_wait_for_task(self, task, id=None): + def fake_wait_for_task(self, task, id): class FakeEvent: def send(self, value): -- cgit From dd70c9f3909c800d72d73d507e9da05a6ed932de Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Wed, 19 Jan 2011 11:20:16 -0600 Subject: Fixed unit tests --- nova/virt/xenapi/vm_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 5f5ac254d..7484472d7 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -371,7 +371,7 @@ class VMHelper(HelperBase): args = {} args['vdi-ref'] = vdi_ref task = session.async_call_plugin('objectstore', fn, args) - pv_str = session.wait_for_task(instance_id, task) + pv_str = session.wait_for_task(task, instance_id) pv = None if pv_str.lower() == 'true': pv = True -- cgit From 671f27322156615643ce9194a26bec66819c0c78 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Wed, 26 Jan 2011 10:34:57 -0600 Subject: Cleaned up _start() and _shutdown() --- nova/virt/xenapi/vmops.py | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index e348aee95..e4aff2313 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -208,22 +208,6 @@ class VMOps(object): logging.debug(_("Finished snapshot and upload for VM %s"), instance) - def start(self, instance): - """Start a VM instance""" - vm = self._get_vm_opaque_ref(instance) - task = self._session.call_xenapi("Async.VM.start", vm, False, False) - self._session.wait_for_task(task, instance.id) - - def shutdown(self, instance): - """Shutdown a VM instance""" - vm = self._get_vm_opaque_ref(instance) - try: - task = self._session.call_xenapi("Async.VM.clean_shutdown", vm) - self._session.wait_for_task(task, instance.id) - except self.XenAPI.Failure: - task = self._session.call_xenapi("Async.VM.hard_shutdown", vm) - self._session.wait_for_task(task, instance.id) - def reboot(self, instance): """Reboot VM instance""" vm = self._get_vm_opaque_ref(instance) @@ -268,8 +252,13 @@ class VMOps(object): raise RuntimeError(resp_dict['message']) return resp_dict['message'] + def _start(self, instance, vm): + """Start an instance""" + task = self._session.call_xenapi("Async.VM.start", vm, False, False) + self._session.wait_for_task(task, instance.id) + def _shutdown(self, instance, vm): - """Shutdown an instance """ + """Shutdown an instance""" state = self.get_info(instance['name'])['state'] if state == power_state.SHUTDOWN: LOG.warn(_("VM %(vm)s already halted, skipping shutdown...") % @@ -277,8 +266,12 @@ class VMOps(object): return try: - task = self._session.call_xenapi('Async.VM.hard_shutdown', vm) - self._session.wait_for_task(task, instance.id) + try: + task = self._session.call_xenapi("Async.VM.clean_shutdown", vm) + self._session.wait_for_task(task, instance.id) + except self.XenAPI.Failure: + task = self._session.call_xenapi("Async.VM.hard_shutdown", vm) + self._session.wait_for_task(task, instance.id) except self.XenAPI.Failure, exc: LOG.exception(exc) @@ -368,9 +361,9 @@ class VMOps(object): def rescue(self, instance, callback): """Rescue the specified instance""" vm = self._get_vm_opaque_ref(instance) - target_vm = VMHelper.lookup(self._session, "instance-00000001") + target_vm = VMHelper.lookup(self._session, "instance-00000012") - self.shutdown(instance) + self._shutdown(instance, vm) vbd = self._session.get_xenapi().VM.get_VBDs(vm)[0] vdi_ref = self._session.get_xenapi().VBD.get_record(vbd)["VDI"] @@ -387,7 +380,7 @@ class VMOps(object): def unrescue(self, instance, callback): """Unrescue the specified instance""" vm = self._get_vm_opaque_ref(instance) - target_vm = VMHelper.lookup(self._session, "instance-00000001") + target_vm = VMHelper.lookup(self._session, "instance-00000012") vbds = self._session.get_xenapi().VM.get_VBDs(target_vm) @@ -397,7 +390,7 @@ class VMOps(object): VMHelper.unplug_vbd(self._session, vbd_ref) VMHelper.destroy_vbd(self._session, vbd_ref) - self.start(instance) + self._start(instance, vm) def get_info(self, instance): """Return data about VM instance""" -- cgit From ac5a1cfb0dbcebd36e7cbaab20795d03d523afee Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Mon, 21 Feb 2011 11:20:03 -0600 Subject: Stub out VM create --- nova/virt/xenapi/vmops.py | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 4f3468f8e..ac09179a3 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -27,6 +27,7 @@ import tempfile import uuid from nova import db +from nova import compute from nova import context from nova import log as logging from nova import exception @@ -49,6 +50,8 @@ class VMOps(object): def __init__(self, session): self.XenAPI = session.get_imported_xenapi() self._session = session + self.compute_api = compute.API() + VMHelper.XenAPI = self.XenAPI def list_instances(self): @@ -364,21 +367,31 @@ class VMOps(object): def rescue(self, instance, callback): """Rescue the specified instance""" vm = self._get_vm_opaque_ref(instance) - target_vm = VMHelper.lookup(self._session, "instance-00000012") - - self._shutdown(instance, vm) - vbd = self._session.get_xenapi().VM.get_VBDs(vm)[0] - vdi_ref = self._session.get_xenapi().VBD.get_record(vbd)["VDI"] - vbd_ref = VMHelper.create_vbd( - self._session, - target_vm, - vdi_ref, - 1, - False) + #self._shutdown(instance, vm) + #target_vm = VMHelper.lookup(self._session, "instance-00000012") + target_vm = self.compute_api.create( + context=context.get_admin_context(), + instance_type="m1.tiny", + image_id=1, + kernel_id=3, + ramdisk_id=2, + display_name="test", + display_description="test") + print context.get_admin_context().__dict__ + print target_vm + + #vbd = self._session.get_xenapi().VM.get_VBDs(vm)[0] + #vdi_ref = self._session.get_xenapi().VBD.get_record(vbd)["VDI"] + #vbd_ref = VMHelper.create_vbd( + # self._session, + # target_vm, + # vdi_ref, + # 1, + # False) # Plug the VBD into the target instance - self._session.call_xenapi("Async.VBD.plug", vbd_ref) + #self._session.call_xenapi("Async.VBD.plug", vbd_ref) def unrescue(self, instance, callback): """Unrescue the specified instance""" -- cgit From 78ed840ef2f7066c638a76cc3192fec2f93d8450 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Mon, 21 Feb 2011 12:48:34 -0600 Subject: Enable rescue testing --- nova/virt/xenapi/vmops.py | 51 ++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 3c9fd7d31..bd57dc9a1 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -406,8 +406,8 @@ class VMOps(object): if ramdisk: args['ramdisk-file'] = ramdisk task2 = self._session.async_call_plugin('glance', fn, args) - self._session.wait_for_task(instance.id, task1) - self._session.wait_for_task(instance.id, task2) + self._session.wait_for_task(task1, instance.id) + self._session.wait_for_task(task2, instance.id) LOG.debug(_("kernel/ramdisk files removed")) except self.XenAPI.Failure, exc: LOG.exception(exc) @@ -477,35 +477,36 @@ class VMOps(object): """Rescue the specified instance""" vm = self._get_vm_opaque_ref(instance) - #self._shutdown(instance, vm) - #target_vm = VMHelper.lookup(self._session, "instance-00000012") - target_vm = self.compute_api.create( - context=context.get_admin_context(), - instance_type="m1.tiny", - image_id=1, - kernel_id=3, - ramdisk_id=2, - display_name="test", - display_description="test") - print context.get_admin_context().__dict__ - print target_vm - - #vbd = self._session.get_xenapi().VM.get_VBDs(vm)[0] - #vdi_ref = self._session.get_xenapi().VBD.get_record(vbd)["VDI"] - #vbd_ref = VMHelper.create_vbd( - # self._session, - # target_vm, - # vdi_ref, - # 1, - # False) + self._shutdown(instance, vm) + target_vm = VMHelper.lookup(self._session, "instance-00000001") + #target_vm = self.compute_api.create( + # context=context.get_admin_context(), + # instance_type="m1.tiny", + # image_id=1, + # kernel_id=3, + # ramdisk_id=2, + # display_name="test", + # display_description="test") + #print context.get_admin_context().__dict__ + #print target_vm + + vbd = self._session.get_xenapi().VM.get_VBDs(vm)[0] + vdi_ref = self._session.get_xenapi().VBD.get_record(vbd)["VDI"] + vbd_ref = VMHelper.create_vbd( + self._session, + target_vm, + vdi_ref, + 1, + False) # Plug the VBD into the target instance - #self._session.call_xenapi("Async.VBD.plug", vbd_ref) + self._session.call_xenapi("Async.VBD.plug", vbd_ref) + pass def unrescue(self, instance, callback): """Unrescue the specified instance""" vm = self._get_vm_opaque_ref(instance) - target_vm = VMHelper.lookup(self._session, "instance-00000012") + target_vm = VMHelper.lookup(self._session, "instance-00000001") vbds = self._session.get_xenapi().VM.get_VBDs(target_vm) -- cgit From 94bd7e2c45ca971e318813bb1e897fb5e79ab7bd Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Wed, 23 Feb 2011 12:05:46 -0600 Subject: Removed pass --- nova/virt/xenapi/vmops.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index bd57dc9a1..7bffd8c6c 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -501,7 +501,6 @@ class VMOps(object): # Plug the VBD into the target instance self._session.call_xenapi("Async.VBD.plug", vbd_ref) - pass def unrescue(self, instance, callback): """Unrescue the specified instance""" -- cgit From 3c6a44327f0015cb531b06fbce38eb4e3a04ce6a Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Wed, 23 Feb 2011 20:13:50 +0100 Subject: Fixes lp715424, code now checks network range can fit num_networks * network_size --- nova/network/manager.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nova/network/manager.py b/nova/network/manager.py index c6eba225e..1b8627562 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -521,6 +521,11 @@ class VlanManager(NetworkManager): ' than 4094')) fixed_net = IPy.IP(cidr) + if fixed_net.len() < num_networks * network_size: + raise ValueError(_('The network range is not big enough to fit %s' + ' networks of size %s' % + (num_networks, network_size))) + fixed_net_v6 = IPy.IP(cidr_v6) network_size_v6 = 1 << 64 significant_bits_v6 = 64 -- cgit From 7c19fe87693b89d56ef9d9402d2667eacf297b97 Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Wed, 23 Feb 2011 20:51:27 +0100 Subject: Deleted trailing whitespace --- nova/network/manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/network/manager.py b/nova/network/manager.py index 1b8627562..7bdd56d7b 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -523,7 +523,7 @@ class VlanManager(NetworkManager): fixed_net = IPy.IP(cidr) if fixed_net.len() < num_networks * network_size: raise ValueError(_('The network range is not big enough to fit %s' - ' networks of size %s' % + ' networks of size %s' % (num_networks, network_size))) fixed_net_v6 = IPy.IP(cidr_v6) -- cgit From 9e018bbee1d4a308fdf1700bd25aa733cedc26e6 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 24 Feb 2011 13:01:16 -0600 Subject: Updated email in Authors --- .mailmap | 1 + Authors | 2 +- nova/virt/xenapi/vmops.py | 20 +++++++++----------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.mailmap b/.mailmap index a839eba6c..d479bfdf2 100644 --- a/.mailmap +++ b/.mailmap @@ -19,6 +19,7 @@ + Masumoto diff --git a/Authors b/Authors index 494e614a0..39241b45c 100644 --- a/Authors +++ b/Authors @@ -31,7 +31,7 @@ John Dewey Jonathan Bryce Jordan Rinke Josh Durgin -Josh Kearney +Josh Kearney Joshua McKenty Justin Santa Barbara Kei Masumoto diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 7bffd8c6c..a47d23f88 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -476,19 +476,15 @@ class VMOps(object): def rescue(self, instance, callback): """Rescue the specified instance""" vm = self._get_vm_opaque_ref(instance) - self._shutdown(instance, vm) + + # Temporary instance target_vm = VMHelper.lookup(self._session, "instance-00000001") - #target_vm = self.compute_api.create( - # context=context.get_admin_context(), - # instance_type="m1.tiny", - # image_id=1, - # kernel_id=3, - # ramdisk_id=2, - # display_name="test", - # display_description="test") - #print context.get_admin_context().__dict__ - #print target_vm + + # Plan of action + # Create `instance` object for rescue_vm + # rescue_instance = self._make_rescue_instance() # Write this + #rescue_vm = self.spawn(instance) vbd = self._session.get_xenapi().VM.get_VBDs(vm)[0] vdi_ref = self._session.get_xenapi().VBD.get_record(vbd)["VDI"] @@ -505,6 +501,8 @@ class VMOps(object): def unrescue(self, instance, callback): """Unrescue the specified instance""" vm = self._get_vm_opaque_ref(instance) + + # Temporary instance target_vm = VMHelper.lookup(self._session, "instance-00000001") vbds = self._session.get_xenapi().VM.get_VBDs(target_vm) -- cgit From 907df1b90e5c22eb82ce85bc12f48d8abf09b665 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 24 Feb 2011 13:57:11 -0600 Subject: nothing --- nova/virt/xenapi/vmops.py | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index a47d23f88..0b9b7d0a4 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -475,37 +475,29 @@ class VMOps(object): def rescue(self, instance, callback): """Rescue the specified instance""" - vm = self._get_vm_opaque_ref(instance) - self._shutdown(instance, vm) - - # Temporary instance - target_vm = VMHelper.lookup(self._session, "instance-00000001") + #vm = self._get_vm_opaque_ref(instance) + #self._shutdown(instance, vm) - # Plan of action - # Create `instance` object for rescue_vm - # rescue_instance = self._make_rescue_instance() # Write this + print instance.__dict__ + print instance.name + print "%s-rescue" % instance.name #rescue_vm = self.spawn(instance) - vbd = self._session.get_xenapi().VM.get_VBDs(vm)[0] - vdi_ref = self._session.get_xenapi().VBD.get_record(vbd)["VDI"] - vbd_ref = VMHelper.create_vbd( - self._session, - target_vm, - vdi_ref, - 1, - False) + #vbd = self._session.get_xenapi().VM.get_VBDs(vm)[0] + #vdi_ref = self._session.get_xenapi().VBD.get_record(vbd)["VDI"] + #vbd_ref = VMHelper.create_vbd( + # self._session, + # rescue_vm, + # vdi_ref, + # 1, + # False) - # Plug the VBD into the target instance - self._session.call_xenapi("Async.VBD.plug", vbd_ref) + #self._session.call_xenapi("Async.VBD.plug", vbd_ref) def unrescue(self, instance, callback): """Unrescue the specified instance""" vm = self._get_vm_opaque_ref(instance) - - # Temporary instance - target_vm = VMHelper.lookup(self._session, "instance-00000001") - - vbds = self._session.get_xenapi().VM.get_VBDs(target_vm) + vbds = self._session.get_xenapi().VM.get_VBDs(vm) for vbd_ref in vbds: vbd = self._session.get_xenapi().VBD.get_record(vbd_ref) @@ -513,7 +505,7 @@ class VMOps(object): VMHelper.unplug_vbd(self._session, vbd_ref) VMHelper.destroy_vbd(self._session, vbd_ref) - self._start(instance, vm) + self.reboot(instance) def get_info(self, instance): """Return data about VM instance""" -- cgit From 6033f657aad9bd5b244a21908caedfc92840c9cf Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Fri, 25 Feb 2011 10:54:37 -0600 Subject: Create rescue instance --- nova/db/sqlalchemy/models.py | 7 ++++- nova/virt/xenapi/vmops.py | 69 +++++++++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index 1882efeba..b1eb1a7b7 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -126,11 +126,16 @@ class Certificate(BASE, NovaBase): class Instance(BASE, NovaBase): """Represents a guest vm.""" __tablename__ = 'instances' + onset_files = [] + id = Column(Integer, primary_key=True, autoincrement=True) @property def name(self): - return FLAGS.instance_name_template % self.id + base_name = FLAGS.instance_name_template % self.id + if getattr(self, '_rescue', False): + base_name += "-rescue" + return base_name admin_pass = Column(String(255)) user_id = Column(String(255)) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 0b9b7d0a4..d70129d80 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -65,20 +65,20 @@ class VMOps(object): def spawn(self, instance): """Create VM instance""" - vm = VMHelper.lookup(self._session, instance.name) + instance_name = instance.name + vm = VMHelper.lookup(self._session, instance_name) if vm is not None: raise exception.Duplicate(_('Attempted to create' - ' non-unique name %s') % instance.name) + ' non-unique name %s') % instance_name) #ensure enough free memory is available if not VMHelper.ensure_free_mem(self._session, instance): - name = instance['name'] - LOG.exception(_('instance %(name)s: not enough free memory') - % locals()) - db.instance_set_state(context.get_admin_context(), - instance['id'], - power_state.SHUTDOWN) - return + LOG.exception(_('instance %(instance_name)s: not enough free ' + 'memory') % locals()) + db.instance_set_state(context.get_admin_context(), + instance['id'], + power_state.SHUTDOWN) + return user = AuthManager().get_user(instance.user_id) project = AuthManager().get_project(instance.project_id) @@ -150,9 +150,8 @@ class VMOps(object): LOG.debug(_('Starting VM %s...'), vm_ref) self._session.call_xenapi('VM.start', vm_ref, False, False) - instance_name = instance.name LOG.info(_('Spawning VM %(instance_name)s created %(vm_ref)s.') - % locals()) + % locals()) def _inject_onset_files(): onset_files = instance.onset_files @@ -176,18 +175,18 @@ class VMOps(object): def _wait_for_boot(): try: - state = self.get_info(instance['name'])['state'] + state = self.get_info(instance_name)['state'] db.instance_set_state(context.get_admin_context(), instance['id'], state) if state == power_state.RUNNING: - LOG.debug(_('Instance %s: booted'), instance['name']) + LOG.debug(_('Instance %s: booted'), instance_name) timer.stop() _inject_onset_files() return True except Exception, exc: LOG.warn(exc) LOG.exception(_('instance %s: failed to boot'), - instance['name']) + instance_name) db.instance_set_state(context.get_admin_context(), instance['id'], power_state.SHUTDOWN) @@ -475,24 +474,26 @@ class VMOps(object): def rescue(self, instance, callback): """Rescue the specified instance""" - #vm = self._get_vm_opaque_ref(instance) - #self._shutdown(instance, vm) + vm = self._get_vm_opaque_ref(instance) + self._shutdown(instance, vm) - print instance.__dict__ - print instance.name - print "%s-rescue" % instance.name - #rescue_vm = self.spawn(instance) + # log old instance + # log new instance - #vbd = self._session.get_xenapi().VM.get_VBDs(vm)[0] - #vdi_ref = self._session.get_xenapi().VBD.get_record(vbd)["VDI"] - #vbd_ref = VMHelper.create_vbd( - # self._session, - # rescue_vm, - # vdi_ref, - # 1, - # False) + instance._rescue = True + self.spawn(instance) + rescue_vm = self._get_vm_opaque_ref(instance) - #self._session.call_xenapi("Async.VBD.plug", vbd_ref) + vbd = self._session.get_xenapi().VM.get_VBDs(vm)[0] + vdi_ref = self._session.get_xenapi().VBD.get_record(vbd)["VDI"] + vbd_ref = VMHelper.create_vbd( + self._session, + rescue_vm, + vdi_ref, + 1, + False) + + self._session.call_xenapi("Async.VBD.plug", vbd_ref) def unrescue(self, instance, callback): """Unrescue the specified instance""" @@ -505,7 +506,15 @@ class VMOps(object): VMHelper.unplug_vbd(self._session, vbd_ref) VMHelper.destroy_vbd(self._session, vbd_ref) - self.reboot(instance) + # fetch old instance + # fetch new instance + # destroy new instance + # start old instance + + self.destroy(instance) + instance._rescue = False + + self._start(instance, vm) def get_info(self, instance): """Return data about VM instance""" -- cgit From 2dc9d8bfe4bcd61c4d634767715b2be3a214426e Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Fri, 25 Feb 2011 12:43:09 -0600 Subject: Teardown rescue instance --- nova/virt/xenapi/vmops.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 93c2ab0c7..6b531ca2c 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -113,7 +113,7 @@ class VMOps(object): self.create_vifs(instance, networks) LOG.debug(_('Starting VM %s...'), vm_ref) - self._session.call_xenapi('VM.start', vm_ref, False, False) + self._start(instance, vm_ref) LOG.info(_('Spawning VM %(instance_name)s created %(vm_ref)s.') % locals()) @@ -438,12 +438,14 @@ class VMOps(object): def rescue(self, instance, callback): """Rescue the specified instance""" + rescue_vm = VMHelper.lookup(self._session, instance.name + "-rescue") + if rescue_vm: + raise RuntimeError(_( + "Instance is already in Rescue Mode: %s" % instance.name)) + vm = self._get_vm_opaque_ref(instance) self._shutdown(instance, vm) - # log old instance - # log new instance - instance._rescue = True self.spawn(instance) rescue_vm = self._get_vm_opaque_ref(instance) @@ -461,8 +463,16 @@ class VMOps(object): def unrescue(self, instance, callback): """Unrescue the specified instance""" - vm = self._get_vm_opaque_ref(instance) - vbds = self._session.get_xenapi().VM.get_VBDs(vm) + rescue_vm = VMHelper.lookup(self._session, instance.name + "-rescue") + + if not rescue_vm: + raise exception.NotFound(_( + "Instance is not in Rescue Mode: %s" % instance.name)) + + original_vm = self._get_vm_opaque_ref(instance) + vbds = self._session.get_xenapi().VM.get_VBDs(rescue_vm) + + instance._rescue = False for vbd_ref in vbds: vbd = self._session.get_xenapi().VBD.get_record(vbd_ref) @@ -470,15 +480,13 @@ class VMOps(object): VMHelper.unplug_vbd(self._session, vbd_ref) VMHelper.destroy_vbd(self._session, vbd_ref) - # fetch old instance - # fetch new instance - # destroy new instance - # start old instance + task1 = self._session.call_xenapi("Async.VM.hard_shutdown", rescue_vm) + self._session.wait_for_task(task1, instance.id) - self.destroy(instance) - instance._rescue = False + task2 = self._session.call_xenapi('Async.VM.destroy', rescue_vm) + self._session.wait_for_task(task2, instance.id) - self._start(instance, vm) + self._start(instance, original_vm) def get_info(self, instance): """Return data about VM instance""" -- cgit From 6cfa479a1375fb8274dd9130946eab38e1398538 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Fri, 25 Feb 2011 14:35:29 -0600 Subject: Set rescue instance VIF device --- nova/virt/xenapi/vm_utils.py | 4 ++-- nova/virt/xenapi/vmops.py | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 206201817..f0b1e993c 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -207,11 +207,11 @@ class VMHelper(HelperBase): raise StorageError(_('Unable to destroy VBD %s') % vbd_ref) @classmethod - def create_vif(cls, session, vm_ref, network_ref, mac_address): + def create_vif(cls, session, vm_ref, network_ref, mac_address, dev="0"): """Create a VIF record. Returns a Deferred that gives the new VIF reference.""" vif_rec = {} - vif_rec['device'] = '0' + vif_rec['device'] = dev vif_rec['network'] = network_ref vif_rec['VM'] = vm_ref vif_rec['MAC'] = mac_address diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 6b531ca2c..c1e9bec62 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -483,6 +483,14 @@ class VMOps(object): task1 = self._session.call_xenapi("Async.VM.hard_shutdown", rescue_vm) self._session.wait_for_task(task1, instance.id) + vdis = VMHelper.lookup_vm_vdis(self._session, rescue_vm) + for vdi in vdis: + try: + task = self._session.call_xenapi('Async.VDI.destroy', vdi) + self._session.wait_for_task(task, instance.id) + except self.XenAPI.Failure: + continue + task2 = self._session.call_xenapi('Async.VM.destroy', rescue_vm) self._session.wait_for_task(task2, instance.id) @@ -574,8 +582,17 @@ class VMOps(object): NetworkHelper.find_network_with_bridge(self._session, bridge) if network_ref: - VMHelper.create_vif(self._session, vm_opaque_ref, - network_ref, instance.mac_address) + try: + device = "1" if instance._rescue else "0" + except AttributeError: + device = "0" + + VMHelper.create_vif( + self._session, + vm_opaque_ref, + network_ref, + instance.mac_address, + device) def reset_network(self, instance): """ -- cgit From 7ad2e0a731e6b2fbace8528439f6a8c2f0d5aaad Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Fri, 25 Feb 2011 14:47:25 -0600 Subject: Removed unnecessary compute import --- nova/virt/xenapi/vmops.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index c1e9bec62..3e3c9ff6e 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -27,7 +27,6 @@ import tempfile import uuid from nova import db -from nova import compute from nova import context from nova import log as logging from nova import exception @@ -50,7 +49,6 @@ class VMOps(object): def __init__(self, session): self.XenAPI = session.get_imported_xenapi() self._session = session - self.compute_api = compute.API() VMHelper.XenAPI = self.XenAPI -- cgit From 97566c04b3a04626f1bc1b66e72c61b4621b6c7d Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Fri, 25 Feb 2011 16:18:11 -0600 Subject: Bootlock original instance during rescue --- nova/virt/xenapi/vmops.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 3e3c9ff6e..21477a18c 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -196,6 +196,19 @@ class VMOps(object): _('Instance not present %s') % instance_name) return vm + def _bootlock(self, vm, unlock=False): + """Prevent an instance from booting""" + if unlock: + self._session.call_xenapi( + "VM.remove_from_blocked_operations", + vm, + "start") + else: + self._session.call_xenapi( + "VM.set_blocked_operations", + vm, + {"start": ""}) + def snapshot(self, instance, image_id): """ Create snapshot from a running VM instance @@ -443,6 +456,7 @@ class VMOps(object): vm = self._get_vm_opaque_ref(instance) self._shutdown(instance, vm) + self._bootlock(vm) instance._rescue = True self.spawn(instance) @@ -492,6 +506,7 @@ class VMOps(object): task2 = self._session.call_xenapi('Async.VM.destroy', rescue_vm) self._session.wait_for_task(task2, instance.id) + self._bootlock(original_vm, unlock=True) self._start(instance, original_vm) def get_info(self, instance): -- cgit From 05a96b320cf1d6b911b0edb11df0ed408a894e77 Mon Sep 17 00:00:00 2001 From: Brian Lamar Date: Mon, 28 Feb 2011 14:49:03 -0500 Subject: Edited `nova.api.openstack.common:limited` method to raise an HTTPBadRequest exception if a negative limit or offset is given. I'm not confident that this is the correct approach, because I guess this method could be called out of an API/WSGI context, but the method *is* located in the OpenStack API module and is currently only used in WSGI-capable methods, so we should be safe. --- nova/api/openstack/common.py | 8 +++++++- nova/tests/api/openstack/test_common.py | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 1dc3767e2..9f85c5c8a 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -15,6 +15,8 @@ # License for the specific language governing permissions and limitations # under the License. +import webob.exc + from nova import exception @@ -27,7 +29,8 @@ def limited(items, request, max_limit=1000): GET variables. 'offset' is where to start in the list, and 'limit' is the maximum number of items to return. If 'limit' is not specified, 0, or > max_limit, we default - to max_limit. + to max_limit. Negative values for either offset or limit + will cause exc.HTTPBadRequest() exceptions to be raised. @kwarg max_limit: The maximum number of items to return from 'items' """ try: @@ -40,6 +43,9 @@ def limited(items, request, max_limit=1000): except ValueError: limit = max_limit + if offset < 0 or limit < 0: + raise webob.exc.HTTPBadRequest() + limit = min(max_limit, limit or max_limit) range_end = offset + limit return items[offset:range_end] diff --git a/nova/tests/api/openstack/test_common.py b/nova/tests/api/openstack/test_common.py index 59d850157..92023362c 100644 --- a/nova/tests/api/openstack/test_common.py +++ b/nova/tests/api/openstack/test_common.py @@ -19,6 +19,7 @@ Test suites for 'common' code used throughout the OpenStack HTTP API. """ +import webob.exc from webob import Request @@ -160,3 +161,23 @@ class LimiterTest(test.TestCase): self.assertEqual(limited(items, req, max_limit=2000), items[3:]) req = Request.blank('/?offset=3000&limit=10') self.assertEqual(limited(items, req, max_limit=2000), []) + + def test_limiter_negative_limit(self): + """ + Test a negative limit. + """ + def _limit_large(): + limited(self.large, req, max_limit=2000) + + req = Request.blank('/?limit=-3000') + self.assertRaises(webob.exc.HTTPBadRequest, _limit_large) + + def test_limiter_negative_offset(self): + """ + Test a negative offset. + """ + def _limit_large(): + limited(self.large, req, max_limit=2000) + + req = Request.blank('/?offset=-30') + self.assertRaises(webob.exc.HTTPBadRequest, _limit_large) -- cgit From fbcbf5ef805748bea29e4135ee8989830064c273 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Tue, 1 Mar 2011 10:55:13 -0600 Subject: Fixed trunk merge issues --- nova/virt/xenapi/vm_utils.py | 2 +- nova/virt/xenapi/vmops.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 527d8700c..977c19359 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -343,7 +343,7 @@ class VMHelper(HelperBase): kwargs = {'params': pickle.dumps(params)} task = session.async_call_plugin('glance', 'download_vhd', kwargs) - vdi_uuid = session.wait_for_task(instance_id, task) + vdi_uuid = session.wait_for_task(task, instance_id) scan_sr(session, instance_id, sr_ref) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 43b63bfd8..a3379fa7f 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -411,7 +411,7 @@ class VMOps(object): args = {'kernel-file': kernel, 'ramdisk-file': ramdisk} task = self._session.async_call_plugin( 'glance', 'remove_kernel_ramdisk', args) - self._session.wait_for_task(instance.id, task) + self._session.wait_for_task(task, instance.id) LOG.debug(_("kernel/ramdisk files removed")) -- cgit From 93b69176277217a3cfae738dd328e649081a370f Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Tue, 1 Mar 2011 13:26:31 -0600 Subject: Review feedback --- nova/compute/manager.py | 42 ++++++++++++++++++++++++------------------ nova/virt/xenapi/vmops.py | 42 ++++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index ef7ed55c9..3af97683f 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -370,16 +370,19 @@ class ComputeManager(manager.Manager): context = context.elevated() instance_ref = self.db.instance_get(context, instance_id) LOG.audit(_('instance %s: rescuing'), instance_id, context=context) - self.db.instance_set_state(context, - instance_id, - power_state.NOSTATE, - 'rescuing') + self.db.instance_set_state( + context, + instance_id, + power_state.NOSTATE, + 'rescuing') self.network_manager.setup_compute_network(context, instance_id) - self.driver.rescue(instance_ref, - lambda result: self._update_state_callback(self, - context, - instance_id, - result)) + self.driver.rescue( + instance_ref, + lambda result: self._update_state_callback( + self, + context, + instance_id, + result)) self._update_state(context, instance_id) @exception.wrap_exception @@ -389,15 +392,18 @@ class ComputeManager(manager.Manager): context = context.elevated() instance_ref = self.db.instance_get(context, instance_id) LOG.audit(_('instance %s: unrescuing'), instance_id, context=context) - self.db.instance_set_state(context, - instance_id, - power_state.NOSTATE, - 'unrescuing') - self.driver.unrescue(instance_ref, - lambda result: self._update_state_callback(self, - context, - instance_id, - result)) + self.db.instance_set_state( + context, + instance_id, + power_state.NOSTATE, + 'unrescuing') + self.driver.unrescue( + instance_ref, + lambda result: self._update_state_callback( + self, + context, + instance_id, + result)) self._update_state(context, instance_id) @staticmethod diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index a3379fa7f..1c58f529d 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -202,18 +202,19 @@ class VMOps(object): _('Instance not present %s') % instance_name) return vm - def _bootlock(self, vm, unlock=False): + def _acquire_bootlock(self, vm): """Prevent an instance from booting""" - if unlock: - self._session.call_xenapi( - "VM.remove_from_blocked_operations", - vm, - "start") - else: - self._session.call_xenapi( - "VM.set_blocked_operations", - vm, - {"start": ""}) + self._session.call_xenapi( + "VM.set_blocked_operations", + vm, + {"start": ""}) + + def _release_bootlock(self, vm): + """Allow an instance to boot""" + self._session.call_xenapi( + "VM.remove_from_blocked_operations", + vm, + "start") def snapshot(self, instance, image_id): """ Create snapshot from a running VM instance @@ -338,7 +339,7 @@ class VMOps(object): raise RuntimeError(resp_dict['message']) return resp_dict['message'] - def _shutdown(self, instance, vm): + def _shutdown(self, instance, vm, hard=True): """Shutdown an instance""" state = self.get_info(instance['name'])['state'] if state == power_state.SHUTDOWN: @@ -350,12 +351,13 @@ class VMOps(object): LOG.debug(_("Shutting down VM for Instance %(instance_id)s") % locals()) try: - try: - task = self._session.call_xenapi("Async.VM.clean_shutdown", vm) - self._session.wait_for_task(task, instance.id) - except self.XenAPI.Failure: + task = None + if hard: task = self._session.call_xenapi("Async.VM.hard_shutdown", vm) - self._session.wait_for_task(task, instance.id) + else: + task = self._session.call_xenapi("Async.VM.clean_shutdown", vm) + + self._session.wait_for_task(task, instance.id) except self.XenAPI.Failure, exc: LOG.exception(exc) @@ -501,7 +503,7 @@ class VMOps(object): vm = self._get_vm_opaque_ref(instance) self._shutdown(instance, vm) - self._bootlock(vm) + self._acquire_bootlock(vm) instance._rescue = True self.spawn(instance) @@ -533,7 +535,7 @@ class VMOps(object): for vbd_ref in vbds: vbd = self._session.get_xenapi().VBD.get_record(vbd_ref) - if vbd["userdevice"] == str(1): + if vbd["userdevice"] == "1": VMHelper.unplug_vbd(self._session, vbd_ref) VMHelper.destroy_vbd(self._session, vbd_ref) @@ -551,7 +553,7 @@ class VMOps(object): task2 = self._session.call_xenapi('Async.VM.destroy', rescue_vm) self._session.wait_for_task(task2, instance.id) - self._bootlock(original_vm, unlock=True) + self._release_bootlock(original_vm) self._start(instance, original_vm) def get_info(self, instance): -- cgit From 6d62f387e39b42821f8a8f6ca560dd47b3bb9c7e Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Wed, 2 Mar 2011 15:42:21 -0600 Subject: Inject IPv6 data into XenStore for instance --- nova/virt/xenapi/vmops.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index bc39aa140..094b41588 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -514,18 +514,30 @@ class VMOps(object): network_IPs = [ip for ip in IPs if ip.network_id == network.id] def ip_dict(ip): - return {'netmask': network['netmask'], - 'enabled': '1', - 'ip': ip.address} + return { + "ip": ip.address, + "netmask": network["netmask"], + "enabled": "1"} + + def ip6_dict(ip6): + return { + "ip": ip6.addressV6, + "netmask": ip6.netmaskV6, + "gateway": ip6.gatewayV6, + "enabled": "1"} mac_id = instance.mac_address.replace(':', '') location = 'vm-data/networking/%s' % mac_id - mapping = {'label': network['label'], - 'gateway': network['gateway'], - 'mac': instance.mac_address, - 'dns': [network['dns']], - 'ips': [ip_dict(ip) for ip in network_IPs]} + mapping = { + 'label': network['label'], + 'gateway': network['gateway'], + 'mac': instance.mac_address, + 'dns': [network['dns']], + 'ips': [ip_dict(ip) for ip in network_IPs], + 'ip6s': [ip6_dict(ip) for ip in network_IPs]} + self.write_to_param_xenstore(vm_opaque_ref, {location: mapping}) + try: self.write_to_xenstore(vm_opaque_ref, location, mapping['location']) -- cgit From 67d9051551775df73aed118a3ca307c61d284225 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Wed, 2 Mar 2011 16:20:54 -0600 Subject: Added IPv6 migrations --- .../versions/007_add_ipv6_to_fixed_ips.py | 90 ++++++++++++++++++++++ nova/db/sqlalchemy/models.py | 3 + 2 files changed, 93 insertions(+) create mode 100644 nova/db/sqlalchemy/migrate_repo/versions/007_add_ipv6_to_fixed_ips.py diff --git a/nova/db/sqlalchemy/migrate_repo/versions/007_add_ipv6_to_fixed_ips.py b/nova/db/sqlalchemy/migrate_repo/versions/007_add_ipv6_to_fixed_ips.py new file mode 100644 index 000000000..427934d53 --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/007_add_ipv6_to_fixed_ips.py @@ -0,0 +1,90 @@ +# Copyright 2011 OpenStack LLC +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from sqlalchemy import * +from migrate import * + +from nova import log as logging + + +meta = MetaData() + + +# Table stub-definitions +# Just for the ForeignKey and column creation to succeed, these are not the +# actual definitions of instances or services. +# +fixed_ips = Table( + "fixed_ips", + meta, + Column( + "id", + Integer(), + primary_key=True, + nullable=False)) + +# +# New Tables +# +# None + +# +# Tables to alter +# +# None + +# +# Columns to add to existing tables +# + +fixed_ips_addressV6 = Column( + "addressV6", + String( + length=255, + convert_unicode=False, + assert_unicode=None, + unicode_error=None, + _warn_on_bytestring=False)) + + +fixed_ips_netmaskV6 = Column( + "netmaskV6", + String( + length=3, + convert_unicode=False, + assert_unicode=None, + unicode_error=None, + _warn_on_bytestring=False)) + + +fixed_ips_gatewayV6 = Column( + "gatewayV6", + String( + length=255, + convert_unicode=False, + assert_unicode=None, + unicode_error=None, + _warn_on_bytestring=False)) + + +def upgrade(migrate_engine): + # Upgrade operations go here. Don't create your own engine; + # bind migrate_engine to your metadata + meta.bind = migrate_engine + + # Add columns to existing tables + fixed_ips.create_column(fixed_ips_addressV6) + fixed_ips.create_column(fixed_ips_netmaskV6) + fixed_ips.create_column(fixed_ips_gatewayV6) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index 1882efeba..821fd4a83 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -437,6 +437,9 @@ class FixedIp(BASE, NovaBase): allocated = Column(Boolean, default=False) leased = Column(Boolean, default=False) reserved = Column(Boolean, default=False) + addressV6 = Column(String(255)) + netmaskV6 = Column(String(3)) + gatewayV6 = Column(String(255)) class User(BASE, NovaBase): -- cgit From e34e9dd982870915f8c4dbf84a08bece42b0c592 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Wed, 2 Mar 2011 17:09:50 -0600 Subject: Updated docstrings --- nova/virt/xenapi/vmops.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 1c58f529d..10d5c0160 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -495,7 +495,12 @@ class VMOps(object): self._wait_with_callback(instance.id, task, callback) def rescue(self, instance, callback): - """Rescue the specified instance""" + """Rescue the specified instance + - shutdown the instance VM + - set 'bootlock' to prevent the instance from starting in rescue + - spawn a rescue VM (the vm name-label will be instance-N-rescue) + + """ rescue_vm = VMHelper.lookup(self._session, instance.name + "-rescue") if rescue_vm: raise RuntimeError(_( @@ -521,7 +526,12 @@ class VMOps(object): self._session.call_xenapi("Async.VBD.plug", vbd_ref) def unrescue(self, instance, callback): - """Unrescue the specified instance""" + """Unrescue the specified instance + - unplug the instance VM's disk from the rescue VM + - teardown the rescue VM + - release the bootlock to allow the instance VM to start + + """ rescue_vm = VMHelper.lookup(self._session, instance.name + "-rescue") if not rescue_vm: -- cgit