You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2012/08/10 08:33:33 UTC

[3/7] Removed trailing whitespaces and fixed line endings in some files

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/6cddd1e7/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 7a70eb0..53eb350 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -436,9 +436,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             }
 
             Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId());
-            NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, 
-                    _networkMgr.isSecurityGroupSupportedInNetwork(defaultNetwork), 
-                    _networkMgr.getNetworkTag(template.getHypervisorType(), defaultNetwork));
+            NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, _networkMgr.isSecurityGroupSupportedInNetwork(defaultNetwork), _networkMgr.getNetworkTag(template.getHypervisorType(), defaultNetwork));
             VirtualMachineProfile<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmInstance);
             vmProfile.setParameter(VirtualMachineProfile.Param.VmPassword, password);
 
@@ -460,7 +458,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                     s_logger.debug("Vm " + vmInstance + " is stopped, not rebooting it as a part of password reset");
                     return true;
                 }
-                
+
                 if (rebootVirtualMachine(userId, vmId) == null) { 
                     s_logger.warn("Failed to reboot the vm " + vmInstance);
                     return false;
@@ -583,15 +581,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 
         //permission check
         _accountMgr.checkAccess(caller, null, true, volume, vm);
-        
+
         //Check if volume is stored on secondary Storage.
         boolean isVolumeOnSec = false;
         VolumeHostVO  volHostVO = _volumeHostDao.findByVolumeId(volume.getId());
         if (volHostVO != null){
-        	isVolumeOnSec = true;
-        	if( !(volHostVO.getDownloadState() == Status.DOWNLOADED) ){
-        		throw new InvalidParameterValueException("Volume is not uploaded yet. Please try this operation once the volume is uploaded");	
-        	}
+            isVolumeOnSec = true;
+            if( !(volHostVO.getDownloadState() == Status.DOWNLOADED) ){
+                throw new InvalidParameterValueException("Volume is not uploaded yet. Please try this operation once the volume is uploaded");
+            }
         }
 
         //If the volume is Ready, check that the volume is stored on shared storage
@@ -617,7 +615,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         if (dataDiskHyperType != HypervisorType.None && rootDiskHyperType != dataDiskHyperType) {
             throw new InvalidParameterValueException("Can't attach a volume created by: " + dataDiskHyperType + " to a " + rootDiskHyperType + " vm");
         }
-        
+
         //allocate deviceId
         List<VolumeVO> vols = _volsDao.findByInstance(vmId);
         if (deviceId != null) {
@@ -641,12 +639,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             }
             deviceId = Long.parseLong(devIds.iterator().next());
         }
-        
+
         boolean createVolumeOnBackend = true;
         if (rootVolumeOfVm.getState() == Volume.State.Allocated) {
             createVolumeOnBackend = false;
             if(isVolumeOnSec){
-            	throw new CloudRuntimeException("Cant attach uploaded volume to the vm which is not created. Please start it and then retry");
+                throw new CloudRuntimeException("Cant attach uploaded volume to the vm which is not created. Please start it and then retry");
             }
         }
 
@@ -661,34 +659,34 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                 ServiceOfferingVO svo = _serviceOfferingDao.findById(vm.getServiceOfferingId());
                 DiskOfferingVO diskVO = _diskOfferingDao.findById(volume.getDiskOfferingId());
                 Long clusterId = (rootDiskPool == null ? null : rootDiskPool.getClusterId());
-                                           
+
                 if (!isVolumeOnSec){
-                	volume = _storageMgr.createVolume(volume, vm, rootDiskTmplt, dcVO, pod, clusterId, svo, diskVO, new ArrayList<StoragePoolVO>(), volume.getSize(), rootDiskHyperType);
+                    volume = _storageMgr.createVolume(volume, vm, rootDiskTmplt, dcVO, pod, clusterId, svo, diskVO, new ArrayList<StoragePoolVO>(), volume.getSize(), rootDiskHyperType);
                 }else {
-                	try {
-                    	// Format of data disk should be the same as root disk
-                    	if( ! volHostVO.getFormat().getFileExtension().equals(_storageMgr.getSupportedImageFormatForCluster(rootDiskPool.getClusterId())) ){
-                    		throw new InvalidParameterValueException("Failed to attach volume to VM since volumes format " +volHostVO.getFormat().getFileExtension() + " is not compatible with the vm hypervisor type" );
-                    	}
-                        
-                    	// Check that there is some shared storage.
+                    try {
+                        // Format of data disk should be the same as root disk
+                        if( ! volHostVO.getFormat().getFileExtension().equals(_storageMgr.getSupportedImageFormatForCluster(rootDiskPool.getClusterId())) ){
+                            throw new InvalidParameterValueException("Failed to attach volume to VM since volumes format " +volHostVO.getFormat().getFileExtension() + " is not compatible with the vm hypervisor type" );
+                        }
+
+                        // Check that there is some shared storage.
                         StoragePoolVO vmRootVolumePool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());                                           
-                        List<StoragePoolVO> sharedVMPools = _storagePoolDao.findPoolsByTags(vmRootVolumePool.getDataCenterId(), vmRootVolumePool.getPodId(), vmRootVolumePool.getClusterId(), null, true);                        
+                        List<StoragePoolVO> sharedVMPools = _storagePoolDao.findPoolsByTags(vmRootVolumePool.getDataCenterId(), vmRootVolumePool.getPodId(), vmRootVolumePool.getClusterId(), null, true);
                         if (sharedVMPools.size() == 0) {
                             throw new CloudRuntimeException("Cannot attach volume since there are no shared storage pools in the VM's cluster to copy the uploaded volume to.");
                         }
-                        
-    					volume = _storageMgr.copyVolumeFromSecToPrimary(volume, vm, rootDiskTmplt, dcVO, pod, rootDiskPool.getClusterId(), svo, diskVO, new ArrayList<StoragePoolVO>(), volume.getSize(), rootDiskHyperType);
-    				} catch (NoTransitionException e) {				
-    					throw new CloudRuntimeException("Unable to transition the volume ",e);
-    				}
+
+                        volume = _storageMgr.copyVolumeFromSecToPrimary(volume, vm, rootDiskTmplt, dcVO, pod, rootDiskPool.getClusterId(), svo, diskVO, new ArrayList<StoragePoolVO>(), volume.getSize(), rootDiskHyperType);
+                    } catch (NoTransitionException e) {
+                        throw new CloudRuntimeException("Unable to transition the volume ",e);
+                    }
                 }
 
                 if (volume == null) {
                     throw new CloudRuntimeException("Failed to create volume when attaching it to VM: " + vm.getHostName());
                 }
             }
-            
+
             StoragePoolVO vmRootVolumePool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());
             DiskOfferingVO volumeDiskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
             String[] volumeTags = volumeDiskOffering.getTagsArray();
@@ -721,7 +719,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                     }
                 }
             }
-            
+
             if (moveVolumeNeeded) {
                 // Move the volume to a storage pool in the VM's zone, pod, or cluster
                 try {
@@ -825,7 +823,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         if (volume.getVolumeType() != Volume.Type.DATADISK) {
             throw new InvalidParameterValueException("Please specify a data volume.");
         }
-        
+
         // Check that the volume is currently attached to a VM
         if (vmId == null) {
             throw new InvalidParameterValueException("The specified volume is not attached to a VM.");
@@ -977,7 +975,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 
         // Check that the specified service offering ID is valid
         _itMgr.checkIfCanUpgrade(vmInstance, svcOffId);
-        
+
         _itMgr.upgradeVmDb(vmId, svcOffId);
 
         return _vmDao.findById(vmInstance.getId());
@@ -1075,7 +1073,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                 s_logger.debug("Unable to recover the vm because it is not in the correct state: " + vmId);
                 throw new InvalidParameterValueException("Unable to recover the vm because it is not in the correct state: " + vmId);
             }
-        } catch (NoTransitionException e) {
+        } catch (NoTransitionException e){
             throw new InvalidParameterValueException("Unable to recover the vm because it is not in the correct state: " + vmId);
         }
 
@@ -1189,7 +1187,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         ctx.setAccountId(vm.getAccountId());
 
         try {
-        	//expunge the vm
+            //expunge the vm
             if (!_itMgr.advanceExpunge(vm, _accountMgr.getSystemUser(), caller)) {
                 s_logger.info("Did not expunge " + vm);
                 return false;
@@ -1354,7 +1352,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             if (snapshot == null) {
                 throw new InvalidParameterValueException("Failed to create private template record, unable to find snapshot " + snapshotId);
             }
-            
+
             volume = _volsDao.findById(snapshot.getVolumeId());
             VolumeVO snapshotVolume = _volsDao.findByIdIncludingRemoved(snapshot.getVolumeId());     
 
@@ -1371,7 +1369,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                 throw new UnsupportedServiceException("operation not supported, snapshot with id " + snapshotId + " is created from Data Disk");
             }
              */
-            
+
             hyperType = snapshot.getHypervisorType();            
         }
 
@@ -1419,19 +1417,19 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         VMTemplateVO template = _templateDao.persist(privateTemplate);
         // Increment the number of templates
         if (template != null) {
-        	if(cmd.getDetails() != null) {
-        		_templateDetailsDao.persist(template.getId(), cmd.getDetails());
-        	}
-        	
+            if(cmd.getDetails() != null) {
+                _templateDetailsDao.persist(template.getId(), cmd.getDetails());
+            }
+
             _resourceLimitMgr.incrementResourceCount(templateOwner.getId(), ResourceType.template);
         }
 
         if (template != null){
-        	return template;
+            return template;
         }else {
-        	throw new CloudRuntimeException("Failed to create a template");
+            throw new CloudRuntimeException("Failed to create a template");
         }
-        
+
     }
 
     @Override
@@ -1631,12 +1629,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                 txn.commit();
             }
         }
-        
+
         if (privateTemplate != null){
-        	return privateTemplate;
+            return privateTemplate;
         }else {
-        	throw new CloudRuntimeException("Failed to create a template");
-        }        
+            throw new CloudRuntimeException("Failed to create a template");
+        }
     }
 
     @Override
@@ -1657,10 +1655,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 
     // used for vm transitioning to error state
     private void updateVmStateForFailedVmCreation(Long vmId) {
-       
+
         UserVmVO vm = _vmDao.findById(vmId);
-        
-        
+
+
         if (vm != null) {
             if (vm.getState().equals(State.Stopped)) {
                 s_logger.debug("Destroying vm " + vm + " as it failed to create");
@@ -2150,7 +2148,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                 if (securityGroupIdList == null) {
                     securityGroupIdList = new ArrayList<Long>();
                 }
-    
+
                 SecurityGroup defaultGroup = _securityGroupMgr.getDefaultSecurityGroup(owner.getId());
                 if (defaultGroup != null) {
                     securityGroupIdList.add(defaultGroup.getId());
@@ -2179,7 +2177,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 
         // Verify that caller can perform actions in behalf of vm owner
         _accountMgr.checkAccess(caller, null, true, owner);
-        
+
         if (networkIdList == null || networkIdList.isEmpty()) {
             NetworkVO defaultNetwork = null;
 
@@ -2191,17 +2189,16 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 
             List<NetworkOfferingVO> requiredOfferings = _networkOfferingDao.listByAvailability(Availability.Required, false);
             if (requiredOfferings.size() < 1) {
-            	throw new InvalidParameterValueException("Unable to find network offering with availability=" + Availability.Required + " to automatically create the network as a part of vm creation");
+                throw new InvalidParameterValueException("Unable to find network offering with availability=" + Availability.Required + " to automatically create the network as a part of vm creation");
             }
-            
+
             PhysicalNetwork physicalNetwork = _networkMgr.translateZoneIdToPhysicalNetwork(zone.getId());
             if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled) {
                 // get Virtual networks
                 List<NetworkVO> virtualNetworks = _networkMgr.listNetworksForAccount(owner.getId(), zone.getId(), Network.GuestType.Isolated);
 
                 if (virtualNetworks.isEmpty()) {
-                    s_logger.debug("Creating network for account " + owner + " from the network offering id=" + 
-                requiredOfferings.get(0).getId() + " as a part of deployVM process");
+                    s_logger.debug("Creating network for account " + owner + " from the network offering id=" + requiredOfferings.get(0).getId() + " as a part of deployVM process");
                     Network newNetwork = _networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(), 
                             owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, null,
                             null, null, owner, null, physicalNetwork, zone.getId(), ACLType.Account, null, null);
@@ -2212,7 +2209,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                     defaultNetwork = virtualNetworks.get(0);
                 }
             } else {
-            	throw new InvalidParameterValueException("Required network offering id=" + requiredOfferings.get(0).getId() + " is not in " + NetworkOffering.State.Enabled); 
+                throw new InvalidParameterValueException("Required network offering id=" + requiredOfferings.get(0).getId() + " is not in " + NetworkOffering.State.Enabled); 
             }
 
             networkList.add(defaultNetwork);
@@ -2243,11 +2240,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             Long diskSize, List<NetworkVO> networkList, List<Long> securityGroupIdList, String group, String userData, String sshKeyPair, HypervisorType hypervisor, Account caller, Map<Long, String> requestedIps, String defaultNetworkIp, String keyboard) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, StorageUnavailableException, ResourceAllocationException {
 
         _accountMgr.checkAccess(caller, null, true, owner);
-        
+
         if (owner.getState() == Account.State.disabled) {
             throw new PermissionDeniedException("The owner of vm to deploy is disabled: " + owner);
         }
-        
+
         long accountId = owner.getId();
 
         assert !(requestedIps != null && defaultNetworkIp != null) : "requestedIp list and defaultNetworkIp should never be specified together";
@@ -2275,12 +2272,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         //verify security group ids
         if (securityGroupIdList != null) {
             for (Long securityGroupId : securityGroupIdList) {
-            	SecurityGroup sg = _securityGroupDao.findById(securityGroupId);
+                SecurityGroup sg = _securityGroupDao.findById(securityGroupId);
                 if (sg == null) {
                     throw new InvalidParameterValueException("Unable to find security group by id " + securityGroupId);
                 } else {
-                	//verify permissions
-                	_accountMgr.checkAccess(caller, null, true, owner, sg);
+                    //verify permissions
+                    _accountMgr.checkAccess(caller, null, true, owner, sg);
                 }
             }
         }
@@ -2373,22 +2370,22 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             if (network.getDataCenterId() != zone.getId()) {
                 throw new InvalidParameterValueException("Network id=" + network.getId() + " doesn't belong to zone " + zone.getId());
             }
-            
+
             String requestedIp = null;
             if (requestedIps != null && !requestedIps.isEmpty()) {
-            	requestedIp = requestedIps.get(network.getId());
+                requestedIp = requestedIps.get(network.getId());
             }
 
             NicProfile profile = new NicProfile(requestedIp);
-            
+
             if (defaultNetworkNumber == 0) {
-            	 defaultNetworkNumber++;
-                 // if user requested specific ip for default network, add it
-                 if (defaultNetworkIp != null) {
-                     profile = new NicProfile(defaultNetworkIp);
-                 }
+                defaultNetworkNumber++;
+                // if user requested specific ip for default network, add it
+                if (defaultNetworkIp != null) {
+                    profile = new NicProfile(defaultNetworkIp);
+                }
 
-            	 profile.setDefaultNic(true);
+                profile.setDefaultNic(true);
             }
 
             networks.add(new Pair<NetworkVO, NicProfile>(network, profile));
@@ -2396,7 +2393,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             if (_networkMgr.isSecurityGroupSupportedInNetwork(network)) {
                 securityGroupEnabled = true;
             }
-            
+
             //vm can't be a part of more than 1 VPC network
             if (network.getVpcId() != null) {
                 if (vpcNetwork) {
@@ -2422,9 +2419,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         long id = _vmDao.getNextInSequence(Long.class, "id");
 
         String instanceName = VirtualMachineName.getVmName(id, owner.getId(), _instance);
-        
+
         String uuidName = UUID.randomUUID().toString();
-        
+
         //verify hostname information
         if (hostName == null) {
             hostName = uuidName;
@@ -2448,7 +2445,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                     ntwkDomains.put(ntwkDomain, ntwkIds);
                 }
             } 
-            
+
             for (String ntwkDomain : ntwkDomains.keySet()) {
                 for (Long ntwkId : ntwkDomains.get(ntwkDomain)) {
                   //* get all vms hostNames in the network
@@ -2474,7 +2471,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         UserVmVO vm = new UserVmVO(id, instanceName, displayName, template.getId(), hypervisorType, template.getGuestOSId(), offering.getOfferHA(), offering.getLimitCpuUse(), owner.getDomainId(), owner.getId(),
                 offering.getId(), userData, hostName);
         vm.setUuid(uuidName);
-        
+
         if (sshPublicKey != null) {
             vm.setDetail("SSH.PublicKey", sshPublicKey);
         }
@@ -2550,7 +2547,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         long vmId = cmd.getEntityId();
         Long hostId = cmd.getHostId();
         UserVmVO vm = _vmDao.findById(vmId);
-        
+
         Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> vmParamPair = null;
         try {
             vmParamPair = startVirtualMachine(vmId, hostId, additonalParams);
@@ -2558,7 +2555,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         } finally {
             updateVmStateForFailedVmCreation(vm.getId());
         }
-        
+
         // Check that the password was passed in and is valid
         VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
         if (template.getEnablePassword()) {
@@ -2586,14 +2583,14 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             Pair<String, String> isoPathPair = _storageMgr.getAbsoluteIsoPath(template.getId(), vm.getDataCenterIdToDeployIn());
 
             if (template.getTemplateType() == TemplateType.PERHOST) {
-            	isoPath = template.getName();
+                isoPath = template.getName();
             } else {
-            	if (isoPathPair == null) {
-            		s_logger.warn("Couldn't get absolute iso path");
-            		return false;
-            	} else {
-            		isoPath = isoPathPair.first();
-            	}
+                if (isoPathPair == null) {
+                    s_logger.warn("Couldn't get absolute iso path");
+                    return false;
+                } else {
+                    isoPath = isoPathPair.first();
+                }
             }
 
             if (template.isBootable()) {
@@ -2621,7 +2618,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 
     @Override
     public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<UserVmVO> profile, DeployDestination dest, ReservationContext context) {
-    	UserVmVO userVm = profile.getVirtualMachine();
+        UserVmVO userVm = profile.getVirtualMachine();
         List<NicVO> nics = _nicDao.listByVmId(userVm.getId());
         for (NicVO nic : nics) {
             NetworkVO network = _networkDao.findById(nic.getNetworkId());
@@ -2701,7 +2698,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                 s_logger.info("Detected that ip changed in the answer, updated nic in the db with new ip " + returnedIp);
             }
         }
-        
+
         //get system ip and create static nat rule for the vm
         try {
             _rulesMgr.getSystemIpAndEnableStaticNatForVm(profile.getVirtualMachine(), false);
@@ -2709,8 +2706,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             s_logger.warn("Failed to get system ip and enable static nat for the vm " + profile.getVirtualMachine() + " due to exception ", ex);
             return false;
         }
-         
-         return true;
+
+        return true;
     }
 
     @Override
@@ -2768,16 +2765,16 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 
     @Override
     public void finalizeStop(VirtualMachineProfile<UserVmVO> profile, StopAnswer answer) {
-    	//release elastic IP here
-    	IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());
-    	if (ip != null && ip.getSystem()) {
-    		UserContext ctx = UserContext.current();
-    		try {
-            	_rulesMgr.disableStaticNat(ip.getId(), ctx.getCaller(), ctx.getCallerUserId(), true);
-    		} catch (Exception ex) {
-    			s_logger.warn("Failed to disable static nat and release system ip " + ip + " as a part of vm " + profile.getVirtualMachine() + " stop due to exception ", ex);
-    		}
-    	}
+        //release elastic IP here
+        IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());
+        if (ip != null && ip.getSystem()) {
+            UserContext ctx = UserContext.current();
+            try {
+                _rulesMgr.disableStaticNat(ip.getId(), ctx.getCaller(), ctx.getCallerUserId(), true);
+            } catch (Exception ex) {
+                s_logger.warn("Failed to disable static nat and release system ip " + ip + " as a part of vm " + profile.getVirtualMachine() + " stop due to exception ", ex);
+            }
+        }
     }
 
     public String generateRandomPassword() {
@@ -2801,7 +2798,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         }
 
         _accountMgr.checkAccess(callerAccount, null, true, vm);
-        
+
         Account owner = _accountDao.findById(vm.getAccountId());
 
         if (owner == null) {
@@ -2811,7 +2808,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         if (owner.getState() == Account.State.disabled) {
             throw new PermissionDeniedException("The owner of " + vm + " is disabled: " + vm.getAccountId());
         }
-        
+
         Host destinationHost = null;
         if(hostId != null){
             Account account = UserContext.current().getCaller();
@@ -2838,13 +2835,13 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                 _securityGroupMgr.addInstanceToGroups(vmId, groupList);
             }
         }
-        
+
         DataCenterDeployment plan = null;
         if (destinationHost != null) {
             s_logger.debug("Destination Host to deploy the VM is specified, specifying a deployment plan to deploy the VM");
             plan = new DataCenterDeployment(vm.getDataCenterIdToDeployIn(), destinationHost.getPodId(), destinationHost.getClusterId(), destinationHost.getId(), null, null);
         }
-        
+
         //Set parameters
         Map<VirtualMachineProfile.Param, Object> params = null;
         VMTemplateVO template = null;
@@ -2873,7 +2870,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                 vm.setDetail("Encrypted.Password", encryptedPasswd);
                 _vmDao.saveDetails(vm);
             }
-            
+
             params = new HashMap<VirtualMachineProfile.Param, Object>();
             if (additionalParams != null) {
                 params.putAll(additionalParams);
@@ -2892,7 +2889,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                 _vmDao.update(vm.getId(), vm);
             }
         }
-        
+
         return vmParamPair;
     }
 
@@ -2904,8 +2901,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         // Verify input parameters
         UserVmVO vm = _vmDao.findById(vmId);
         if (vm == null || vm.getRemoved() != null) {
-        	InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a virtual machine with specified vmId");
-        	ex.addProxyObject(vm, vmId, "vmId");
+            InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a virtual machine with specified vmId");
+            ex.addProxyObject(vm, vmId, "vmId");
             throw ex;
         } 
 
@@ -2923,8 +2920,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         try {
             status = _itMgr.destroy(vm, userCaller, caller);
         } catch (OperationTimedoutException e) {
-        	CloudRuntimeException ex = new CloudRuntimeException("Unable to destroy with specified vmId", e);
-        	ex.addProxyObject(vm, vmId, "vmId");
+            CloudRuntimeException ex = new CloudRuntimeException("Unable to destroy with specified vmId", e);
+            ex.addProxyObject(vm, vmId, "vmId");
             throw ex;
         }
 
@@ -2944,22 +2941,22 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 
             return _vmDao.findById(vmId);
         } else {
-        	CloudRuntimeException ex = new CloudRuntimeException("Failed to destroy vm with specified vmId");
-        	ex.addProxyObject(vm, vmId, "vmId");
+            CloudRuntimeException ex = new CloudRuntimeException("Failed to destroy vm with specified vmId");
+            ex.addProxyObject(vm, vmId, "vmId");
             throw ex;
         }
     }
 
     @Override
     public List<UserVmVO> searchForUserVMs(ListVMsCmd cmd) {
-    	 Account caller = UserContext.current().getCaller();
-         List<Long> permittedAccounts = new ArrayList<Long>();
-         String hypervisor = cmd.getHypervisor();
-         boolean listAll = cmd.listAll();
-         Long id = cmd.getId();
-         Map<String, String> tags = cmd.getTags();
-
-         Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
+        Account caller = UserContext.current().getCaller();
+        List<Long> permittedAccounts = new ArrayList<Long>();
+        String hypervisor = cmd.getHypervisor();
+        boolean listAll = cmd.listAll();
+        Long id = cmd.getId();
+        Map<String, String> tags = cmd.getTags();
+
+        Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
         _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, listAll, false);
         Long domainId = domainIdRecursiveListProject.first();
         Boolean isRecursive = domainIdRecursiveListProject.second();
@@ -3084,7 +3081,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         // populate the search criteria with the values passed in
         SearchCriteria<UserVmVO> sc = sb.create();
         _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
-        
+
         if (tags != null && !tags.isEmpty()) {
             int count = 0;
             sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.UserVm.toString());
@@ -3094,7 +3091,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                 count++;
             }
         }
-        
+
         if (groupId != null && (Long) groupId == -1) {
             sc.setJoinParameters("vmSearch", "instanceId", (Object) null);
         } else if (groupId != null) {
@@ -3118,7 +3115,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         if (templateId != null) {
             sc.setParameters("templateId", templateId);
         }
-        
+
         if (isoId != null) {
             sc.setParameters("isoId", isoId);
         }
@@ -3192,8 +3189,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
     public HypervisorType getHypervisorTypeOfUserVM(long vmId) {
         UserVmVO userVm = _vmDao.findById(vmId);
         if (userVm == null) {
-        	InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with specified id");
-        	ex.addProxyObject(userVm, vmId, "vmId");            
+            InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with specified id");
+            ex.addProxyObject(userVm, vmId, "vmId");            
             throw ex;
         }
 
@@ -3229,18 +3226,18 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         }
 
         if (vm.getState() != State.Stopped) {
-        	InvalidParameterValueException ex = new InvalidParameterValueException("VM is not Stopped, unable to migrate the vm having the specified id");
-        	ex.addProxyObject(vm, vmId, "vmId");
+            InvalidParameterValueException ex = new InvalidParameterValueException("VM is not Stopped, unable to migrate the vm having the specified id");
+            ex.addProxyObject(vm, vmId, "vmId");
             throw ex;
         }
 
         if (vm.getType() != VirtualMachine.Type.User) {
             throw new InvalidParameterValueException("can only do storage migration on user vm");
         }
-        
+
         List<VolumeVO> vols = _volsDao.findByInstance(vm.getId());
         if (vols.size() > 1) {
-        	throw new InvalidParameterValueException("Data disks attached to the vm, can not migrate. Need to dettach data disks at first");
+            throw new InvalidParameterValueException("Data disks attached to the vm, can not migrate. Need to dettach data disks at first");
         }
 
         HypervisorType destHypervisorType = _clusterDao.findById(destPool.getClusterId()).getHypervisorType();
@@ -3297,7 +3294,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         if(destinationHost.getId() == srcHostId){
             throw new InvalidParameterValueException("Cannot migrate VM, VM is already presnt on this host, please specify valid destination host to migrate the VM");
         }
-        
+
         //check if host is UP
         if(destinationHost.getStatus() != com.cloud.host.Status.Up || destinationHost.getResourceState() != ResourceState.Enabled){
             throw new InvalidParameterValueException("Cannot migrate VM, destination host is not in correct state, has status: "+destinationHost.getStatus() + ", state: " +destinationHost.getResourceState());
@@ -3334,7 +3331,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         //VV 1: verify the two users
         Account caller = UserContext.current().getCaller();
         if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN  && caller.getType() != Account.ACCOUNT_TYPE_DOMAIN_ADMIN){ // only root admin can assign VMs
-        	throw new InvalidParameterValueException("Only domain admins are allowed to assign VMs and not " + caller.getType());
+            throw new InvalidParameterValueException("Only domain admins are allowed to assign VMs and not " + caller.getType());
         }
 
         //get and check the valid VM
@@ -3356,8 +3353,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         }
         //don't allow to move the vm from the project
         if (oldAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
-        	InvalidParameterValueException ex = new InvalidParameterValueException("Specified Vm id belongs to the project and can't be moved");
-        	ex.addProxyObject(vm, cmd.getVmId(), "vmId");
+            InvalidParameterValueException ex = new InvalidParameterValueException("Specified Vm id belongs to the project and can't be moved");
+            ex.addProxyObject(vm, cmd.getVmId(), "vmId");
             throw ex;
         }
         Account newAccount = _accountService.getActiveAccountByName(cmd.getAccountName(), cmd.getDomainId());
@@ -3371,39 +3368,39 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         
         // make sure the accounts are under same domain
         if (oldAccount.getDomainId() != newAccount.getDomainId()){
-        	 throw new InvalidParameterValueException("The account should be under same domain for moving VM between two accounts. Old owner domain =" + oldAccount.getDomainId() +
-        			 " New owner domain=" + newAccount.getDomainId());
+            throw new InvalidParameterValueException("The account should be under same domain for moving VM between two accounts. Old owner domain =" + oldAccount.getDomainId() +
+                     " New owner domain=" + newAccount.getDomainId());
         }
-        
+
         // make sure the accounts are not same
         if (oldAccount.getAccountId() == newAccount.getAccountId()){
-       	    throw new InvalidParameterValueException("The account should be same domain for moving VM between two accounts. Account id =" + oldAccount.getAccountId());
+               throw new InvalidParameterValueException("The account should be same domain for moving VM between two accounts. Account id =" + oldAccount.getAccountId());
         }
 
-        
+
         // don't allow to move the vm if there are existing PF/LB/Static Nat rules, or vm is assigned to static Nat ip
         List<PortForwardingRuleVO> pfrules = _portForwardingDao.listByVm(cmd.getVmId());
         if (pfrules != null && pfrules.size() > 0){
-        	throw new InvalidParameterValueException("Remove the Port forwarding rules for this VM before assigning to another user.");
+            throw new InvalidParameterValueException("Remove the Port forwarding rules for this VM before assigning to another user.");
         }
         List<FirewallRuleVO> snrules = _rulesDao.listStaticNatByVmId(vm.getId());
         if (snrules != null && snrules.size() > 0){
-        	throw new InvalidParameterValueException("Remove the StaticNat rules for this VM before assigning to another user.");
+            throw new InvalidParameterValueException("Remove the StaticNat rules for this VM before assigning to another user.");
         }
         List<LoadBalancerVMMapVO> maps = _loadBalancerVMMapDao.listByInstanceId(vm.getId());
         if (maps != null && maps.size() > 0) {
-        	throw new InvalidParameterValueException("Remove the load balancing rules for this VM before assigning to another user.");
+            throw new InvalidParameterValueException("Remove the load balancing rules for this VM before assigning to another user.");
         }
         // check for one on one nat
         IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(cmd.getVmId());
         if (ip != null){
-        	if (ip.isOneToOneNat()){
-        		throw new InvalidParameterValueException("Remove the one to one nat rule for this VM for ip " + ip.toString());
-        	}
+            if (ip.isOneToOneNat()){
+                throw new InvalidParameterValueException("Remove the one to one nat rule for this VM for ip " + ip.toString());
+            }
         }
-        
+
         DataCenterVO zone = _dcDao.findById(vm.getDataCenterIdToDeployIn());
-    
+
         //Remove vm from instance group
         removeInstanceFromInstanceGroup(cmd.getVmId());
 
@@ -3436,7 +3433,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         vm.setAccountId(newAccount.getAccountId());
         vm.setDomainId(cmd.getDomainId());
         _vmDao.persist(vm);
-        
+
         // OS 2: update volume
         List<VolumeVO> volumes = _volsDao.findByInstance(cmd.getVmId());
         for (VolumeVO volume : volumes) {
@@ -3446,7 +3443,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             _volsDao.persist(volume);
             _resourceLimitMgr.incrementResourceCount(newAccount.getAccountId(), ResourceType.volume);
             _usageEventDao.persist(new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(),
-            		volume.getDiskOfferingId(), volume.getTemplateId(), volume.getSize()));
+                    volume.getDiskOfferingId(), volume.getTemplateId(), volume.getSize()));
         }
 
         _resourceLimitMgr.incrementResourceCount(newAccount.getAccountId(), ResourceType.user_vm);
@@ -3464,15 +3461,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         List<Long> securityGroupIdList = cmd.getSecurityGroupIdList();
         
         if (zone.getNetworkType() == NetworkType.Basic) {
-        	 if (networkIdList != null && !networkIdList.isEmpty()) {
+             if (networkIdList != null && !networkIdList.isEmpty()) {
                  throw new InvalidParameterValueException("Can't move vm with network Ids; this is a basic zone VM");
              }
-         	//cleanup the old security groups
+             //cleanup the old security groups
              _securityGroupMgr.removeInstanceFromGroups(cmd.getVmId());
-       	 	//cleanup the network for the oldOwner
+            //cleanup the network for the oldOwner
             _networkMgr.cleanupNics(vmOldProfile);
             _networkMgr.expungeNics(vmOldProfile);
-        	//security groups will be recreated for the new account, when the VM is started
+            //security groups will be recreated for the new account, when the VM is started
             List<NetworkVO> networkList = new ArrayList<NetworkVO>();
 
             // Get default guest network in Basic zone
@@ -3516,7 +3513,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                     securityGroupIdList.add(defaultGroup.getId());
                 }
             }
-            
+
 
             List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>();
             NicProfile profile = new NicProfile();
@@ -3528,48 +3525,48 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             _networkMgr.allocate(vmProfile, networks);
 
             _securityGroupMgr.addInstanceToGroups(vm.getId(), securityGroupIdList);
-            
+
             s_logger.debug("AssignVM: Basic zone, adding security groups no " +  securityGroupIdList.size() + " to " + vm.getInstanceName() );
         } else {
             if (zone.isSecurityGroupEnabled())  {
-            	throw new InvalidParameterValueException("Not yet implemented for SecurityGroupEnabled advanced networks.");
+                throw new InvalidParameterValueException("Not yet implemented for SecurityGroupEnabled advanced networks.");
             } else {
                 if (securityGroupIdList != null && !securityGroupIdList.isEmpty()) {
                     throw new InvalidParameterValueException("Can't move vm with security groups; security group feature is not enabled in this zone");
                 }
-            	 //cleanup the network for the oldOwner
+                 //cleanup the network for the oldOwner
                 _networkMgr.cleanupNics(vmOldProfile);
                 _networkMgr.expungeNics(vmOldProfile);
                 
                 Set<NetworkVO> applicableNetworks = new HashSet<NetworkVO>();
             
                 if (networkIdList != null && !networkIdList.isEmpty()){
-	                // add any additional networks
-	                for (Long networkId : networkIdList) {
-	                    NetworkVO network = _networkDao.findById(networkId);
-	                    if (network == null) {
-	                    	InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find specified network id");
-	                    	ex.addProxyObject(network, networkId, "networkId");
-	                        throw ex;
-	                    }
-	
-	                    _networkMgr.checkNetworkPermissions(newAccount, network);
-	
-	                    //don't allow to use system networks 
-	                    NetworkOffering networkOffering = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
-	                    if (networkOffering.isSystemOnly()) {
-	                    	InvalidParameterValueException ex = new InvalidParameterValueException("Specified Network id is system only and can't be used for vm deployment");
-	                    	ex.addProxyObject(network, networkId, "networkId");
-	                        throw ex;
-	                    }
-	                    applicableNetworks.add(network);
-	                }
+                    // add any additional networks
+                    for (Long networkId : networkIdList) {
+                        NetworkVO network = _networkDao.findById(networkId);
+                        if (network == null) {
+                            InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find specified network id");
+                            ex.addProxyObject(network, networkId, "networkId");
+                            throw ex;
+                        }
+
+                        _networkMgr.checkNetworkPermissions(newAccount, network);
+
+                        //don't allow to use system networks 
+                        NetworkOffering networkOffering = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
+                        if (networkOffering.isSystemOnly()) {
+                            InvalidParameterValueException ex = new InvalidParameterValueException("Specified Network id is system only and can't be used for vm deployment");
+                            ex.addProxyObject(network, networkId, "networkId");
+                            throw ex;
+                        }
+                        applicableNetworks.add(network);
+                    }
                 }
                 else {
-                	NetworkVO defaultNetwork = null;
+                    NetworkVO defaultNetwork = null;
                     List<NetworkOfferingVO> requiredOfferings = _networkOfferingDao.listByAvailability(Availability.Required, false);
                     if (requiredOfferings.size() < 1) {
-                    	throw new InvalidParameterValueException("Unable to find network offering with availability="
+                        throw new InvalidParameterValueException("Unable to find network offering with availability="
                     + Availability.Required + " to automatically create the network as a part of vm creation");
                     }
                     
@@ -3587,13 +3584,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                             defaultNetwork = _networkDao.findById(newNetwork.getId());
                         } else if (virtualNetworks.size() > 1) {
                             throw new InvalidParameterValueException("More than 1 default Isolated networks are found " +
-                            		"for account " + newAccount + "; please specify networkIds");
+                                    "for account " + newAccount + "; please specify networkIds");
                         } else {
                             defaultNetwork = virtualNetworks.get(0);
                         }
                     } else {
-                    	throw new InvalidParameterValueException("Required network offering id=" + 
-                    requiredOfferings.get(0).getId() + " is not in " + NetworkOffering.State.Enabled); 
+                        throw new InvalidParameterValueException("Required network offering id=" + requiredOfferings.get(0).getId() + " is not in " + NetworkOffering.State.Enabled); 
                     }
 
                     applicableNetworks.add(defaultNetwork);
@@ -3619,13 +3615,13 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         s_logger.info("AssignVM: vm " + vm.getInstanceName() + " now belongs to account " + cmd.getAccountName());
         return vm;
     }
-    
-    
+
+
     @Override
     public boolean recreateNeeded(VirtualMachineProfile<UserVmVO> profile,
-                       long hostId, Commands cmds, ReservationContext context) {
-               // TODO Auto-generated method stub
-               return false;
+            long hostId, Commands cmds, ReservationContext context) {
+        // TODO Auto-generated method stub
+        return false;
     }
 
 
@@ -3640,11 +3636,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         long vmId = cmd.getVmId();
         UserVmVO vm = _vmDao.findById(vmId);
         if (vm == null) {
-        	InvalidParameterValueException ex = new InvalidParameterValueException("Cann not find VM with ID " + vmId);
-        	ex.addProxyObject(vm, vmId, "vmId");
+            InvalidParameterValueException ex = new InvalidParameterValueException("Cann not find VM with ID " + vmId);
+            ex.addProxyObject(vm, vmId, "vmId");
             throw ex;
         }
-        
+
         Account owner = _accountDao.findById(vm.getAccountId());
         if (owner == null) {
             throw new InvalidParameterValueException("The owner of " + vm + " does not exist: " + vm.getAccountId());
@@ -3664,8 +3660,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 
         List<VolumeVO> rootVols = _volsDao.findByInstance(vmId);
         if (rootVols.isEmpty()) {
-        	InvalidParameterValueException ex = new InvalidParameterValueException("Can not find root volume for VM " + vmId);
-        	ex.addProxyObject(vm, vmId, "vmId");
+            InvalidParameterValueException ex = new InvalidParameterValueException("Can not find root volume for VM " + vmId);
+            ex.addProxyObject(vm, vmId, "vmId");
             throw ex;
         }
 
@@ -3673,9 +3669,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         long templateId = root.getTemplateId();
         VMTemplateVO template = _templateDao.findById(templateId);
         if (template == null) {
-        	InvalidParameterValueException ex = new InvalidParameterValueException("Cannot find template for specified volumeid and vmId");
-        	ex.addProxyObject(vm, vmId, "vmId");
-        	ex.addProxyObject(root, root.getId(), "volumeId");
+            InvalidParameterValueException ex = new InvalidParameterValueException("Cannot find template for specified volumeid and vmId");
+            ex.addProxyObject(vm, vmId, "vmId");
+            ex.addProxyObject(root, root.getId(), "volumeId");
             throw ex;
         }
 
@@ -3734,7 +3730,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
     }
 
     @Override
-	public void prepareStop(VirtualMachineProfile<UserVmVO> profile) {
+    public void prepareStop(VirtualMachineProfile<UserVmVO> profile) {
     }
     
 }