From bf1b35b3ddc5ec8e5fcc38d04e0eef3443f294b2 Mon Sep 17 00:00:00 2001 From: edison Date: Thu, 26 Aug 2010 13:15:18 -0700 Subject: [PATCH] Issue #: 5935, 5937 Status 5935: resolved fixed Status 5937: resolved fixed --- .../computing/LibvirtComputingResource.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java index 03e878e59c7..1722a4b2878 100644 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java +++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java @@ -124,6 +124,7 @@ import com.cloud.agent.api.storage.CreateAnswer; import com.cloud.agent.api.storage.CreateCommand; import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer; import com.cloud.agent.api.storage.CreatePrivateTemplateCommand; +import com.cloud.agent.api.storage.DestroyCommand; import com.cloud.agent.api.storage.DownloadAnswer; import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; import com.cloud.agent.api.to.DiskCharacteristicsTO; @@ -1045,6 +1046,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return execute((MaintainCommand) cmd); } else if (cmd instanceof CreateCommand) { return execute((CreateCommand) cmd); + } else if (cmd instanceof DestroyCommand) { + return execute((DestroyCommand) cmd); } else if (cmd instanceof PrimaryStorageDownloadCommand) { return execute((PrimaryStorageDownloadCommand) cmd); } else if (cmd instanceof CreatePrivateTemplateCommand) { @@ -1144,6 +1147,25 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } } + + public Answer execute(DestroyCommand cmd) { + VolumeTO vol = cmd.getVolume(); + + StorageVol volume = getVolume(vol.getPath()); + if (volume == null) { + s_logger.debug("Failed to find the volume: " + vol.getPath()); + return new Answer(cmd, true, "Success"); + } + try { + volume.delete(0); + volume.free(); + } catch (LibvirtException e) { + s_logger.debug("Failed to delete volume: " + e.toString()); + return new Answer(cmd, false, e.toString()); + } + return new Answer(cmd, true, "Success"); + } + protected ManageSnapshotAnswer execute(final ManageSnapshotCommand cmd) { /*TODO: no snapshot support for KVM right now, but create_private_template needs us to return true here*/ return new ManageSnapshotAnswer(cmd, cmd.getSnapshotId(), cmd.getVolumePath(), true, null);