From 12285e24d500e6d3e36ef27a3e44e3c615c8f065 Mon Sep 17 00:00:00 2001 From: anthony Date: Thu, 31 May 2012 13:37:13 -0700 Subject: [PATCH] CS-15155 : after system VMs boot up, destroy CD virtual device for System VM when reconnect XenServer host, try to destroy CD virtual device for System VM, this is for upgrade Reviewed-By : kelven --- .../xen/resource/CitrixResourceBase.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 4b8146b3be2..d9740b7ae73 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -1100,6 +1100,26 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return cdromVBD; } + protected void destroyPatchVbd(Connection conn, String vmName) throws XmlRpcException, XenAPIException { + try { + if( !vmName.startsWith("r-") && !vmName.startsWith("s-") && !vmName.startsWith("v-") ) { + return; + } + Set vms = VM.getByNameLabel(conn, vmName); + for ( VM vm : vms ) { + Set vbds = vm.getVBDs(conn); + for( VBD vbd : vbds ) { + if (vbd.getType(conn) == Types.VbdType.CD ) { + vbd.destroy(conn); + break; + } + } + } + } catch (Exception e) { + s_logger.debug("Cannot destory CD-ROM device for VM " + vmName + " due to " + e.toString(), e); + } + } + protected CheckSshAnswer execute(CheckSshCommand cmd) { Connection conn = getConnection(); String vmName = cmd.getName(); @@ -1115,6 +1135,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe if (result != null) { return new CheckSshAnswer(cmd, "Can not ping System vm " + vmName + "due to:" + result); } + destroyPatchVbd(conn, vmName); } catch (Exception e) { return new CheckSshAnswer(cmd, e); } @@ -2679,7 +2700,14 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe callHostPlugin(conn, "vmopsSnapshot", "unmountSnapshotsDir", "dcId", dcId.toString()); setupLinkLocalNetwork(conn); - + // try to destroy CD-ROM device for all system VMs + try { + Set vms = VM.getAll(conn); + for ( VM vm : vms ) { + destroyPatchVbd(conn, vm.getNameLabel(conn)); + } + } catch (Exception e) { + } try { boolean result = cleanupHaltedVms(conn); if (!result) {