@@ -2009,31 +2009,22 @@ public UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOff
2009
2009
if (securityGroupIdList != null && isVmWare ) {
2010
2010
throw new InvalidParameterValueException ("Security group feature is not supported for vmWare hypervisor" );
2011
2011
} else if (!isVmWare && _networkMgr .isSecurityGroupSupportedInNetwork (defaultNetwork ) && _networkMgr .canAddDefaultSecurityGroup ()) {
2012
- if (securityGroupIdList == null ) {
2013
- securityGroupIdList = new ArrayList <Long >();
2014
- }
2015
- SecurityGroup defaultGroup = _securityGroupMgr .getDefaultSecurityGroup (owner .getId ());
2016
- if (defaultGroup != null ) {
2017
- //check if security group id list already contains Default security group, and if not - add it
2018
- boolean defaultGroupPresent = false ;
2019
- for (Long securityGroupId : securityGroupIdList ) {
2020
- if (securityGroupId .longValue () == defaultGroup .getId ()) {
2021
- defaultGroupPresent = true ;
2022
- break ;
2023
- }
2012
+ //add the default securityGroup only if no security group is specified
2013
+ if (securityGroupIdList == null || securityGroupIdList .isEmpty ()){
2014
+ if (securityGroupIdList == null ) {
2015
+ securityGroupIdList = new ArrayList <Long >();
2024
2016
}
2025
-
2026
- if (!defaultGroupPresent ) {
2017
+ SecurityGroup defaultGroup = _securityGroupMgr .getDefaultSecurityGroup (owner .getId ());
2018
+ if (defaultGroup != null ) {
2019
+ securityGroupIdList .add (defaultGroup .getId ());
2020
+ } else {
2021
+ //create default security group for the account
2022
+ if (s_logger .isDebugEnabled ()) {
2023
+ s_logger .debug ("Couldn't find default security group for the account " + owner + " so creating a new one" );
2024
+ }
2025
+ defaultGroup = _securityGroupMgr .createSecurityGroup (SecurityGroupManager .DEFAULT_GROUP_NAME , SecurityGroupManager .DEFAULT_GROUP_DESCRIPTION , owner .getDomainId (), owner .getId (), owner .getAccountName ());
2027
2026
securityGroupIdList .add (defaultGroup .getId ());
2028
2027
}
2029
-
2030
- } else {
2031
- //create default security group for the account
2032
- if (s_logger .isDebugEnabled ()) {
2033
- s_logger .debug ("Couldn't find default security group for the account " + owner + " so creating a new one" );
2034
- }
2035
- defaultGroup = _securityGroupMgr .createSecurityGroup (SecurityGroupManager .DEFAULT_GROUP_NAME , SecurityGroupManager .DEFAULT_GROUP_DESCRIPTION , owner .getDomainId (), owner .getId (), owner .getAccountName ());
2036
- securityGroupIdList .add (defaultGroup .getId ());
2037
2028
}
2038
2029
}
2039
2030
0 commit comments