cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [50/50] [abbrv] git commit: updated refs/heads/object_store to 342624e
Date Fri, 10 May 2013 23:33:33 GMT
Merged with head


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

Branch: refs/heads/object_store
Commit: 342624e0eb291f15061c74036e57f97af5efcca0
Parents: 30479293 47f6d65
Author: Alex Huang <alex.huang@gmail.com>
Authored: Fri May 10 16:33:57 2013 -0700
Committer: Alex Huang <alex.huang@gmail.com>
Committed: Fri May 10 16:33:57 2013 -0700

----------------------------------------------------------------------
 api/src/com/cloud/agent/api/to/DataObjectType.java |   25 +
 api/src/com/cloud/agent/api/to/DataTO.java         |   28 +
 api/src/com/cloud/agent/api/to/DiskTO.java         |   60 +
 .../com/cloud/agent/api/to/VirtualMachineTO.java   |    6 +-
 api/src/com/cloud/vm/VirtualMachineProfile.java    |    8 +-
 core/src/com/cloud/serializer/GsonHelper.java      |    2 +-
 .../cloud/storage/resource/StorageProcessor.java   |   45 +
 .../resource/StorageSubsystemCommandHandler.java   |   27 +
 .../StorageSubsystemCommandHandlerBase.java        |  135 ++
 .../storage/template/S3TemplateDownloader.java     |    6 +-
 .../engine/subsystem/api/storage/DataObject.java   |    2 +
 .../subsystem/api/storage/DataObjectType.java      |   25 -
 .../subsystem/api/storage/DataStoreDriver.java     |    1 +
 .../engine/subsystem/api/storage/DataTO.java       |   30 -
 .../subsystem/api/storage/SnapshotResult.java      |   16 +
 .../subsystem/api/storage/SnapshotStrategy.java    |   16 +
 .../cloudstack/storage/command/AttachAnswer.java   |   44 +
 .../cloudstack/storage/command/AttachCommand.java  |   52 +
 .../cloudstack/storage/command/CopyCmdAnswer.java  |    2 +-
 .../cloudstack/storage/command/CopyCommand.java    |    2 +-
 .../storage/command/CreateObjectAnswer.java        |    2 +-
 .../storage/command/CreateObjectCommand.java       |    2 +-
 .../cloudstack/storage/command/DeleteCommand.java  |    2 +-
 .../cloudstack/storage/command/DettachAnswer.java  |   44 +
 .../cloudstack/storage/command/DettachCommand.java |   52 +
 .../storage/datastore/db/ImageStoreDao.java        |    2 +-
 .../cloudstack/storage/to/PrimaryDataStoreTO.java  |   41 +
 .../cloudstack/storage/to/SnapshotObjectTO.java    |   20 +-
 .../cloudstack/storage/to/TemplateObjectTO.java    |   11 +-
 .../cloudstack/storage/to/VolumeObjectTO.java      |   30 +-
 .../storage/motion/AncientDataMotionStrategy.java  |    4 +-
 .../storage/image/TemplateDataFactoryImpl.java     |    2 +-
 .../storage/image/TemplateServiceImpl.java         |    4 +-
 .../manager/ImageStoreProviderManagerImpl.java     |    2 +-
 .../storage/image/store/TemplateObject.java        |    4 +-
 .../MockLocalNfsSecondaryStorageResource.java      |   16 +
 .../cloudstack/storage/test/S3TemplateTest.java    |   16 +
 .../cloudstack/storage/test/TemplateTest.java      |   16 +
 .../storage/snapshot/SnapshotObject.java           |    4 +-
 .../storage/snapshot/SnapshotStrategyBase.java     |   16 +
 .../snapshot/XenserverSnapshotStrategy.java        |   16 +
 .../cloudstack/storage/LocalHostEndpoint.java      |   16 +
 .../datastore/ObjectInDataStoreManager.java        |    2 +-
 .../datastore/ObjectInDataStoreManagerImpl.java    |    2 +-
 .../cloudstack/storage/db/ObjectInDataStoreVO.java |    2 +-
 .../storage/image/db/ImageStoreDaoImpl.java        |    9 +
 .../storage/datastore/PrimaryDataStoreImpl.java    |    2 +-
 .../cloudstack/storage/volume/VolumeObject.java    |    4 +-
 .../kvm/resource/LibvirtComputingResource.java     |  190 +--
 .../hypervisor/kvm/resource/LibvirtVMDef.java      |    6 +-
 .../kvm/storage/KVMStorageProcessor.java           |  879 +++++++++
 .../hypervisor/kvm/storage/KVMStorageResource.java |   87 +
 .../com/cloud/ovm/hypervisor/OvmResourceBase.java  |   26 +-
 .../hypervisor/vmware/resource/VmwareResource.java |  247 ++-
 .../VmwareSecondaryStorageResourceHandler.java     |   17 +-
 .../storage/resource/VmwareStorageProcessor.java   | 1160 ++++++++++++
 .../xen/resource/CitrixResourceBase.java           |   84 +-
 .../xen/resource/XenServer56FP1Resource.java       |   21 +-
 .../xen/resource/XenServerStorageProcessor.java    | 1404 +++++++++++++++
 .../xen/resource/XenServerStorageResource.java     | 1327 --------------
 .../driver/CloudStackImageStoreDriverImpl.java     |    4 +-
 .../datastore/driver/S3ImageStoreDriverImpl.java   |    4 +-
 .../driver/SampleImageStoreDriverImpl.java         |    4 +-
 .../driver/SwiftImageStoreDriverImpl.java          |    4 +-
 .../CloudStackPrimaryDataStoreDriverImpl.java      |    4 +-
 .../driver/SamplePrimaryDataStoreDriverImpl.java   |    2 +-
 .../driver/SolidfirePrimaryDataStoreDriver.java    |    2 +-
 .../src/com/cloud/api/query/QueryManagerImpl.java  |    3 +
 .../com/cloud/api/query/vo/ImageStoreJoinVO.java   |   11 +
 .../com/cloud/hypervisor/HypervisorGuruBase.java   |    4 +-
 .../com/cloud/storage/CreateSnapshotPayload.java   |   16 +
 .../src/com/cloud/storage/VolumeManagerImpl.java   |  173 +-
 .../cloud/storage/download/DownloadListener.java   |   37 +-
 .../com/cloud/template/TemplateManagerImpl.java    |   37 +-
 server/src/com/cloud/vm/UserVmManagerImpl.java     |   64 +-
 .../com/cloud/vm/VirtualMachineProfileImpl.java    |   11 +-
 .../resource/NfsSecondaryStorageResource.java      |    4 +-
 .../storage/template/DownloadManagerImpl.java      |   59 +-
 setup/db/db/schema-410to420.sql                    |    8 +-
 tools/devcloud/devcloud_s3.cfg                     |    2 +-
 80 files changed, 4865 insertions(+), 1911 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
----------------------------------------------------------------------
diff --cc engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
index f27f1c9,4e9b02b..786eeb3
--- a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
+++ b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
@@@ -28,10 -26,9 +28,8 @@@ import org.springframework.stereotype.C
  import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionStrategy;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
- import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
- import org.apache.cloudstack.engine.subsystem.api.storage.DataTO;
 -
  import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
  import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
  import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
@@@ -41,13 -38,33 +39,15 @@@ import org.apache.cloudstack.framework.
  import org.apache.cloudstack.storage.command.CopyCommand;
  import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
  import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
 -import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
 -import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
  import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 -import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
  import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
 -import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
 -import org.apache.log4j.Logger;
 -import org.springframework.stereotype.Component;
  
  import com.cloud.agent.api.Answer;
 -import com.cloud.agent.api.BackupSnapshotAnswer;
 -import com.cloud.agent.api.BackupSnapshotCommand;
 -import com.cloud.agent.api.Command;
 -import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
 -import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
 -import com.cloud.agent.api.CreateVolumeFromSnapshotAnswer;
 -import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
 -import com.cloud.agent.api.UpgradeSnapshotCommand;
 -import com.cloud.agent.api.storage.CopyVolumeAnswer;
 -import com.cloud.agent.api.storage.CopyVolumeCommand;
 -import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
+ import com.cloud.agent.api.to.DataObjectType;
  import com.cloud.agent.api.to.DataStoreTO;
+ import com.cloud.agent.api.to.DataTO;
  import com.cloud.agent.api.to.NfsTO;
 -import com.cloud.agent.api.to.S3TO;
 -import com.cloud.agent.api.to.SwiftTO;
 +import com.cloud.agent.api.to.VirtualMachineTO;
  import com.cloud.configuration.Config;
  import com.cloud.configuration.dao.ConfigurationDao;
  import com.cloud.exception.StorageUnavailableException;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/engine/storage/integration-test/test/org/apache/cloudstack/storage/MockLocalNfsSecondaryStorageResource.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/engine/storage/src/org/apache/cloudstack/storage/LocalHostEndpoint.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --cc plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 6c1f76a,48b3b32..017e4e9
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@@ -327,6 -336,10 +342,10 @@@ public class VmwareResource implements 
          s_statesTable.put(VirtualMachinePowerState.POWERED_OFF, State.Stopped);
          s_statesTable.put(VirtualMachinePowerState.SUSPENDED, State.Stopped);
      }
+     
+     public Gson getGson() {
 -    	return this._gson;
++    	return _gson;
+     }
  
      public VmwareResource() {
          _gson = GsonHelper.getGsonLogger();
@@@ -482,8 -491,8 +501,10 @@@
                  answer = execute((CheckS2SVpnConnectionsCommand) cmd);
              } else if (clz == ResizeVolumeCommand.class) {
                  return execute((ResizeVolumeCommand) cmd);
 +            } else if (clz == UnregisterVMCommand.class) {
 +                return execute((UnregisterVMCommand) cmd);
+             } else if (cmd instanceof StorageSubSystemCommand) {
 -            	return this.storageHandler.handleStorageCommands((StorageSubSystemCommand)cmd);
++            	return storageHandler.handleStorageCommands((StorageSubSystemCommand)cmd);
              } else {
                  answer = Answer.createUnsupportedCommandAnswer(cmd);
              }
@@@ -1430,7 -1439,7 +1451,7 @@@
  
          VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
  
--        int ethDeviceNum = this.findRouterEthDeviceIndex(domrName, routerIp, ip.getVifMacAddress());
++        int ethDeviceNum = findRouterEthDeviceIndex(domrName, routerIp, ip.getVifMacAddress());
          if (ethDeviceNum < 0) {
              if (ip.isAdd()) {
                  throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with.");
@@@ -1597,11 -1587,11 +1618,11 @@@
              vSwitchType = _publicTrafficInfo.getVirtualSwitchType();
          }
          if (VirtualSwitchType.StandardVirtualSwitch == vSwitchType) {
--            networkInfo = HypervisorHostHelper.prepareNetwork(this._publicTrafficInfo.getVirtualSwitchName(), "cloud.public",
--                    vmMo.getRunningHost(), vlanId, null, null, this._ops_timeout, true);
++            networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public",
++                    vmMo.getRunningHost(), vlanId, null, null, _ops_timeout, true);
          } else {
--            networkInfo = HypervisorHostHelper.prepareNetwork(this._publicTrafficInfo.getVirtualSwitchName(), "cloud.public",
-                     vmMo.getRunningHost(), vlanId, null, null, this._ops_timeout, vSwitchType, _portsPerDvPortGroup, null, false);
 -                    vmMo.getRunningHost(), vlanId, null, null, this._ops_timeout, vSwitchType, _portsPerDvPortGroup);
++            networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public",
++                    vmMo.getRunningHost(), vlanId, null, null, _ops_timeout, vSwitchType, _portsPerDvPortGroup, null, false);
          }
  
          int nicIndex = allocPublicNicIndex(vmMo);
@@@ -2178,23 -2176,6 +2207,23 @@@
              VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(),
              vmSpec.getMinSpeed(),(int) (vmSpec.getMaxRam()/(1024*1024)), ramMb,
              translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), vmSpec.getLimitCpuUse());
 +           
 +            if ("true".equals(vmSpec.getDetails().get(VmDetailConstants.NESTED_VIRTUALIZATION_FLAG))) {
 +                s_logger.debug("Nested Virtualization enabled in configuration, checking hypervisor capability");
 +                ManagedObjectReference hostMor = vmMo.getRunningHost().getMor();
 +                ManagedObjectReference computeMor = context.getVimClient().getMoRefProp(hostMor, "parent");
-                 ManagedObjectReference environmentBrowser = 
++                ManagedObjectReference environmentBrowser =
 +                        context.getVimClient().getMoRefProp(computeMor, "environmentBrowser");
 +                HostCapability hostCapability = context.getService().queryTargetCapabilities(environmentBrowser, hostMor);
 +                if (hostCapability.isNestedHVSupported()) {
 +                    s_logger.debug("Hypervisor supports nested virtualization, enabling for VM " + vmSpec.getName());
-                     vmConfigSpec.setNestedHVEnabled(true);                   
++                    vmConfigSpec.setNestedHVEnabled(true);
 +                }
 +                else {
 +                	s_logger.warn("Hypervisor doesn't support nested virtualization, unable to set config for VM " +vmSpec.getName());
 +                	vmConfigSpec.setNestedHVEnabled(false);
 +                }
 +            }
  
              VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[totalChangeDevices];
              int i = 0;
@@@ -2586,13 -2582,13 +2631,13 @@@
          }
  
          if (nicTo.getType() == Networks.TrafficType.Guest) {
--            return new Pair<String, String>(this._guestTrafficInfo.getVirtualSwitchName(), Vlan.UNTAGGED);
++            return new Pair<String, String>(_guestTrafficInfo.getVirtualSwitchName(), Vlan.UNTAGGED);
          } else if (nicTo.getType() == Networks.TrafficType.Control || nicTo.getType() == Networks.TrafficType.Management) {
--            return new Pair<String, String>(this._privateNetworkVSwitchName, Vlan.UNTAGGED);
++            return new Pair<String, String>(_privateNetworkVSwitchName, Vlan.UNTAGGED);
          } else if (nicTo.getType() == Networks.TrafficType.Public) {
--            return new Pair<String, String>(this._publicTrafficInfo.getVirtualSwitchName(), Vlan.UNTAGGED);
++            return new Pair<String, String>(_publicTrafficInfo.getVirtualSwitchName(), Vlan.UNTAGGED);
          } else if (nicTo.getType() == Networks.TrafficType.Storage) {
--            return new Pair<String, String>(this._privateNetworkVSwitchName, Vlan.UNTAGGED);
++            return new Pair<String, String>(_privateNetworkVSwitchName, Vlan.UNTAGGED);
          } else if (nicTo.getType() == Networks.TrafficType.Vpn) {
              throw new Exception("Unsupported traffic type: " + nicTo.getType().toString());
          } else {
@@@ -3715,51 -3715,14 +3760,50 @@@
          }
      }
  
 -    
 +    protected Answer execute(UnregisterVMCommand cmd){
 +        if (s_logger.isInfoEnabled()) {
 +            s_logger.info("Executing resource UnregisterVMCommand: " + _gson.toJson(cmd));
 +        }
 +
 +        VmwareContext context = getServiceContext();
 +        VmwareHypervisorHost hyperHost = getHyperHost(context);
 +        try {
 +            VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
 +            if (vmMo != null) {
 +                try {
 +                    context.getService().unregisterVM(vmMo.getMor());
 +                    return new Answer(cmd, true, "unregister succeeded");
 +                } catch(Exception e) {
 +                    s_logger.warn("We are not able to unregister VM " + VmwareHelper.getExceptionMessage(e));
 +                }
 +
 +                String msg = "Expunge failed in vSphere. vm: " + cmd.getVmName();
 +                s_logger.warn(msg);
 +                return new Answer(cmd, false, msg);
 +            } else {
 +                String msg = "Unable to find the VM in vSphere to unregister, assume it is already removed. VM: " + cmd.getVmName();
 +                s_logger.warn(msg);
 +                return new Answer(cmd, true, msg);
 +            }
 +        } catch (Exception e) {
 +            if (e instanceof RemoteException) {
 +                s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
 +                invalidateServiceContext();
 +            }
 +
 +            String msg = "UnregisterVMCommand failed due to " + VmwareHelper.getExceptionMessage(e);
 +            s_logger.error(msg);
 +            return new Answer(cmd, false, msg);
 +        }
 +    }
 +
-     @Override
-     public Answer execute(DestroyCommand cmd) {
+     public Answer execute(DeleteCommand cmd) {
          if (s_logger.isInfoEnabled()) {
              s_logger.info("Executing resource DestroyCommand: " + _gson.toJson(cmd));
          }
  
          /*
--         * DestroyCommand content example
++         * DestroyCommand content exafmple
           *
           * {"volume": {"id":5,"name":"Volume1", "mountPoint":"/export/home/kelven/vmware-test/primary",
           * "path":"6bb8762f-c34c-453c-8e03-26cc246ceec4", "size":0,"type":"DATADISK","resourceType":
@@@ -3932,48 -3896,8 +3977,49 @@@
          }
      }
  
++    @Override
 +    public CreateVolumeOVAAnswer execute(CreateVolumeOVACommand cmd) {
 +        if (s_logger.isInfoEnabled()) {
 +            s_logger.info("Executing resource CreateVolumeOVACommand: " + _gson.toJson(cmd));
 +        }
 +
 +        try {
 +            VmwareContext context = getServiceContext();
 +            VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
 +            return (CreateVolumeOVAAnswer) mgr.getStorageManager().execute(this, cmd);
 +        } catch (Throwable e) {
 +            if (e instanceof RemoteException) {
 +                s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
 +                invalidateServiceContext();
 +            }
 +
 +            String msg = "CreateVolumeOVACommand failed due to " + VmwareHelper.getExceptionMessage(e);
 +            s_logger.error(msg, e);
 +            return new CreateVolumeOVAAnswer(cmd, false, msg);
 +        }
 +    }
 +
 +    protected Answer execute(PrepareOVAPackingCommand cmd) {
 +        if (s_logger.isInfoEnabled()) {
 +            s_logger.info("Executing resource PrepareOVAPackingCommand: " + _gson.toJson(cmd));
 +        }
 +
 +        try {
 +            VmwareContext context = getServiceContext();
 +            VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
  
 +            return mgr.getStorageManager().execute(this, cmd);
 +        } catch (Throwable e) {
 +            if (e instanceof RemoteException) {
 +                s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
 +                invalidateServiceContext();
 +            }
  
 +            String details = "PrepareOVAPacking for template failed due to " + VmwareHelper.getExceptionMessage(e);
 +            s_logger.error(details, e);
 +            return new PrepareOVAPackingAnswer(cmd, false, details);
 +        }
 +    }
      private boolean createVMFullClone(VirtualMachineMO vmTemplate, DatacenterMO dcMo, DatastoreMO dsMo,
              String vmdkName, ManagedObjectReference morDatastore, ManagedObjectReference morPool) throws Exception {
  
@@@ -4688,8 -4612,8 +4734,8 @@@
                      if(!"untagged".equalsIgnoreCase(tokens[2]))
                          vlanId = tokens[2];
  
--                    HypervisorHostHelper.prepareNetwork(this._privateNetworkVSwitchName, "cloud.private",
--                            hostMo, vlanId, networkRateMbps, null, this._ops_timeout, false);
++                    HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private",
++                            hostMo, vlanId, networkRateMbps, null, _ops_timeout, false);
                  } else {
                      s_logger.info("Skip suspecious cloud network " + networkName);
                  }
@@@ -4705,7 -4629,7 +4751,7 @@@
                          vlanId = tokens[2];
  
                      HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public",
--                            hostMo, vlanId, networkRateMbps, null, this._ops_timeout, false);
++                            hostMo, vlanId, networkRateMbps, null, _ops_timeout, false);
                  } else {
                      s_logger.info("Skip suspecious cloud network " + networkName);
                  }
@@@ -4722,7 -4646,7 +4768,7 @@@
                          vlanId = tokens[2];
  
                      HypervisorHostHelper.prepareNetwork(_guestTrafficInfo.getVirtualSwitchName(), "cloud.guest",
--                            hostMo, vlanId, networkRateMbps, null, this._ops_timeout, false);
++                            hostMo, vlanId, networkRateMbps, null, _ops_timeout, false);
                  } else {
                      s_logger.info("Skip suspecious cloud network " + networkName);
                  }
@@@ -5103,9 -5027,9 +5149,9 @@@
  
          s_logger.info("VmwareResource network configuration info." +
                  " private traffic over vSwitch: " + _privateNetworkVSwitchName + ", public traffic over " +
--                this._publicTrafficInfo.getVirtualSwitchType() + " : " + this._publicTrafficInfo.getVirtualSwitchName() +
--                ", guest traffic over " + this._guestTrafficInfo.getVirtualSwitchType() + " : " +
--                this._guestTrafficInfo.getVirtualSwitchName());
++                _publicTrafficInfo.getVirtualSwitchType() + " : " + _publicTrafficInfo.getVirtualSwitchName() +
++                ", guest traffic over " + _guestTrafficInfo.getVirtualSwitchType() + " : " +
++                _guestTrafficInfo.getVirtualSwitchName());
  
          value = params.get("vmware.create.full.clone").toString();
          if (value != null && value.equalsIgnoreCase("true")) {
@@@ -5113,6 -5037,13 +5159,13 @@@
          } else {
              _fullCloneFlag = false;
          }
+         value = (String)params.get("scripts.timeout");
+         int timeout = NumbersUtil.parseInt(value, 1440) * 1000;
+         VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
 -        VmwareStorageProcessor storageProcessor = new VmwareStorageProcessor((VmwareHostService)this, this._fullCloneFlag, (VmwareStorageMount)mgr,
 -        		timeout, this, this._shutdown_waitMs
++        VmwareStorageProcessor storageProcessor = new VmwareStorageProcessor((VmwareHostService)this, _fullCloneFlag, (VmwareStorageMount)mgr,
++        		timeout, this, _shutdown_waitMs
+         		);
+         storageHandler = new StorageSubsystemCommandHandlerBase(storageProcessor);
  
          return true;
      }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
----------------------------------------------------------------------
diff --cc plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
index 95ba317,645b6d3..4d04ffe
--- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
@@@ -18,9 -18,9 +18,14 @@@ package com.cloud.storage.resource
  
  import java.util.List;
  
- import org.apache.cloudstack.storage.resource.SecondaryStorageResourceHandler;
 -import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
  import org.apache.log4j.Logger;
  
++import com.google.gson.Gson;
++import com.vmware.vim25.ManagedObjectReference;
++
++import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
++import org.apache.cloudstack.storage.resource.SecondaryStorageResourceHandler;
++
  import com.cloud.agent.api.Answer;
  import com.cloud.agent.api.BackupSnapshotCommand;
  import com.cloud.agent.api.Command;
@@@ -45,8 -43,8 +50,6 @@@ import com.cloud.hypervisor.vmware.util
  import com.cloud.hypervisor.vmware.util.VmwareHelper;
  import com.cloud.serializer.GsonHelper;
  import com.cloud.utils.Pair;
--import com.google.gson.Gson;
--import com.vmware.vim25.ManagedObjectReference;
  
  public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageResourceHandler, VmwareHostService, VmwareStorageMount {
      private static final Logger s_logger = Logger.getLogger(VmwareSecondaryStorageResourceHandler.class);
@@@ -55,6 -53,7 +58,7 @@@
      private final VmwareStorageManager _storageMgr;
  
      private final Gson _gson;
 -    private StorageSubsystemCommandHandler storageSubsystemHandler;
++    private final StorageSubsystemCommandHandler storageSubsystemHandler;
  
      /*
  	private Map<String, HostMO> _activeHosts = new HashMap<String, HostMO>();
@@@ -64,6 -63,11 +68,11 @@@
          _resource = resource;
          _storageMgr = new VmwareStorageManagerImpl(this);
          _gson = GsonHelper.getGsonLogger();
+       
 -        VmwareStorageProcessor storageProcessor = new VmwareStorageProcessor((VmwareHostService)this, true, (VmwareStorageMount)this,
++        VmwareStorageProcessor storageProcessor = new VmwareStorageProcessor(this, true, this,
+         		null, null, null
+         		);
+         storageSubsystemHandler = new StorageSubsystemCommandHandlerBase(storageProcessor);
      }
  
      @Override
@@@ -79,12 -83,10 +88,14 @@@
              answer = execute((CreatePrivateTemplateFromSnapshotCommand)cmd);
          } else if(cmd instanceof CopyVolumeCommand) {
              answer = execute((CopyVolumeCommand)cmd);
 +        } else if(cmd instanceof CreateVolumeOVACommand) {
 +            answer = execute((CreateVolumeOVACommand)cmd);
 +        } else if (cmd instanceof PrepareOVAPackingCommand) {
 +            answer = execute((PrepareOVAPackingCommand)cmd);
          } else if(cmd instanceof CreateVolumeFromSnapshotCommand) {
              answer = execute((CreateVolumeFromSnapshotCommand)cmd);
+         } else if (cmd instanceof StorageSubSystemCommand) {
+         	answer = storageSubsystemHandler.handleStorageCommands((StorageSubSystemCommand)cmd);
          } else {
              answer =  _resource.defaultAction(cmd);
          }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --cc plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
index c0675e7,52f8d9c..177d8d8
--- a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
+++ b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
@@@ -29,12 -27,11 +29,10 @@@ import org.apache.log4j.Logger
  import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
  import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
- import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
- import org.apache.cloudstack.engine.subsystem.api.storage.DataTO;
  import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
  import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 -import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
  import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
  import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
  import org.apache.cloudstack.framework.async.AsyncRpcConext;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --cc plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
index 87eb14a,1992c5e..29cafdb
--- a/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
+++ b/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
@@@ -31,12 -29,11 +31,10 @@@ import org.apache.cloudstack.api.ApiCon
  import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
  import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
- import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
- import org.apache.cloudstack.engine.subsystem.api.storage.DataTO;
  import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
  import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 -import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
  import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
  import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
  import org.apache.cloudstack.framework.async.AsyncRpcConext;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/server/src/com/cloud/api/query/QueryManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/server/src/com/cloud/hypervisor/HypervisorGuruBase.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/server/src/com/cloud/storage/VolumeManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/VolumeManagerImpl.java
index 2e13866,17e0e09..9799d85
--- a/server/src/com/cloud/storage/VolumeManagerImpl.java
+++ b/server/src/com/cloud/storage/VolumeManagerImpl.java
@@@ -25,6 -25,6 +25,7 @@@ import java.net.URISyntaxException
  import java.net.UnknownHostException;
  import java.util.ArrayList;
  import java.util.Date;
++import java.util.HashMap;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Map;
@@@ -36,6 -35,6 +36,9 @@@ import java.util.concurrent.ExecutionEx
  import javax.inject.Inject;
  import javax.naming.ConfigurationException;
  
++import org.apache.log4j.Logger;
++import org.springframework.stereotype.Component;
++
  import org.apache.cloudstack.api.BaseCmd;
  import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
  import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
@@@ -59,21 -57,24 +61,22 @@@ import org.apache.cloudstack.engine.sub
  import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
  import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult;
  import org.apache.cloudstack.framework.async.AsyncCallFuture;
+ import org.apache.cloudstack.storage.command.AttachAnswer;
+ import org.apache.cloudstack.storage.command.AttachCommand;
 -import org.apache.cloudstack.storage.command.DettachAnswer;
++import org.apache.cloudstack.storage.command.CommandResult;
+ import org.apache.cloudstack.storage.command.DettachCommand;
  import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
  import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
  import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
  import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
  import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
  import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
  
  import com.cloud.agent.AgentManager;
  import com.cloud.agent.api.Answer;
--import com.cloud.agent.api.AttachVolumeAnswer;
- import com.cloud.agent.api.AttachVolumeCommand;
+ import com.cloud.agent.api.to.DataTO;
+ import com.cloud.agent.api.to.DiskTO;
 +import com.cloud.agent.api.to.VirtualMachineTO;
- import com.cloud.agent.api.to.VolumeTO;
  import com.cloud.alert.AlertManager;
  import com.cloud.api.ApiDBUtils;
  import com.cloud.async.AsyncJobExecutor;
@@@ -112,9 -112,8 +115,9 @@@ import com.cloud.host.Host
  import com.cloud.host.HostVO;
  import com.cloud.host.dao.HostDao;
  import com.cloud.hypervisor.Hypervisor.HypervisorType;
++import com.cloud.hypervisor.HypervisorCapabilitiesVO;
  import com.cloud.hypervisor.HypervisorGuruManager;
  import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
- import com.cloud.hypervisor.HypervisorCapabilitiesVO;
  import com.cloud.network.NetworkModel;
  import com.cloud.org.Grouping;
  import com.cloud.resource.ResourceManager;
@@@ -322,7 -319,7 +323,7 @@@ public class VolumeManagerImpl extends 
      @Inject
      StorageManager storageMgr;
      private int _customDiskOfferingMinSize = 1;
--    private int _customDiskOfferingMaxSize = 1024;
++    private final int _customDiskOfferingMaxSize = 1024;
      private long _maxVolumeSizeInGb;
      private boolean _recreateSystemVmEnabled;
  
@@@ -358,7 -355,7 +359,7 @@@
          }
  
          Volume newVol = migrateVolume(volume, destPool);
--        return this.volFactory.getVolume(newVol.getId());
++        return volFactory.getVolume(newVol.getId());
      }
  
      /*
@@@ -376,20 -373,20 +377,20 @@@
          String url = cmd.getUrl();
          String format = cmd.getFormat();
          String imageStoreUuid = cmd.getImageStoreUuid();
--        DataStore store = this._tmpltMgr.getImageStore(imageStoreUuid, zoneId);
++        DataStore store = _tmpltMgr.getImageStore(imageStoreUuid, zoneId);
  
          validateVolume(caller, ownerId, zoneId, volumeName, url, format);
  
          VolumeVO volume = persistVolume(caller, ownerId, zoneId, volumeName,
                  url, cmd.getFormat());
  
--        VolumeInfo vol = this.volFactory.getVolume(volume.getId());
++        VolumeInfo vol = volFactory.getVolume(volume.getId());
  
          RegisterVolumePayload payload = new RegisterVolumePayload(cmd.getUrl(), cmd.getChecksum(),
                  cmd.getFormat());
          vol.addPayload(payload);
  
--        this.volService.registerVolume(vol, store);
++        volService.registerVolume(vol, store);
          return volume;
      }
  
@@@ -532,10 -529,10 +533,10 @@@
              }
          }
  
--        VolumeInfo vol = this.volFactory.getVolume(volume.getId());
--        DataStore store = this.dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
--        SnapshotInfo snapInfo = this.snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Image);
--        AsyncCallFuture<VolumeApiResult> future = this.volService.createVolumeFromSnapshot(vol, store, snapInfo);
++        VolumeInfo vol = volFactory.getVolume(volume.getId());
++        DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
++        SnapshotInfo snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Image);
++        AsyncCallFuture<VolumeApiResult> future = volService.createVolumeFromSnapshot(vol, store, snapInfo);
          try {
              VolumeApiResult result = future.get();
              if (result.isFailed()) {
@@@ -557,7 -554,7 +558,7 @@@
              VMTemplateVO template, DataCenterVO dc, DiskOfferingVO diskOffering) {
          if (volume.getVolumeType() == Type.ROOT
                  && Storage.ImageFormat.ISO != template.getFormat()) {
--            TemplateDataStoreVO ss = this._vmTemplateStoreDao.findByTemplateZoneDownloadStatus(template.getId(), dc.getId(),
++            TemplateDataStoreVO ss = _vmTemplateStoreDao.findByTemplateZoneDownloadStatus(template.getId(), dc.getId(),
                      VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
              if (ss == null) {
                  throw new CloudRuntimeException("Template "
@@@ -596,7 -593,7 +597,7 @@@
                  null, createdVolume.getSize());
          _usageEventDao.persist(usageEvent);
  
--        return this._volsDao.findById(createdVolume.getId());
++        return _volsDao.findById(createdVolume.getId());
      }
  
      @DB
@@@ -614,8 -611,8 +615,8 @@@
          // Find a suitable storage to create volume on
          StoragePool destPool = storageMgr.findStoragePool(dskCh, dc, pod,
                  clusterId, null, vm, avoidPools);
--        DataStore destStore = this.dataStoreMgr.getDataStore(destPool.getId(), DataStoreRole.Primary);
--        AsyncCallFuture<VolumeApiResult> future = this.volService.copyVolume(volume, destStore);
++        DataStore destStore = dataStoreMgr.getDataStore(destPool.getId(), DataStoreRole.Primary);
++        AsyncCallFuture<VolumeApiResult> future = volService.copyVolume(volume, destStore);
  
          try {
              VolumeApiResult result = future.get();
@@@ -670,14 -667,14 +671,14 @@@
          if (s_logger.isDebugEnabled()) {
              s_logger.debug("Trying to create " + volume + " on " + pool);
          }
--        DataStore store = this.dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
++        DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
          AsyncCallFuture<VolumeApiResult> future = null;
          boolean isNotCreatedFromTemplate = volume.getTemplateId() == null ? true : false;
          if (isNotCreatedFromTemplate) {
--            future = this.volService.createVolumeAsync(volume, store);
++            future = volService.createVolumeAsync(volume, store);
          } else {
--            TemplateInfo templ = this.tmplFactory.getTemplate(template.getId(), DataStoreRole.Image);
--            future = this.volService.createVolumeFromTemplateAsync(volume, store.getId(), templ);
++            TemplateInfo templ = tmplFactory.getTemplate(template.getId(), DataStoreRole.Image);
++            future = volService.createVolumeFromTemplateAsync(volume, store.getId(), templ);
          }
          try {
              VolumeApiResult result = future.get();
@@@ -1147,7 -1144,7 +1148,7 @@@
  
          UserVmVO userVm = _userVmDao.findById(volume.getInstanceId());
  
--        PrimaryDataStoreInfo pool = (PrimaryDataStoreInfo)this.dataStoreMgr.getDataStore(volume.getPoolId(), DataStoreRole.Primary);
++        PrimaryDataStoreInfo pool = (PrimaryDataStoreInfo)dataStoreMgr.getDataStore(volume.getPoolId(), DataStoreRole.Primary);
          long currentSize = volume.getSize();
  
          /*
@@@ -1198,10 -1195,10 +1199,10 @@@
          ResizeVolumePayload payload = new ResizeVolumePayload(newSize, shrinkOk, instanceName, hosts);
  
          try {
--            VolumeInfo vol = this.volFactory.getVolume(volume.getId());
++            VolumeInfo vol = volFactory.getVolume(volume.getId());
              vol.addPayload(payload);
  
--            AsyncCallFuture<VolumeApiResult> future = this.volService.resize(vol);
++            AsyncCallFuture<VolumeApiResult> future = volService.resize(vol);
              future.get();
              volume = _volsDao.findById(volume.getId());
  
@@@ -1266,11 -1263,11 +1267,11 @@@
          try {
              if (volume.getState() != Volume.State.Destroy && volume.getState() != Volume.State.Expunging && volume.getState() != Volume.State.Expunging) {
                  Long instanceId = volume.getInstanceId();
--                if (!this.volService.destroyVolume(volume.getId())) {
++                if (!volService.destroyVolume(volume.getId())) {
                      return false;
                  }
  
--                VMInstanceVO vmInstance = this._vmInstanceDao.findById(instanceId);
++                VMInstanceVO vmInstance = _vmInstanceDao.findById(instanceId);
                  if (instanceId == null
                          || (vmInstance.getType().equals(VirtualMachine.Type.User))) {
                      // Decrement the resource count for volumes and primary storage belonging user VM's only
@@@ -1293,7 -1290,7 +1294,7 @@@
                      _usageEventDao.persist(usageEvent);
                  }
              }
--            AsyncCallFuture<VolumeApiResult> future = this.volService.expungeVolumeAsync(this.volFactory.getVolume(volume.getId()));
++            AsyncCallFuture<VolumeApiResult> future = volService.expungeVolumeAsync(volFactory.getVolume(volume.getId()));
              future.get();
  
          } catch (Exception e) {
@@@ -1369,7 -1366,7 +1370,7 @@@
              VMTemplateVO template, VMInstanceVO vm, Account owner) {
          assert (template.getFormat() != ImageFormat.ISO) : "ISO is not a template really....";
  
--        Long size = this._tmpltMgr.getTemplateSize(template.getId(), vm.getDataCenterId());
++        Long size = _tmpltMgr.getTemplateSize(template.getId(), vm.getDataCenterId());
  
          VolumeVO vol = new VolumeVO(type, name, vm.getDataCenterId(),
                  owner.getDomainId(), owner.getId(), offering.getId(), size);
@@@ -1491,8 -1488,8 +1492,8 @@@
      }
  
      private boolean needMoveVolume(VolumeVO rootVolumeOfVm, VolumeInfo volume) {
--        DataStore storeForRootVol = this.dataStoreMgr.getPrimaryDataStore(rootVolumeOfVm.getPoolId());
--        DataStore storeForDataVol = this.dataStoreMgr.getPrimaryDataStore(volume.getPoolId());
++        DataStore storeForRootVol = dataStoreMgr.getPrimaryDataStore(rootVolumeOfVm.getPoolId());
++        DataStore storeForDataVol = dataStoreMgr.getPrimaryDataStore(volume.getPoolId());
  
          Scope storeForRootStoreScope = storeForRootVol.getScope();
          if (storeForRootStoreScope == null) {
@@@ -1531,16 -1528,11 +1532,11 @@@
          }
  
          if (sendCommand) {
-             StoragePoolVO volumePool = _storagePoolDao.findById(volume
-                     .getPoolId());
-             AttachVolumeCommand cmd = new AttachVolumeCommand(true,
-                     vm.getInstanceName(), volume.getPoolType(),
-                     volume.getFolder(), volume.getPath(), volume.getName(),
-                     deviceId, volume.getChainInfo());
-             cmd.setPoolUuid(volumePool.getUuid());
- 
 -            DataTO volTO = this.volFactory.getVolume(volume.getId()).getTO();
++            DataTO volTO = volFactory.getVolume(volume.getId()).getTO();
+             DiskTO disk = new DiskTO(volTO, deviceId, volume.getVolumeType());
+             AttachCommand cmd = new AttachCommand(disk, vm.getInstanceName());
              try {
-                 answer = (AttachVolumeAnswer) _agentMgr.send(hostId, cmd);
+                 answer = (AttachAnswer) _agentMgr.send(hostId, cmd);
              } catch (Exception e) {
                  throw new CloudRuntimeException(errorMsg + " due to: "
                          + e.getMessage());
@@@ -1826,7 -1819,7 +1823,7 @@@
          }
  
          // Check that the VM is in the correct state
--        UserVmVO vm = this._userVmDao.findById(vmId);
++        UserVmVO vm = _userVmDao.findById(vmId);
          if (vm.getState() != State.Running && vm.getState() != State.Stopped
                  && vm.getState() != State.Destroyed) {
              throw new InvalidParameterValueException(
@@@ -1863,16 -1856,9 +1860,9 @@@
          Answer answer = null;
  
          if (sendCommand) {
-             AttachVolumeCommand cmd = new AttachVolumeCommand(false,
-                     vm.getInstanceName(), volume.getPoolType(),
-                     volume.getFolder(), volume.getPath(), volume.getName(),
-                     cmmd.getDeviceId() != null ? cmmd.getDeviceId() : volume
-                             .getDeviceId(), volume.getChainInfo());
- 
-             StoragePoolVO volumePool = _storagePoolDao.findById(volume
-                     .getPoolId());
-             cmd.setPoolUuid(volumePool.getUuid());
- 
 -            DataTO volTO = this.volFactory.getVolume(volume.getId()).getTO();
++            DataTO volTO = volFactory.getVolume(volume.getId()).getTO();
+             DiskTO disk = new DiskTO(volTO, volume.getDeviceId(), volume.getVolumeType());
+             DettachCommand cmd = new DettachCommand(disk, vm.getInstanceName());
              try {
                  answer = _agentMgr.send(vm.getHostId(), cmd);
              } catch (Exception e) {
@@@ -1970,7 -1950,7 +1954,7 @@@
                  // This check is for VM in Error state (volume is already
                  // destroyed)
                  if (!vol.getState().equals(Volume.State.Destroy)) {
--                    this.volService.destroyVolume(vol.getId());
++                    volService.destroyVolume(vol.getId());
                  }
                  toBeExpunged.add(vol);
              } else {
@@@ -1983,7 -1963,7 +1967,7 @@@
          txn.commit();
          AsyncCallFuture<VolumeApiResult> future = null;
          for (VolumeVO expunge : toBeExpunged) {
--            future = this.volService.expungeVolumeAsync(this.volFactory.getVolume(expunge.getId()));
++            future = volService.expungeVolumeAsync(volFactory.getVolume(expunge.getId()));
              try {
                  future.get();
              } catch (InterruptedException e) {
@@@ -2011,42 -1991,12 +1995,42 @@@
                      "Volume must be in ready state");
          }
  
 -        if (vol.getInstanceId() != null) {
 -            throw new InvalidParameterValueException(
 -                    "Volume needs to be dettached from VM");
 +        boolean liveMigrateVolume = false;
 +        Long instanceId = vol.getInstanceId();
 +        VMInstanceVO vm = null;
 +        if (instanceId != null) {
 +            vm = _vmInstanceDao.findById(instanceId);
 +        }
 +
 +        if (vm != null && vm.getState() == State.Running) {
 +            // Check if the underlying hypervisor supports storage motion.
 +            Long hostId = vm.getHostId();
 +            if (hostId != null) {
 +                HostVO host = _hostDao.findById(hostId);
 +                HypervisorCapabilitiesVO capabilities = null;
 +                if (host != null) {
 +                    capabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(host.getHypervisorType(),
 +                            host.getHypervisorVersion());
 +                }
 +
 +                if (capabilities != null) {
 +                    liveMigrateVolume = capabilities.isStorageMotionSupported();
 +                }
 +            }
 +        }
 +
 +        // If the disk is not attached to any VM then it can be moved. Otherwise, it needs to be attached to a vm
 +        // running on a hypervisor that supports storage motion so that it be be migrated.
 +        if (instanceId != null && !liveMigrateVolume) {
 +            throw new InvalidParameterValueException("Volume needs to be detached from VM");
 +        }
 +
 +        if (liveMigrateVolume && !cmd.isLiveMigrate()) {
 +            throw new InvalidParameterValueException("The volume " + vol + "is attached to a vm and for migrating it " +
 +                    "the parameter livemigrate should be specified");
          }
  
--        StoragePool destPool = (StoragePool)this.dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
++        StoragePool destPool = (StoragePool)dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
          if (destPool == null) {
              throw new InvalidParameterValueException(
                      "Failed to find the destination storage pool: "
@@@ -2067,30 -2012,12 +2051,30 @@@
          return newVol;
      }
  
 -
 -
      @DB
      protected Volume migrateVolume(Volume volume, StoragePool destPool) {
--        VolumeInfo vol = this.volFactory.getVolume(volume.getId());
--        AsyncCallFuture<VolumeApiResult> future = this.volService.copyVolume(vol, (DataStore)destPool);
++        VolumeInfo vol = volFactory.getVolume(volume.getId());
++        AsyncCallFuture<VolumeApiResult> future = volService.copyVolume(vol, (DataStore)destPool);
 +        try {
 +            VolumeApiResult result = future.get();
 +            if (result.isFailed()) {
 +                s_logger.debug("migrate volume failed:" + result.getResult());
 +                return null;
 +            }
 +            return result.getVolume();
 +        } catch (InterruptedException e) {
 +            s_logger.debug("migrate volume failed", e);
 +            return null;
 +        } catch (ExecutionException e) {
 +            s_logger.debug("migrate volume failed", e);
 +            return null;
 +        }
 +    }
 +
 +    @DB
 +    protected Volume liveMigrateVolume(Volume volume, StoragePool destPool) {
-         VolumeInfo vol = this.volFactory.getVolume(volume.getId());
-         AsyncCallFuture<VolumeApiResult> future = this.volService.migrateVolume(vol, (DataStore)destPool);
++        VolumeInfo vol = volFactory.getVolume(volume.getId());
++        AsyncCallFuture<VolumeApiResult> future = volService.migrateVolume(vol, (DataStore)destPool);
          try {
              VolumeApiResult result = future.get();
              if (result.isFailed()) {
@@@ -2108,46 -2035,6 +2092,46 @@@
      }
  
      @Override
 +    public <T extends VMInstanceVO> void migrateVolumes(T vm, VirtualMachineTO vmTo, Host srcHost, Host destHost,
 +            Map<VolumeVO, StoragePoolVO> volumeToPool) {
 +        // Check if all the vms being migrated belong to the vm.
 +        // Check if the storage pool is of the right type.
 +        // Create a VolumeInfo to DataStore map too.
 +        Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
 +        for (Map.Entry<VolumeVO, StoragePoolVO> entry : volumeToPool.entrySet()) {
 +            VolumeVO volume = entry.getKey();
 +            StoragePoolVO storagePool = entry.getValue();
-             StoragePool destPool = (StoragePool)this.dataStoreMgr.getDataStore(storagePool.getId(),
++            StoragePool destPool = (StoragePool)dataStoreMgr.getDataStore(storagePool.getId(),
 +                    DataStoreRole.Primary);
 +
 +            if (volume.getInstanceId() != vm.getId()) {
 +                throw new CloudRuntimeException("Volume " + volume + " that has to be migrated doesn't belong to the" +
 +                        " instance " + vm);
 +            }
 +
 +            if (destPool == null) {
 +                throw new CloudRuntimeException("Failed to find the destination storage pool " + storagePool.getId());
 +            }
 +
-             volumeMap.put(this.volFactory.getVolume(volume.getId()), (DataStore)destPool);
++            volumeMap.put(volFactory.getVolume(volume.getId()), (DataStore)destPool);
 +        }
 +
-         AsyncCallFuture<CommandResult> future = this.volService.migrateVolumes(volumeMap, vmTo, srcHost, destHost);
++        AsyncCallFuture<CommandResult> future = volService.migrateVolumes(volumeMap, vmTo, srcHost, destHost);
 +        try {
 +            CommandResult result = future.get();
 +            if (result.isFailed()) {
 +                s_logger.debug("Failed to migrated vm " + vm + " along with its volumes. " + result.getResult());
 +                throw new CloudRuntimeException("Failed to migrated vm " + vm + " along with its volumes. " +
 +                        result.getResult());
 +            }
 +        } catch (InterruptedException e) {
 +            s_logger.debug("Failed to migrated vm " + vm + " along with its volumes.", e);
 +        } catch (ExecutionException e) {
 +            s_logger.debug("Failed to migrated vm " + vm + " along with its volumes.", e);
 +        }
 +    }
 +
 +    @Override
      public boolean storageMigration(
              VirtualMachineProfile<? extends VirtualMachine> vm,
              StoragePool destPool) {
@@@ -2195,22 -2082,17 +2179,17 @@@
          }
  
          for (VolumeVO vol : vols) {
-             PrimaryDataStoreInfo pool = (PrimaryDataStoreInfo)this.dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
-             vm.addDisk(new VolumeTO(vol, pool));
 -            DataTO volTO = this.volFactory.getVolume(vol.getId()).getTO();
++            DataTO volTO = volFactory.getVolume(vol.getId()).getTO();
+             DiskTO disk = new DiskTO(volTO, vol.getDeviceId(), vol.getVolumeType());
+             vm.addDisk(disk);
          }
  
          if (vm.getType() == VirtualMachine.Type.User) {
              UserVmVO userVM = (UserVmVO) vm.getVirtualMachine();
              if (userVM.getIsoId() != null) {
-                 Pair<String, String> isoPathPair = this._tmpltMgr.getAbsoluteIsoPath(
-                         userVM.getIsoId(), userVM.getDataCenterId());
-                 if (isoPathPair != null) {
-                     String isoPath = isoPathPair.first();
-                     VolumeTO iso = new VolumeTO(vm.getId(), Volume.Type.ISO,
-                             StoragePoolType.ISO, null, null, null, isoPath, 0,
-                             null, null);
-                     vm.addDisk(iso);
-                 }
 -                DataTO dataTO = this.tmplFactory.getTemplate(userVM.getIsoId(), DataStoreRole.Image, userVM.getDataCenterId()).getTO();
++                DataTO dataTO = tmplFactory.getTemplate(userVM.getIsoId(), DataStoreRole.Image, userVM.getDataCenterId()).getTO();
+                 DiskTO iso = new DiskTO(dataTO, 3L, Volume.Type.ISO);
+                 vm.addDisk(iso);
              }
          }
      }
@@@ -2362,10 -2244,10 +2341,10 @@@
          Long templateId = newVol.getTemplateId();
          AsyncCallFuture<VolumeApiResult> future = null;
          if (templateId == null) {
--            future = this.volService.createVolumeAsync(volume, destPool);
++            future = volService.createVolumeAsync(volume, destPool);
          } else {
--            TemplateInfo templ = this.tmplFactory.getTemplate(templateId, DataStoreRole.Image);
--            future = this.volService.createVolumeFromTemplateAsync(volume, destPool.getId(), templ);
++            TemplateInfo templ = tmplFactory.getTemplate(templateId, DataStoreRole.Image);
++            future = volService.createVolumeFromTemplateAsync(volume, destPool.getId(), templ);
          }
          VolumeApiResult result = null;
          try {
@@@ -2376,7 -2258,7 +2355,7 @@@
                  throw new StorageUnavailableException("Unable to create "
                          + newVol + ":" + result.getResult(), destPool.getId());
              }
--            newVol = this._volsDao.findById(newVol.getId());
++            newVol = _volsDao.findById(newVol.getId());
          } catch (InterruptedException e) {
              s_logger.error("Unable to create " + newVol, e);
              throw new StorageUnavailableException("Unable to create "
@@@ -2426,7 -2308,9 +2405,9 @@@
                  pool = (StoragePool)dataStoreMgr.getDataStore(result.second().getId(), DataStoreRole.Primary);
                  vol = result.first();
              }
-             vm.addDisk(new VolumeTO(vol, pool));
 -            DataTO volumeTO = this.volFactory.getVolume(vol.getId()).getTO();
++            DataTO volumeTO = volFactory.getVolume(vol.getId()).getTO();
+             DiskTO disk = new DiskTO(volumeTO, vol.getDeviceId(), vol.getVolumeType());
+             vm.addDisk(disk);
          }
      }
  
@@@ -2560,7 -2444,7 +2541,7 @@@
      @Override
      public void destroyVolume(VolumeVO volume) {
          try {
--            this.volService.destroyVolume(volume.getId());
++            volService.destroyVolume(volume.getId());
          } catch (ConcurrentOperationException e) {
              s_logger.debug("Failed to destroy volume" + volume.getId(), e);
              throw new CloudRuntimeException("Failed to destroy volume" + volume.getId(), e);
@@@ -2572,7 -2456,7 +2553,7 @@@
  
      @Override
      public Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account account) throws ResourceAllocationException {
--        VolumeInfo volume = this.volFactory.getVolume(volumeId);
++        VolumeInfo volume = volFactory.getVolume(volumeId);
          if (volume == null) {
              throw new InvalidParameterValueException("Creating snapshot failed due to volume:" + volumeId + " doesn't exist");
          }
@@@ -2586,14 -2470,14 +2567,14 @@@
          payload.setSnapshotPolicyId(policyId);
          payload.setAccount(account);
          volume.addPayload(payload);
--        return this.volService.takeSnapshot(volume);
++        return volService.takeSnapshot(volume);
      }
  
      @Override
      public Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException {
          Account caller = UserContext.current().getCaller();
  
--        VolumeInfo volume = this.volFactory.getVolume(volumeId);
++        VolumeInfo volume = volFactory.getVolume(volumeId);
          if (volume == null) {
              throw new InvalidParameterValueException("Creating snapshot failed due to volume:" + volumeId + " doesn't exist");
          }
@@@ -2622,7 -2506,7 +2603,7 @@@
              throw new InvalidParameterValueException("VolumeId: " + volumeId + " please attach this volume to a VM before create snapshot for it");
          }
  
--        return this.snapshotMgr.allocSnapshot(volumeId, policyId);
++        return snapshotMgr.allocSnapshot(volumeId, policyId);
      }
  
  }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/server/src/com/cloud/storage/download/DownloadListener.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/storage/download/DownloadListener.java
index 48c6ebf,691d655..3b6c0dd
--- a/server/src/com/cloud/storage/download/DownloadListener.java
+++ b/server/src/com/cloud/storage/download/DownloadListener.java
@@@ -25,8 -25,7 +25,10 @@@ import java.util.TimerTask
  
  import javax.inject.Inject;
  
++import org.apache.log4j.Level;
++import org.apache.log4j.Logger;
++
  import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
- import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
  import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
  import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
@@@ -35,11 -34,11 +37,9 @@@ import org.apache.cloudstack.engine.sub
  import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
  import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
  import org.apache.cloudstack.storage.command.DownloadCommand;
 -import org.apache.cloudstack.storage.command.DownloadProgressCommand;
  import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
 +import org.apache.cloudstack.storage.command.DownloadProgressCommand;
  import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType;
--import org.apache.log4j.Level;
--import org.apache.log4j.Logger;
  
  import com.cloud.agent.Listener;
  import com.cloud.agent.api.AgentControlAnswer;
@@@ -50,6 -49,8 +50,7 @@@ import com.cloud.agent.api.StartupComma
  import com.cloud.agent.api.StartupRoutingCommand;
  import com.cloud.agent.api.StartupSecondaryStorageCommand;
  import com.cloud.agent.api.storage.DownloadAnswer;
+ import com.cloud.agent.api.to.DataObjectType;
 -import com.cloud.exception.AgentUnavailableException;
  import com.cloud.exception.ConnectionException;
  import com.cloud.host.Host;
  import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@@ -72,7 -72,7 +73,7 @@@ public class DownloadListener implement
  		private final RequestType reqType;
  
  		public StatusTask( DownloadListener dl,  RequestType req) {
--			this.reqType = req;
++			reqType = req;
  			this.dl = dl;
  		}
  
@@@ -139,26 -139,26 +140,26 @@@
  
  	// TODO: this constructor should be the one used for template only, remove other template constructor later
      public DownloadListener(EndPoint ssAgent, DataStore store, DataObject object, Timer _timer, DownloadMonitorImpl downloadMonitor, DownloadCommand cmd, AsyncCompletionCallback<DownloadAnswer> callback) {
--        this._ssAgent = ssAgent;
++        _ssAgent = ssAgent;
          this.object = object;
--        this._downloadMonitor = downloadMonitor;
--        this._cmd = cmd;
++        _downloadMonitor = downloadMonitor;
++        _cmd = cmd;
          initStateMachine();
--        this._currState=getState(Status.NOT_DOWNLOADED.toString());
++        _currState=getState(Status.NOT_DOWNLOADED.toString());
          this._timer = _timer;
--        this._timeoutTask = new TimeoutTask(this);
++        _timeoutTask = new TimeoutTask(this);
          this._timer.schedule(_timeoutTask, 3*STATUS_POLL_INTERVAL);
--        this._callback = callback;
++        _callback = callback;
          DownloadAnswer answer = new DownloadAnswer("", Status.NOT_DOWNLOADED);
          callback(answer);
      }
  
      public AsyncCompletionCallback<DownloadAnswer> getCallback() {
--    	return this._callback;
++    	return _callback;
      }
  
  	public void setCurrState(VMTemplateHostVO.Status currState) {
--		this._currState = getState(currState.toString());
++		_currState = getState(currState.toString());
  	}
  
  	private void initStateMachine() {
@@@ -180,10 -180,10 +181,10 @@@
  			}
  			try {
  				DownloadProgressCommand dcmd = new DownloadProgressCommand(getCommand(), getJobId(), reqType);
--				if (this.object.getType() == DataObjectType.VOLUME) {
++				if (object.getType() == DataObjectType.VOLUME) {
  					dcmd.setResourceType(ResourceType.VOLUME);
  				}
 -	            _ssAgent.sendMessageAsyncWithListener(dcmd, this);
 +                _ssAgent.sendMessageAsync(dcmd, new UploadListener.Callback(_ssAgent.getId(), this));
              } catch (Exception e) {
              	s_logger.debug("Send command failed", e);
  				setDisconnected();
@@@ -201,12 -201,12 +202,12 @@@
  	}
  
  	public void logDisconnect() {
--			s_logger.warn("Unable to monitor download progress of " + this.object.getType() + ": " +
--					this.object.getId() + " at host " + _ssAgent.getId());
++			s_logger.warn("Unable to monitor download progress of " + object.getType() + ": " +
++					object.getId() + " at host " + _ssAgent.getId());
  	}
  
  	public void log(String message, Level level) {
--		s_logger.log(level, message + ", " + this.object.getType() + ": " + this.object.getId() + " at host " + _ssAgent.getId());
++		s_logger.log(level, message + ", " + object.getType() + ": " + object.getId() + " at host " + _ssAgent.getId());
  	}
  
  	public DownloadListener(DownloadMonitorImpl monitor) {
@@@ -259,7 -259,7 +260,7 @@@
  
  	public void callback(DownloadAnswer answer) {
  	    if ( _callback != null ){
--	        this._callback.complete(answer);
++	        _callback.complete(answer);
  	    }
  	}
  
@@@ -300,7 -300,7 +301,7 @@@
              }
  	    }*/
  	    else if ( cmd instanceof StartupSecondaryStorageCommand ) {
--	        List<DataStore> imageStores = this._storeMgr.getImageStoresByScope(new ZoneScope(agent.getDataCenterId()));
++	        List<DataStore> imageStores = _storeMgr.getImageStoresByScope(new ZoneScope(agent.getDataCenterId()));
  	        for (DataStore store : imageStores){
  	            _volumeSrv.handleVolumeSync(store);
  	            _imageSrv.handleTemplateSync(store);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/template/TemplateManagerImpl.java
index 3a259eb,0bdd8c1..922cc34
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@@ -79,9 -81,11 +81,12 @@@ import org.springframework.stereotype.C
  import com.cloud.agent.AgentManager;
  import com.cloud.agent.api.Answer;
  import com.cloud.agent.api.AttachIsoCommand;
+ import com.cloud.agent.api.Command;
  import com.cloud.agent.api.ComputeChecksumCommand;
 +
  import com.cloud.agent.api.storage.DestroyCommand;
+ import com.cloud.agent.api.to.DataTO;
+ import com.cloud.agent.api.to.DiskTO;
  import com.cloud.api.ApiDBUtils;
  import com.cloud.async.AsyncJobManager;
  import com.cloud.async.AsyncJobVO;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/342624e0/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/vm/UserVmManagerImpl.java
index 125e89c,98aeaf2..d6914eb
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@@ -32,35 -32,22 +32,39 @@@ import javax.ejb.Local
  import javax.inject.Inject;
  import javax.naming.ConfigurationException;
  
 -import com.cloud.api.ApiDBUtils;
++import org.apache.commons.codec.binary.Base64;
++import org.apache.log4j.Logger;
++
  import org.apache.cloudstack.acl.ControlledEntity.ACLType;
  import org.apache.cloudstack.acl.SecurityChecker.AccessType;
 +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.BaseCmd.HTTPMethod;
  import org.apache.cloudstack.api.command.admin.vm.AssignVMCmd;
  import org.apache.cloudstack.api.command.admin.vm.RecoverVMCmd;
 -import org.apache.cloudstack.api.command.user.vm.*;
 +import org.apache.cloudstack.api.command.user.vm.AddNicToVMCmd;
 +import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
 +import org.apache.cloudstack.api.command.user.vm.DestroyVMCmd;
 +import org.apache.cloudstack.api.command.user.vm.RebootVMCmd;
 +import org.apache.cloudstack.api.command.user.vm.RemoveNicFromVMCmd;
 +import org.apache.cloudstack.api.command.user.vm.ResetVMPasswordCmd;
 +import org.apache.cloudstack.api.command.user.vm.ResetVMSSHKeyCmd;
 +import org.apache.cloudstack.api.command.user.vm.RestoreVMCmd;
 +import org.apache.cloudstack.api.command.user.vm.ScaleVMCmd;
 +import org.apache.cloudstack.api.command.user.vm.StartVMCmd;
 +import org.apache.cloudstack.api.command.user.vm.UpdateDefaultNicForVMCmd;
 +import org.apache.cloudstack.api.command.user.vm.UpdateVMCmd;
 +import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd;
  import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd;
  import org.apache.cloudstack.api.command.user.vmgroup.DeleteVMGroupCmd;
  import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity;
  import org.apache.cloudstack.engine.service.api.OrchestrationService;
+ import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
+ import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
  import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
- import org.apache.commons.codec.binary.Base64;
- import org.apache.log4j.Logger;
+ import org.apache.cloudstack.storage.to.TemplateObjectTO;
 -import org.apache.commons.codec.binary.Base64;
 -import org.apache.log4j.Logger;
  
  import com.cloud.agent.AgentManager;
  import com.cloud.agent.AgentManager.OnError;
@@@ -74,12 -61,12 +78,12 @@@ import com.cloud.agent.api.StopAnswer
  import com.cloud.agent.api.UnPlugNicAnswer;
  import com.cloud.agent.api.UnPlugNicCommand;
  import com.cloud.agent.api.VmStatsEntry;
+ import com.cloud.agent.api.to.DiskTO;
  import com.cloud.agent.api.to.NicTO;
  import com.cloud.agent.api.to.VirtualMachineTO;
--import com.cloud.agent.api.to.VolumeTO;
  import com.cloud.agent.manager.Commands;
  import com.cloud.alert.AlertManager;
 +import com.cloud.api.ApiDBUtils;
  import com.cloud.api.query.dao.UserVmJoinDao;
  import com.cloud.api.query.vo.UserVmJoinVO;
  import com.cloud.async.AsyncJobManager;
@@@ -169,14 -155,15 +173,14 @@@ import com.cloud.resource.ResourceState
  import com.cloud.server.Criteria;
  import com.cloud.service.ServiceOfferingVO;
  import com.cloud.service.dao.ServiceOfferingDao;
++import com.cloud.storage.DataStoreRole;
  import com.cloud.storage.DiskOfferingVO;
  import com.cloud.storage.GuestOSCategoryVO;
  import com.cloud.storage.GuestOSVO;
  import com.cloud.storage.SnapshotVO;
  import com.cloud.storage.Storage;
  import com.cloud.storage.Storage.ImageFormat;
--import com.cloud.storage.Storage.StoragePoolType;
  import com.cloud.storage.Storage.TemplateType;
 -import com.cloud.storage.DataStoreRole;
  import com.cloud.storage.StorageManager;
  import com.cloud.storage.StoragePool;
  import com.cloud.storage.StoragePoolStatus;
@@@ -193,7 -180,7 +197,6 @@@ import com.cloud.storage.dao.VMTemplate
  import com.cloud.storage.dao.VMTemplateDetailsDao;
  import com.cloud.storage.dao.VMTemplateZoneDao;
  import com.cloud.storage.dao.VolumeDao;
--import com.cloud.storage.dao.VolumeHostDao;
  import com.cloud.storage.snapshot.SnapshotManager;
  import com.cloud.tags.dao.ResourceTagDao;
  import com.cloud.template.TemplateManager;
@@@ -392,12 -377,9 +395,14 @@@ public class UserVmManagerImpl extends 
      protected VMSnapshotManager _vmSnapshotMgr;
  
      @Inject
 +    AffinityGroupVMMapDao _affinityGroupVMMapDao;
 +    @Inject
 +    AffinityGroupDao _affinityGroupDao;
 +
 +    @Inject
      List<DeployPlannerSelector> plannerSelectors;
+     @Inject
+     TemplateDataFactory templateFactory;
  
      protected ScheduledExecutorService _executor = null;
      protected int _expungeInterval;
@@@ -1490,7 -1489,7 +1495,7 @@@
                          .findUsableVolumesForInstance(vm.getId());
                  for (VolumeVO volume : volumesForThisVm) {
                      if (volume.getState() != Volume.State.Destroy) {
--                        this.volumeMgr.destroyVolume(volume);
++                        volumeMgr.destroyVolume(volume);
                      }
                  }
                  String msg = "Failed to deploy Vm with Id: " + vmId + ", on Host with Id: " + hostId;
@@@ -4180,30 -3972,7 +4166,30 @@@
          /* Detach and destory the old root volume */
  
          _volsDao.detachVolume(root.getId());
--        this.volumeMgr.destroyVolume(root);
++        volumeMgr.destroyVolume(root);
 +
 +        if (template.getEnablePassword()) {
 +            String password = generateRandomPassword();
 +            boolean result = resetVMPasswordInternal(vmId, password);
 +            if (result) {
 +                vm.setPassword(password);
 +                _vmDao.loadDetails(vm);
 +                // update the password in vm_details table too
 +                // Check if an SSH key pair was selected for the instance and if so
 +                // use it to encrypt & save the vm password
 +                String sshPublicKey = vm.getDetail("SSH.PublicKey");
 +                if (sshPublicKey != null && !sshPublicKey.equals("") && password != null && !password.equals("saved_password")) {
 +                    String encryptedPasswd = RSAHelper.encryptWithSSHPublicKey(sshPublicKey, password);
 +                    if (encryptedPasswd == null) {
 +                        throw new CloudRuntimeException("VM reset is completed but error occurred when encrypting newly created password");
 +                    }
 +                    vm.setDetail("Encrypted.Password", encryptedPasswd);
 +                    _vmDao.saveDetails(vm);
 +                }
 +            } else {
 +                throw new CloudRuntimeException("VM reset is completed but failed to reset password for the virtual machine ");
 +            }
 +        }
  
          if (needRestart) {
              try {


Mime
View raw message