@@ -262,7 +262,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
262262 String _name ;
263263 String _instance ;
264264 String _zone ;
265- String _defaultNetworkDomain ;
266265
267266 private ConfigurationDao _configDao ;
268267
@@ -1052,14 +1051,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
10521051
10531052 Map <String , String > configs = _configDao .getConfiguration ("AgentManager" , params );
10541053
1055- _defaultNetworkDomain = configs .get ("domain" );
1056- if (_defaultNetworkDomain == null ) {
1057- _defaultNetworkDomain = ".myvm.com" ;
1058- }
1059- if (!_defaultNetworkDomain .startsWith ("." )) {
1060- _defaultNetworkDomain = "." + _defaultNetworkDomain ;
1061- }
1062-
10631054 _instance = configs .get ("instance.name" );
10641055 if (_instance == null ) {
10651056 _instance = "DEFAULT" ;
@@ -1856,6 +1847,9 @@ public void removeInstanceFromInstanceGroup(long vmId) {
18561847 }
18571848
18581849 private boolean validPassword (String password ) {
1850+ if (password == null || password .length () == 0 ) {
1851+ return false ;
1852+ }
18591853 for (int i = 0 ; i < password .length (); i ++) {
18601854 if (password .charAt (i ) == ' ' ) {
18611855 return false ;
@@ -1970,20 +1964,6 @@ public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityE
19701964 }
19711965 }
19721966
1973- // Check that the password was passed in and is valid
1974- String password = PasswordGenerator .generateRandomPassword (6 );
1975- if (!template .getEnablePassword ()) {
1976- password = "saved_password" ;
1977- }
1978- if (password == null || password .equals ("" ) || (!validPassword (password ))) {
1979- throw new InvalidParameterValueException ("A valid password for this virtual machine was not provided." );
1980- }
1981-
1982- String networkDomain = null ;
1983- if (networkDomain == null ) {
1984- networkDomain = "v" + Long .toHexString (owner .getId ()) + _defaultNetworkDomain ;
1985- }
1986-
19871967 String userData = cmd .getUserData ();
19881968 byte [] decodedUserData = null ;
19891969 if (userData != null ) {
@@ -2140,7 +2120,7 @@ public UserVm startVirtualMachine(DeployVMCmd cmd) throws ResourceUnavailableExc
21402120 password = generateRandomPassword ();
21412121 }
21422122
2143- if (password == null || password . equals ( "" ) || ( !validPassword (password ) )) {
2123+ if (!validPassword (password )) {
21442124 throw new InvalidParameterValueException ("A valid password for this virtual machine was not provided." );
21452125 }
21462126
@@ -2150,7 +2130,7 @@ public UserVm startVirtualMachine(DeployVMCmd cmd) throws ResourceUnavailableExc
21502130 if (sshPublicKey != null && !sshPublicKey .equals ("" ) && password != null && !password .equals ("saved_password" ) ) {
21512131 String encryptedPasswd = RSAHelper .encryptWithSSHPublicKey (sshPublicKey , password );
21522132 if (encryptedPasswd == null ) {
2153- throw new ServerApiException ( BaseCmd . INTERNAL_ERROR , "Error encrypting password" );
2133+ throw new CloudRuntimeException ( "Error encrypting password" );
21542134 }
21552135
21562136 vm .setDetail ("Encrypted.Password" , encryptedPasswd );
@@ -2183,14 +2163,22 @@ public UserVm startVirtualMachine(DeployVMCmd cmd) throws ResourceUnavailableExc
21832163
21842164 @ Override
21852165 public boolean finalizeVirtualMachineProfile (VirtualMachineProfile <UserVmVO > profile , DeployDestination dest , ReservationContext context ) {
2186- UserVmVO vo = profile .getVirtualMachine ();
2166+ UserVmVO vm = profile .getVirtualMachine ();
2167+ Account owner = _accountDao .findById (vm .getAccountId ());
2168+
2169+ if (owner == null || owner .getState () == Account .State .disabled ) {
2170+ throw new PermissionDeniedException ("The owner of " + vm + " either does not exist or is disabled: " + vm .getAccountId ());
2171+ }
2172+
2173+
2174+
21872175 VirtualMachineTemplate template = profile .getTemplate ();
2188- if (vo .getIsoId () != null ) {
2189- template = _templateDao .findById (vo .getIsoId ());
2176+ if (vm .getIsoId () != null ) {
2177+ template = _templateDao .findById (vm .getIsoId ());
21902178 }
2191- if (template != null && template .getFormat () == ImageFormat .ISO && vo .getIsoId () != null ) {
2179+ if (template != null && template .getFormat () == ImageFormat .ISO && vm .getIsoId () != null ) {
21922180 String isoPath = null ;
2193- Pair <String , String > isoPathPair = _storageMgr .getAbsoluteIsoPath (template .getId (), vo .getDataCenterId ());
2181+ Pair <String , String > isoPathPair = _storageMgr .getAbsoluteIsoPath (template .getId (), vm .getDataCenterId ());
21942182 if (isoPathPair == null ) {
21952183 s_logger .warn ("Couldn't get absolute iso path" );
21962184 return false ;
@@ -2233,7 +2221,6 @@ public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<UserVmVO>
22332221 }
22342222 }
22352223 _vmDao .update (userVm .getId (), userVm );
2236-
22372224 return true ;
22382225 }
22392226
0 commit comments