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 B9F5F10A4E for ; Mon, 26 Aug 2013 23:32:44 +0000 (UTC) Received: (qmail 90947 invoked by uid 500); 26 Aug 2013 23:32:38 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 90752 invoked by uid 500); 26 Aug 2013 23:32:38 -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 90242 invoked by uid 99); 26 Aug 2013 23:32:37 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Aug 2013 23:32:37 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 854851E1C1; Mon, 26 Aug 2013 23:32:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: edison@apache.org To: commits@cloudstack.apache.org Date: Mon, 26 Aug 2013 23:32:50 -0000 Message-Id: In-Reply-To: <156de7f76e9b4060a39a80b0b59715ab@git.apache.org> References: <156de7f76e9b4060a39a80b0b59715ab@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [14/50] [abbrv] git commit: updated refs/heads/4.2 to a23322b 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/c6928f2f Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c6928f2f Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c6928f2f Branch: refs/heads/4.2 Commit: c6928f2f5390420ea3f578ff89885aff3caff98e Parents: 3a12718 Author: Min Chen Authored: Fri Aug 23 14:34:12 2013 -0700 Committer: Min Chen Committed: Fri Aug 23 14:36:11 2013 -0700 ---------------------------------------------------------------------- .../vmware/resource/VmwareResource.java | 45 +++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6928f2f/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 9cb6115..e883433 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 @@ -6587,8 +6587,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{