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

git commit: should have used non url safe

Updated Branches:
  refs/heads/master dd949aeba -> c1c952b42


should have used non url safe


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

Branch: refs/heads/master
Commit: c1c952b42b62769da1af492add0073599351b41f
Parents: dd949ae
Author: Alex Huang <al...@citrix.com>
Authored: Tue Aug 7 16:50:30 2012 -0700
Committer: Alex Huang <al...@citrix.com>
Committed: Tue Aug 7 16:58:16 2012 -0700

----------------------------------------------------------------------
 server/src/com/cloud/api/ApiServer.java            |    4 +-
 .../src/com/cloud/servlet/ConsoleProxyServlet.java |    2 +-
 server/src/com/cloud/vm/UserVmManagerImpl.java     |  413 ++++++++-------
 .../cloud/test/stress/StressTestDirectAttach.java  |    2 +-
 .../com/cloud/test/stress/TestClientWithAPI.java   |    2 +-
 test/src/com/cloud/test/utils/UtilsForTest.java    |    2 +-
 6 files changed, 213 insertions(+), 212 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c1c952b4/server/src/com/cloud/api/ApiServer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java
index 4cb3c6f..e84215d 100755
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -751,7 +751,7 @@ public class ApiServer implements HttpRequestHandler {
             mac.init(keySpec);
             mac.update(unsignedRequest.getBytes());
             byte[] encryptedBytes = mac.doFinal();
-            String computedSignature = Base64.encodeBase64URLSafeString(encryptedBytes);
+            String computedSignature = Base64.encodeBase64String(encryptedBytes);
             boolean equalSig = signature.equals(computedSignature);
             if (!equalSig) {
                 s_logger.info("User signature: " + signature + " is not equaled to computed signature: " + computedSignature);
@@ -843,7 +843,7 @@ public class ApiServer implements HttpRequestHandler {
             SecureRandom sesssionKeyRandom = new SecureRandom();
             byte sessionKeyBytes[] = new byte[20];
             sesssionKeyRandom.nextBytes(sessionKeyBytes);
-            String sessionKey = Base64.encodeBase64URLSafeString(sessionKeyBytes);
+            String sessionKey = Base64.encodeBase64String(sessionKeyBytes);
             session.setAttribute("sessionkey", sessionKey);
 
             return;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c1c952b4/server/src/com/cloud/servlet/ConsoleProxyServlet.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/servlet/ConsoleProxyServlet.java b/server/src/com/cloud/servlet/ConsoleProxyServlet.java
index 20faa32..a052ce2 100644
--- a/server/src/com/cloud/servlet/ConsoleProxyServlet.java
+++ b/server/src/com/cloud/servlet/ConsoleProxyServlet.java
@@ -406,7 +406,7 @@ public class ConsoleProxyServlet extends HttpServlet {
 
             byte[] encryptedBytes = mac.doFinal();
 
-            return Base64.encodeBase64URLSafeString(encryptedBytes);
+            return Base64.encodeBase64String(encryptedBytes);
         } catch(Exception e) {
             s_logger.error("Unexpected exception ", e);
         }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c1c952b4/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 f441c72..4a0a8d9 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit;
 import javax.ejb.Local;
 import javax.naming.ConfigurationException;
 
+import org.apache.commons.codec.binary.Base64;
 import org.apache.log4j.Logger;
 
 import com.cloud.acl.ControlledEntity.ACLType;
@@ -157,7 +158,6 @@ import com.cloud.storage.GuestOSVO;
 import com.cloud.storage.Snapshot;
 import com.cloud.storage.SnapshotVO;
 import com.cloud.storage.Storage;
-import com.cloud.storage.VolumeHostVO;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Storage.StoragePoolType;
 import com.cloud.storage.Storage.TemplateType;
@@ -171,6 +171,7 @@ import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.VMTemplateZoneVO;
 import com.cloud.storage.Volume;
 import com.cloud.storage.Volume.Type;
+import com.cloud.storage.VolumeHostVO;
 import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.DiskOfferingDao;
 import com.cloud.storage.dao.GuestOSDao;
@@ -457,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;
@@ -580,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
@@ -614,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) {
@@ -638,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");
             }
         }
 
@@ -658,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);                        
                         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();
@@ -718,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 {
@@ -822,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.");
@@ -974,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());
@@ -1186,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;
@@ -1351,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());     
 
@@ -1362,13 +1363,13 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
                 throw new InvalidParameterValueException("Snapshot id=" + snapshotId + " is not in " + Snapshot.Status.BackedUp + " state yet and can't be used for template creation");
             }
 
-/*            
+            /*            
             // bug #11428. Operation not supported if vmware and snapshots parent volume = ROOT
             if(snapshot.getHypervisorType() == HypervisorType.VMware && snapshotVolume.getVolumeType() == Type.DATADISK){ 
                 throw new UnsupportedServiceException("operation not supported, snapshot with id " + snapshotId + " is created from Data Disk");
             }
-*/
-            
+             */
+
             hyperType = snapshot.getHypervisorType();            
         }
 
@@ -1416,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
@@ -1628,11 +1629,11 @@ 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");
         }        
     }
 
@@ -1654,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");
@@ -2141,13 +2142,13 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 
         // if network is security group enabled, and no security group is specified, then add the default security group automatically
         if (isSecurityGroupEnabledNetworkUsed && !isVmWare && _networkMgr.canAddDefaultSecurityGroup()) {
-            
-          //add the default securityGroup only if no security group is specified
+
+            //add the default securityGroup only if no security group is specified
             if(securityGroupIdList == null || securityGroupIdList.isEmpty()){
                 if (securityGroupIdList == null) {
                     securityGroupIdList = new ArrayList<Long>();
                 }
-    
+
                 SecurityGroup defaultGroup = _securityGroupMgr.getDefaultSecurityGroup(owner.getId());
                 if (defaultGroup != null) {
                     securityGroupIdList.add(defaultGroup.getId());
@@ -2176,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;
 
@@ -2188,9 +2189,9 @@ 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
@@ -2207,7 +2208,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);
@@ -2238,11 +2239,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";
@@ -2270,12 +2271,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);
                 }
             }
         }
@@ -2367,22 +2368,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));
@@ -2408,7 +2409,7 @@ 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();
         if (hostName == null) {
             hostName = uuidName;
@@ -2431,7 +2432,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);
         }
@@ -2485,7 +2486,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             if (userData.length() >= 2 * MAX_USER_DATA_LENGTH_BYTES) {
                 throw new InvalidParameterValueException("User data is too long");
             }
-            decodedUserData = org.apache.commons.codec.binary.Base64.decodeBase64(userData.getBytes());
+            decodedUserData = Base64.decodeBase64(userData.getBytes());
             if (decodedUserData.length > MAX_USER_DATA_LENGTH_BYTES) {
                 throw new InvalidParameterValueException("User data is too long");
             }
@@ -2507,7 +2508,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);
@@ -2515,7 +2516,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()) {
@@ -2543,14 +2544,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()) {
@@ -2578,7 +2579,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());
@@ -2658,7 +2659,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);
@@ -2666,8 +2667,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
@@ -2725,16 +2726,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() {
@@ -2751,14 +2752,14 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         if (callerAccount != null && callerAccount.getRemoved() != null) {
             throw new InvalidParameterValueException("The account " + callerAccount.getId() + " is removed");
         }
-        
+
         UserVmVO vm = _vmDao.findById(vmId);
         if (vm == null) {
             throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
         }
 
         _accountMgr.checkAccess(callerAccount, null, true, vm);
-        
+
         Account owner = _accountDao.findById(vm.getAccountId());
 
         if (owner == null) {
@@ -2768,7 +2769,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();
@@ -2795,13 +2796,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;
@@ -2830,7 +2831,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);
@@ -2839,17 +2840,17 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         }
 
         vm = _itMgr.start(vm, params, callerUser, callerAccount, plan);
-           
+
         Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> vmParamPair = new Pair(vm, params);
         if (vm != null && vm.isUpdateParameters()) {
-         // this value is not being sent to the backend; need only for api display purposes
+            // this value is not being sent to the backend; need only for api display purposes
             if (template.getEnablePassword()) {
                 vm.setPassword((String)vmParamPair.second().get(VirtualMachineProfile.Param.VmPassword));   
                 vm.setUpdateParameters(false);
                 _vmDao.update(vm.getId(), vm);
             }
         }
-        
+
         return vmParamPair;
     }
 
@@ -2861,8 +2862,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;
         } 
 
@@ -2880,8 +2881,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;
         }
 
@@ -2901,22 +2902,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();
@@ -2966,7 +2967,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 
         SearchBuilder<UserVmVO> sb = _vmDao.createSearchBuilder();
         _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
-        
+
         Object id = c.getCriteria(Criteria.ID);
         Object name = c.getCriteria(Criteria.NAME);
         Object state = c.getCriteria(Criteria.STATE);
@@ -3008,7 +3009,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             groupSearch.and("groupId", groupSearch.entity().getGroupId(), SearchCriteria.Op.EQ);
             sb.join("groupSearch", groupSearch, sb.entity().getId(), groupSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER);
         }
-        
+
         if (tags != null && !tags.isEmpty()) {
             SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
             for (int count=0; count < tags.size(); count++) {
@@ -3041,7 +3042,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());
@@ -3051,7 +3052,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) {
@@ -3071,11 +3072,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         if (id != null) {
             sc.setParameters("id", id);
         }
-        
+
         if (templateId != null) {
             sc.setParameters("templateId", templateId);
         }
-        
+
         if (isoId != null) {
             sc.setParameters("isoId", isoId);
         }
@@ -3149,8 +3150,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;
         }
 
@@ -3186,18 +3187,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();
@@ -3248,13 +3249,13 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
             }
             throw new InvalidParameterValueException("Unsupported operation, VM uses Local storage, cannot migrate");
         }
-        
+
         //check if migrating to same host
         long srcHostId = vm.getHostId();
         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());
@@ -3291,7 +3292,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
@@ -3313,54 +3314,54 @@ 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());
         if (newAccount == null || newAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
             throw new InvalidParameterValueException("Invalid accountid=" + cmd.getAccountName() + " in domain " + cmd.getDomainId());
         }
-        
+
         if (newAccount.getState() == Account.State.disabled) {
             throw new InvalidParameterValueException("The new account owner " + cmd.getAccountName() + " is disabled.");
         }
-        
+
         // 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());
 
@@ -3369,7 +3370,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
 
         //VV 3: check if volumes are with in resource limits
         _resourceLimitMgr.checkResourceLimit(newAccount, ResourceType.volume, _volsDao.findByInstance(cmd.getVmId()).size());
-        
+
         // VV 4: Check if new owner can use the vm template
         VirtualMachineTemplate template = _templateDao.findById(vm.getTemplateId());
         if (!template.isPublicTemplate()) {
@@ -3393,7 +3394,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) {
@@ -3403,7 +3404,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);
@@ -3419,17 +3420,17 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         // OS 3: update the network
         List<Long> networkIdList = cmd.getNetworkIds();
         List<Long> securityGroupIdList = cmd.getSecurityGroupIdList();
-        
+
         if (zone.getNetworkType() == NetworkType.Basic) {
-        	 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
-             _securityGroupMgr.removeInstanceFromGroups(cmd.getVmId());
-       	 	//cleanup the network for the oldOwner
+            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
+            _securityGroupMgr.removeInstanceFromGroups(cmd.getVmId());
+            //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
@@ -3473,62 +3474,62 @@ 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();
             profile.setDefaultNic(true);
             networks.add(new Pair<NetworkVO, NicProfile>(networkList.get(0), profile));
-           
+
             VMInstanceVO vmi = _itMgr.findByIdAndType(vm.getType(), vm.getId());
             VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmi);
             _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=" + 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
@@ -3545,7 +3546,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); 
                     }
 
                     applicableNetworks.add(defaultNetwork);
@@ -3573,9 +3574,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
     }
     @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;
     }
 
 
@@ -3590,11 +3591,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());
@@ -3614,8 +3615,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;
         }
 
@@ -3623,9 +3624,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;
         }
 
@@ -3666,9 +3667,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
         s_logger.debug("Restore VM " + vmId + " with template " + root.getTemplateId() + " successfully");
         return vm;
     }
-    
-	@Override
-	public void prepareStop(VirtualMachineProfile<UserVmVO> profile) {
-	}
-    
+
+    @Override
+    public void prepareStop(VirtualMachineProfile<UserVmVO> profile) {
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c1c952b4/test/src/com/cloud/test/stress/StressTestDirectAttach.java
----------------------------------------------------------------------
diff --git a/test/src/com/cloud/test/stress/StressTestDirectAttach.java b/test/src/com/cloud/test/stress/StressTestDirectAttach.java
index 28f5935..9f77d25 100644
--- a/test/src/com/cloud/test/stress/StressTestDirectAttach.java
+++ b/test/src/com/cloud/test/stress/StressTestDirectAttach.java
@@ -1226,7 +1226,7 @@ public class StressTestDirectAttach {
             mac.init(keySpec);
             mac.update(request.getBytes());
             byte[] encryptedBytes = mac.doFinal();
-            return Base64.encodeBase64URLSafeString(encryptedBytes);
+            return Base64.encodeBase64String(encryptedBytes);
         } catch (Exception ex) {
             s_logger.error("unable to sign request", ex);
         }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c1c952b4/test/src/com/cloud/test/stress/TestClientWithAPI.java
----------------------------------------------------------------------
diff --git a/test/src/com/cloud/test/stress/TestClientWithAPI.java b/test/src/com/cloud/test/stress/TestClientWithAPI.java
index 9d21927..c1058f8 100644
--- a/test/src/com/cloud/test/stress/TestClientWithAPI.java
+++ b/test/src/com/cloud/test/stress/TestClientWithAPI.java
@@ -1977,7 +1977,7 @@ public class TestClientWithAPI {
             mac.init(keySpec);
             mac.update(request.getBytes());
             byte[] encryptedBytes = mac.doFinal();
-            return org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(encryptedBytes);
+            return org.apache.commons.codec.binary.Base64.encodeBase64String(encryptedBytes);
         } catch (Exception ex) {
             s_logger.error("unable to sign request", ex);
         }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c1c952b4/test/src/com/cloud/test/utils/UtilsForTest.java
----------------------------------------------------------------------
diff --git a/test/src/com/cloud/test/utils/UtilsForTest.java b/test/src/com/cloud/test/utils/UtilsForTest.java
index 6414c0b..9926444 100644
--- a/test/src/com/cloud/test/utils/UtilsForTest.java
+++ b/test/src/com/cloud/test/utils/UtilsForTest.java
@@ -226,7 +226,7 @@ public class UtilsForTest {
             mac.update(request.getBytes());
             byte[] encryptedBytes = mac.doFinal();
             //System.out.println("HmacSHA1 hash: " + encryptedBytes);
-            return Base64.encodeBase64URLSafeString(encryptedBytes);
+            return Base64.encodeBase64String(encryptedBytes);
         } catch (Exception ex) {
             System.out.println("unable to sign request");
             ex.printStackTrace();