@@ -2455,35 +2455,19 @@ public UserVm updateVirtualMachine(long id, String displayName, String group, Bo
24552455 isDynamicallyScalable = vm .isDynamicallyScalable ();
24562456 }
24572457
2458- Network defaultNetwork = null ;
2458+ // Get default guest network in Basic zone
24592459 DataCenterVO zone = _dcDao .findById (vm .getDataCenterId ());
2460- if (zone .getNetworkType () == NetworkType .Basic ) {
2461- // Get default guest network in Basic zone
2462- defaultNetwork = _networkModel .getExclusiveGuestNetwork (zone .getId ());
2463- } else if (zone .isSecurityGroupEnabled ()) {
2464- NicVO defaultNic = _nicDao .findDefaultNicForVM (vm .getId ());
2465- if (defaultNic != null ) {
2466- defaultNetwork = _networkDao .findById (defaultNic .getNetworkId ());
2467- }
2468- }
2469-
2470- if (defaultNetwork == null && (zone .getNetworkType () == NetworkType .Basic || zone .isSecurityGroupEnabled ())) {
2471- throw new InvalidParameterValueException ("Cannot find default network for vm:" + vm .getId ());
2472- }
2460+ Network defaultNetwork = _networkModel .getExclusiveGuestNetwork (zone .getId ());
24732461
24742462 boolean isVmWare = (vm .getHypervisorType () == HypervisorType .VMware );
24752463
24762464 if (securityGroupIdList != null && isVmWare ) {
24772465 throw new InvalidParameterValueException ("Security group feature is not supported for vmWare hypervisor" );
24782466 } else if (securityGroupIdList != null && _networkModel .isSecurityGroupSupportedInNetwork (defaultNetwork ) && _networkModel .canAddDefaultSecurityGroup ()) {
2479- if (vm .getState () == State .Stopped ) {
2480- // Remove instance from security groups
2481- _securityGroupMgr .removeInstanceFromGroups (id );
2482- // Add instance in provided groups
2483- _securityGroupMgr .addInstanceToGroups (id , securityGroupIdList );
2484- } else {
2485- throw new InvalidParameterValueException ("Virtual machine must be stopped prior to update security groups " );
2486- }
2467+ // Remove instance from security groups
2468+ _securityGroupMgr .removeInstanceFromGroups (id );
2469+ // Add instance in provided groups
2470+ _securityGroupMgr .addInstanceToGroups (id , securityGroupIdList );
24872471 }
24882472
24892473 if (hostName != null ) {
0 commit comments