Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 942D5105F0 for ; Fri, 23 Aug 2013 22:27:09 +0000 (UTC) Received: (qmail 53624 invoked by uid 500); 23 Aug 2013 22:27:09 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 53587 invoked by uid 500); 23 Aug 2013 22:27:09 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 53495 invoked by uid 99); 23 Aug 2013 22:27:09 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Aug 2013 22:27:09 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 047538C440E; Fri, 23 Aug 2013 22:27:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mchen@apache.org To: commits@cloudstack.apache.org Date: Fri, 23 Aug 2013 22:27:09 -0000 Message-Id: <0e1b7162117d47f1b0f5224f3bb613c0@git.apache.org> In-Reply-To: <501ad78618154be7aa46331b914afa4e@git.apache.org> References: <501ad78618154be7aa46331b914afa4e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/3] git commit: updated refs/heads/master to c6e5697 CLOUDSTACK-4480: Handle DestroyCommand in VmwareResource to evict unused template from primary storage pool. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/2807d083 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2807d083 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2807d083 Branch: refs/heads/master Commit: 2807d083dbd75deff0216caa26804bd1ce7f64dc Parents: 4218ce4 Author: Min Chen Authored: Fri Aug 23 14:34:12 2013 -0700 Committer: Min Chen Committed: Fri Aug 23 15:26:43 2013 -0700 ---------------------------------------------------------------------- .../vmware/resource/VmwareResource.java | 45 +++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2807d083/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 5ab2216..5c743d5 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -6448,8 +6448,49 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa @Override public Answer execute(DestroyCommand cmd) { - // TODO Auto-generated method stub - return null; + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource DestroyCommand to evict template from storage pool: " + _gson.toJson(cmd)); + } + + try { + VmwareContext context = getServiceContext(null); + VmwareHypervisorHost hyperHost = getHyperHost(context, null); + VolumeTO vol = cmd.getVolume(); + + ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, vol.getPoolUuid()); + if (morDs == null) { + String msg = "Unable to find datastore based on volume mount point " + vol.getMountPoint(); + s_logger.error(msg); + throw new Exception(msg); + } + + ManagedObjectReference morCluster = hyperHost.getHyperHostCluster(); + ClusterMO clusterMo = new ClusterMO(context, morCluster); + + VirtualMachineMO vmMo = clusterMo.findVmOnHyperHost(vol.getPath()); + if (vmMo != null) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Destroy template volume " + vol.getPath()); + } + vmMo.destroy(); + } + else{ + if (s_logger.isInfoEnabled()) { + s_logger.info("Template volume " + vol.getPath() + " is not found, no need to delete."); + } + } + return new Answer(cmd, true, "Success"); + + } catch (Throwable e) { + if (e instanceof RemoteException) { + s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); + invalidateServiceContext(null); + } + + String msg = "DestroyCommand failed due to " + VmwareHelper.getExceptionMessage(e); + s_logger.error(msg, e); + return new Answer(cmd, false, msg); + } } private boolean isVMWareToolsInstalled(VirtualMachineMO vmMo) throws Exception{ GuestInfo guestInfo = vmMo.getVmGuestInfo();