From 16e981928af570c9e5cffe3b09c27e7ceea754ad 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 6ae752fd200..90cb53dc497 100644 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java +++ b/agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java @@ -134,6 +134,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.StoragePoolTO; @@ -1116,6 +1117,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) { @@ -1225,6 +1228,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) { String snapshotName = cmd.getSnapshotName(); String VolPath = cmd.getVolumePath();