incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mlsoren...@apache.org
Subject git commit: refs/heads/master - Summary: Add missing ResizeVolumeCommand in VmwareResource.java
Date Wed, 06 Feb 2013 14:54:41 GMT
Updated Branches:
  refs/heads/master 6e4aeeadf -> c5185c09e


Summary: Add missing ResizeVolumeCommand in VmwareResource.java

Submitted-by: hongtu_zang <hongtu_zang@tcloudcomputing.com>
Signed-off-by: Marcus Sorensen <marcus@betterservers.com>


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

Branch: refs/heads/master
Commit: c5185c09efd8747f22e1ed4268cea3d037d6fde6
Parents: 6e4aeea
Author: Marcus Sorensen <marcus@betterservers.com>
Authored: Wed Feb 6 07:52:37 2013 -0700
Committer: Marcus Sorensen <marcus@betterservers.com>
Committed: Wed Feb 6 07:52:37 2013 -0700

----------------------------------------------------------------------
 .../hypervisor/vmware/resource/VmwareResource.java |   52 +++++++++++++++
 .../src/com/cloud/storage/StorageManagerImpl.java  |    7 +-
 2 files changed, 56 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c5185c09/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 a1b1336..841a535 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
@@ -154,6 +154,8 @@ import com.cloud.agent.api.storage.DestroyCommand;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
 import com.cloud.agent.api.to.FirewallRuleTO;
+import com.cloud.agent.api.storage.ResizeVolumeAnswer;
+import com.cloud.agent.api.storage.ResizeVolumeCommand;
 import com.cloud.agent.api.to.IpAddressTO;
 import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.PortForwardingRuleTO;
@@ -449,6 +451,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
                 answer = execute((Site2SiteVpnCfgCommand) cmd);
             } else if (clz == CheckS2SVpnConnectionsCommand.class) {
                 answer = execute((CheckS2SVpnConnectionsCommand) cmd);
+            } else if (clz == ResizeVolumeCommand.class) {
+                return execute((ResizeVolumeCommand) cmd);
             } else {
                 answer = Answer.createUnsupportedCommandAnswer(cmd);
             }
@@ -487,6 +491,54 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
 
         return answer;
     }
+    
+    private Answer execute(ResizeVolumeCommand cmd) {
+        String path = cmd.getPath();
+        String vmName = cmd.getInstanceName();
+        long newSize = cmd.getNewSize()/1024;
+
+        try {
+            VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
+            ManagedObjectReference morDc = hyperHost.getHyperHostDatacenter();
+            // find VM through datacenter (VM is not at the target host yet)
+            VirtualMachineMO vmMo = hyperHost.findVmOnPeerHyperHost(vmName);
+            if (vmMo == null) {
+                String msg = "VM " + vmName + " does not exist in VMware datacenter";
+                s_logger.error(msg);
+                throw new Exception(msg);
+            }
+
+            Pair<VirtualDisk, String> vdisk = vmMo.getDiskDevice(path, false);
+            if(vdisk == null) {
+                if(s_logger.isTraceEnabled())
+                    s_logger.trace("resize volume done (failed)");
+                throw new Exception("No such disk device: " + path);
+            }
+            VirtualDisk disk = vdisk.first();
+            long oldSize = disk.getCapacityInKB();
+            if (newSize < oldSize){
+                throw new Exception("VMware doesn't support shrinking volume from larger
size: " + oldSize+ " MB to a smaller size: " + newSize + " MB");
+            } else if(newSize == oldSize){
+                return new ResizeVolumeAnswer(cmd, true, "success", newSize*1024); 
+            }
+            disk.setCapacityInKB(newSize);
+
+            VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
+            VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
+            deviceConfigSpec.setDevice(disk);
+            deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);
+            vmConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[] { deviceConfigSpec
});
+            if (!vmMo.configureVm(vmConfigSpec)) {
+                throw new Exception("Failed to configure VM to resize disk. vmName: " + vmName);
+            }
+
+            return new ResizeVolumeAnswer(cmd, true, "success", newSize*1024);
+        } catch (Exception e) {
+            s_logger.error("Unable to resize volume",e);
+            String error = "failed to resize volume:"  +e;
+            return new ResizeVolumeAnswer(cmd, false, error );
+        }
+    }
 
     protected Answer execute(CheckNetworkCommand cmd) {
         if (s_logger.isInfoEnabled()) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c5185c09/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index 45e3a7f..05e0cfe 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -2043,10 +2043,11 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
             throw new InvalidParameterValueException("Can't resize a volume that has never
been attached, not sure which hypervisor type. Recreate volume to resize.");
         }
 
-        /* Only works for KVM/Xen for now */
+        /* Only works for KVM/Xen/VMware for now */
         if(_volsDao.getHypervisorType(volume.getId()) != HypervisorType.KVM 
-           && _volsDao.getHypervisorType(volume.getId()) != HypervisorType.XenServer){
-            throw new InvalidParameterValueException("Cloudstack currently only supports
volumes marked as KVM or XenServer hypervisor for resize");
+           && _volsDao.getHypervisorType(volume.getId()) != HypervisorType.XenServer
+           && _volsDao.getHypervisorType(volume.getId()) != HypervisorType.VMware){
+            throw new InvalidParameterValueException("Cloudstack currently only supports
volumes marked as KVM, XenServer or VMware hypervisor for resize");
         }
 
         if (volume == null) {


Mime
View raw message