@@ -3236,11 +3236,29 @@ public UserVm updateVirtualMachine(long id, String displayName, String group, Bo
32363236 .getUuid(), nic.getId(), extraDhcpOptionsMap);
32373237 }
32383238
3239+ checkAndUpdateSecurityGroupForVM(securityGroupIdList, vm, networks);
3240+
3241+ _vmDao.updateVM(id, displayName, ha, osTypeId, userData, userDataId,
3242+ userDataDetails, isDisplayVmEnabled, isDynamicallyScalable,
3243+ deleteProtection, customId, hostName, instanceName);
3244+
3245+ if (updateUserdata) {
3246+ updateUserData(vm);
3247+ }
3248+
3249+ if (State.Running == vm.getState()) {
3250+ updateDns(vm, hostName);
3251+ }
3252+
3253+ return _vmDao.findById(id);
3254+ }
3255+
3256+ private void checkAndUpdateSecurityGroupForVM(List<Long> securityGroupIdList, UserVmVO vm, List<NetworkVO> networks) {
32393257 boolean isVMware = (vm.getHypervisorType() == HypervisorType.VMware);
32403258
32413259 if (securityGroupIdList != null && isVMware) {
3242- throw new InvalidParameterValueException("Security group feature is not supported for vmWare hypervisor");
3243- } else if (securityGroupIdList != null){
3260+ throw new InvalidParameterValueException("Security group feature is not supported for VMware hypervisor");
3261+ } else if (securityGroupIdList != null) {
32443262 DataCenterVO zone = _dcDao.findById(vm.getDataCenterId());
32453263 List<Long> networkIds = new ArrayList<>();
32463264 try {
@@ -3264,20 +3282,6 @@ public UserVm updateVirtualMachine(long id, String displayName, String group, Bo
32643282 updateSecurityGroup(vm, securityGroupIdList);
32653283 }
32663284 }
3267-
3268- _vmDao.updateVM(id, displayName, ha, osTypeId, userData, userDataId,
3269- userDataDetails, isDisplayVmEnabled, isDynamicallyScalable,
3270- deleteProtection, customId, hostName, instanceName);
3271-
3272- if (updateUserdata) {
3273- updateUserData(vm);
3274- }
3275-
3276- if (State.Running == vm.getState()) {
3277- updateDns(vm, hostName);
3278- }
3279-
3280- return _vmDao.findById(id);
32813285 }
32823286
32833287 private void updateSecurityGroup(UserVmVO vm, List<Long> securityGroupIdList) {
@@ -3287,7 +3291,7 @@ private void updateSecurityGroup(UserVmVO vm, List<Long> securityGroupIdList) {
32873291 // Add instance in provided groups
32883292 _securityGroupMgr.addInstanceToGroups(vm, securityGroupIdList);
32893293 } else {
3290- throw new InvalidParameterValueException("Virtual machine must be stopped prior to update security groups " );
3294+ throw new InvalidParameterValueException(String.format("VM %s must be stopped prior to update security groups", vm.getUuid()) );
32913295 }
32923296 }
32933297
@@ -3831,7 +3835,7 @@ public UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOff
38313835 boolean isVmWare = (template.getHypervisorType() == HypervisorType.VMware || (hypervisor != null && hypervisor == HypervisorType.VMware));
38323836
38333837 if (securityGroupIdList != null && isVmWare) {
3834- throw new InvalidParameterValueException("Security group feature is not supported for vmWare hypervisor");
3838+ throw new InvalidParameterValueException("Security group feature is not supported for VMware hypervisor");
38353839 } else if (!isVmWare && _networkModel.isSecurityGroupSupportedInNetwork(defaultNetwork) && _networkModel.canAddDefaultSecurityGroup()) {
38363840 //add the default securityGroup only if no security group is specified
38373841 if (securityGroupIdList == null || securityGroupIdList.isEmpty()) {
@@ -3891,7 +3895,7 @@ public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, Service
38913895
38923896 } else if (securityGroupIdList != null && !securityGroupIdList.isEmpty()) {
38933897 if (isVmWare) {
3894- throw new InvalidParameterValueException("Security group feature is not supported for vmWare hypervisor");
3898+ throw new InvalidParameterValueException("Security group feature is not supported for VMware hypervisor");
38953899 }
38963900 // Only one network can be specified, and it should be security group enabled
38973901 if (networkIdList.size() > 1 && template.getHypervisorType() != HypervisorType.KVM && hypervisor != HypervisorType.KVM) {
0 commit comments