cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject git commit: updated refs/heads/4.2 to 2e75e8c
Date Mon, 21 Oct 2013 18:11:30 GMT
Updated Branches:
  refs/heads/4.2 b6a13d125 -> 2e75e8ced


CLOUDSTACK-4894: DestroyVirtualMachine API - added "expunge" admin-only parameter. When passed
as true, the vm gets expunged immediately (false by default to preserve the initial command
behavior)


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/2e75e8ce
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2e75e8ce
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2e75e8ce

Branch: refs/heads/4.2
Commit: 2e75e8ced0a9d7c59e39dbfececb50fcc9e13f6a
Parents: b6a13d1
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Mon Oct 21 09:43:29 2013 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Mon Oct 21 09:51:46 2013 -0700

----------------------------------------------------------------------
 .../org/apache/cloudstack/api/ApiConstants.java |  1 +
 .../api/command/user/vm/DestroyVMCmd.java       | 26 ++++++++++++++++----
 server/src/com/cloud/vm/UserVmManagerImpl.java  | 19 +++++++++++++-
 3 files changed, 40 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2e75e8ce/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index 761ff45..d9226c4 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -522,6 +522,7 @@ public class ApiConstants {
     public static final String ROUTING = "isrouting";
     public static final String SERVICE_STATE = "servicestate";
     public static final String MAX_CONNECTIONS = "maxconnections";
+    public static final String EXPUNGE = "expunge";
 
     public enum HostDetails {
         all, capacity, events, stats, min;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2e75e8ce/api/src/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java
index 567768d..0f11da9 100644
--- a/api/src/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java
@@ -16,6 +16,8 @@
 // under the License.
 package org.apache.cloudstack.api.command.user.vm;
 
+import java.util.List;
+
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
@@ -29,7 +31,6 @@ import com.cloud.async.AsyncJob;
 import com.cloud.event.EventTypes;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.user.Account;
 import com.cloud.user.UserContext;
 import com.cloud.uservm.UserVm;
@@ -47,7 +48,12 @@ public class DestroyVMCmd extends BaseAsyncCmd {
     @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=UserVmResponse.class,
             required=true, description="The ID of the virtual machine")
     private Long id;
-
+    
+    
+    @Parameter(name=ApiConstants.EXPUNGE, type=CommandType.BOOLEAN, 
+            description="If true is passed, the vm is expunged immediately. False by default.
Parameter can be passed to the call by ROOT/Domain admin only", since="4.2.1")
+    private Boolean expunge;
+    
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -55,6 +61,13 @@ public class DestroyVMCmd extends BaseAsyncCmd {
     public Long getId() {
         return id;
     }
+    
+    public boolean getExpunge() {
+        if (expunge == null) {
+            return false;
+        } 
+        return expunge;
+    }
 
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
@@ -96,11 +109,14 @@ public class DestroyVMCmd extends BaseAsyncCmd {
     @Override
     public void execute() throws ResourceUnavailableException, ConcurrentOperationException{
         UserContext.current().setEventDetails("Vm Id: "+getId());
-        UserVm result;
-        result = _userVmService.destroyVm(this);
+        UserVm result = _userVmService.destroyVm(this);
 
+        UserVmResponse response = new UserVmResponse();
         if (result != null) {
-            UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine",
result).get(0);
+            List<UserVmResponse> responses =  _responseGenerator.createUserVmResponse("virtualmachine",
result);
+            if (responses != null && !responses.isEmpty()) {
+                response = responses.get(0);
+            }
             response.setResponseName("virtualmachine");
             this.setResponseObject(response);
         } else {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2e75e8ce/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 812f838..41ad50c 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -39,6 +39,7 @@ import org.apache.cloudstack.affinity.AffinityGroupService;
 import org.apache.cloudstack.affinity.AffinityGroupVO;
 import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
 import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
+import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseCmd.HTTPMethod;
 import org.apache.cloudstack.api.command.admin.vm.AssignVMCmd;
 import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd;
@@ -1981,7 +1982,23 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Use
     @ActionEvent(eventType = EventTypes.EVENT_VM_DESTROY, eventDescription = "destroying
Vm", async = true)
     public UserVm destroyVm(DestroyVMCmd cmd)
             throws ResourceUnavailableException, ConcurrentOperationException {
-        return destroyVm(cmd.getId());
+        UserContext ctx = UserContext.current();
+        long vmId = cmd.getId();
+        boolean expunge = cmd.getExpunge();
+        
+        if (!_accountMgr.isAdmin(ctx.getCaller().getType()) && expunge) {
+            throw new PermissionDeniedException("Parameter " + ApiConstants.EXPUNGE + " can
be passed by Admin only");
+        }
+        
+        UserVm destroyedVm = destroyVm(vmId);
+        if (expunge) {
+            UserVmVO vm = _vmDao.findById(vmId);
+            if (!expunge(vm, ctx.getCallerUserId(), ctx.getCaller())) {
+                throw new CloudRuntimeException("Failed to expunge vm " + destroyedVm);
+            }
+        }
+        
+        return destroyedVm;
     }
 
     @Override


Mime
View raw message