Skip to content

Commit 65210f4

Browse files
author
Anthony Xu
committed
CLOUDSTACK-737
support multiple NICs in Security group in java side
1 parent d7201df commit 65210f4

2 files changed

Lines changed: 21 additions & 61 deletions

File tree

‎server/src/com/cloud/network/NetworkManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ public Network createGuestNetwork(long networkOfferingId, String name, String di
18781878
if ( _networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)) {
18791879
throw new InvalidParameterValueException("Service SourceNat is not allowed in security group enabled zone");
18801880
}
1881-
if ( _networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SecurityGroup)) {
1881+
if ( ! _networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SecurityGroup)) {
18821882
throw new InvalidParameterValueException("network must have SecurityGroup provider in security group enabled zone");
18831883
}
18841884
}

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 20 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,80 +2048,41 @@ public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, Service
20482048

20492049
Account caller = UserContext.current().getCaller();
20502050
List<NetworkVO> networkList = new ArrayList<NetworkVO>();
2051-
boolean isSecurityGroupEnabledNetworkUsed = false;
20522051
boolean isVmWare = (template.getHypervisorType() == HypervisorType.VMware || (hypervisor != null && hypervisor == HypervisorType.VMware));
2052+
if (isVmWare) {
2053+
throw new InvalidParameterValueException("Security group feature is not supported for vmWare hypervisor");
2054+
}
20532055

20542056
//Verify that caller can perform actions in behalf of vm owner
20552057
_accountMgr.checkAccess(caller, null, true, owner);
2056-
2057-
// If no network is specified, find system security group enabled network
20582058
if (networkIdList == null || networkIdList.isEmpty()) {
2059-
Network networkWithSecurityGroup = _networkModel.getNetworkWithSecurityGroupEnabled(zone.getId());
2060-
if (networkWithSecurityGroup == null) {
2061-
throw new InvalidParameterValueException("No network with security enabled is found in zone id=" + zone.getId());
2062-
}
2063-
2064-
networkList.add(_networkDao.findById(networkWithSecurityGroup.getId()));
2065-
isSecurityGroupEnabledNetworkUsed = true;
2066-
2067-
} else if (securityGroupIdList != null && !securityGroupIdList.isEmpty()) {
2068-
if (isVmWare) {
2069-
throw new InvalidParameterValueException("Security group feature is not supported for vmWare hypervisor");
2070-
}
2071-
// Only one network can be specified, and it should be security group enabled
2072-
if (networkIdList.size() > 1) {
2073-
throw new InvalidParameterValueException("Only support one network per VM if security group enabled");
2074-
}
2075-
2076-
NetworkVO network = _networkDao.findById(networkIdList.get(0).longValue());
2077-
2059+
throw new InvalidParameterValueException("need to specify networkIDs");
2060+
}
2061+
// Verify that all the networks are Shared/Guest; can't create combination of SG enabled and disabled networks
2062+
for (Long networkId : networkIdList) {
2063+
NetworkVO network = _networkDao.findById(networkId);
20782064
if (network == null) {
20792065
throw new InvalidParameterValueException("Unable to find network by id " + networkIdList.get(0).longValue());
20802066
}
20812067

2082-
if (!_networkModel.isSecurityGroupSupportedInNetwork(network)) {
2083-
throw new InvalidParameterValueException("Network is not security group enabled: " + network.getId());
2084-
}
2085-
2086-
networkList.add(network);
2087-
isSecurityGroupEnabledNetworkUsed = true;
2068+
boolean isSecurityGroupEnabled = _networkModel.isSecurityGroupSupportedInNetwork(network);
2069+
if ( ! isSecurityGroupEnabled) {
2070+
throw new InvalidParameterValueException("Only support Security Group enabled networks in Security enabled zone, network " + network.getUuid() + " doesn't support security group ");
2071+
}
20882072

2089-
} else {
2090-
// Verify that all the networks are Shared/Guest; can't create combination of SG enabled and disabled networks
2091-
for (Long networkId : networkIdList) {
2092-
NetworkVO network = _networkDao.findById(networkId);
2093-
2094-
if (network == null) {
2095-
throw new InvalidParameterValueException("Unable to find network by id " + networkIdList.get(0).longValue());
2096-
}
2097-
2098-
boolean isSecurityGroupEnabled = _networkModel.isSecurityGroupSupportedInNetwork(network);
2099-
if (isSecurityGroupEnabled) {
2100-
if (networkIdList.size() > 1) {
2101-
throw new InvalidParameterValueException("Can't create a vm with multiple networks one of" +
2102-
" which is Security Group enabled");
2103-
}
2104-
2105-
isSecurityGroupEnabledNetworkUsed = true;
2106-
}
2107-
2108-
if (!(network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared)) {
2109-
throw new InvalidParameterValueException("Can specify only Shared Guest networks when" +
2073+
if (!(network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared)) {
2074+
throw new InvalidParameterValueException("Can specify only Shared Guest networks when" +
21102075
" deploy vm in Advance Security Group enabled zone");
2111-
}
2076+
}
21122077

2113-
// Perform account permission check
2114-
if (network.getAclType() == ACLType.Account) {
2115-
_accountMgr.checkAccess(caller, AccessType.UseNetwork, false, network);
2116-
}
2117-
networkList.add(network);
2078+
// Perform account permission check
2079+
if (network.getAclType() == ACLType.Account) {
2080+
_accountMgr.checkAccess(caller, AccessType.UseNetwork, false, network);
21182081
}
2082+
networkList.add(network);
21192083
}
2120-
21212084
// if network is security group enabled, and no security group is specified, then add the default security group automatically
2122-
if (isSecurityGroupEnabledNetworkUsed && !isVmWare && _networkModel.canAddDefaultSecurityGroup()) {
2123-
2124-
//add the default securityGroup only if no security group is specified
2085+
if ( _networkModel.canAddDefaultSecurityGroup()) {
21252086
if(securityGroupIdList == null || securityGroupIdList.isEmpty()){
21262087
if (securityGroupIdList == null) {
21272088
securityGroupIdList = new ArrayList<Long>();
@@ -2140,7 +2101,6 @@ public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, Service
21402101
}
21412102
}
21422103
}
2143-
21442104
return createVirtualMachine(zone, serviceOffering, template, hostName, displayName, owner, diskOfferingId,
21452105
diskSize, networkList, securityGroupIdList, group, userData, sshKeyPair, hypervisor, caller, requestedIps, defaultIp, keyboard);
21462106
}

0 commit comments

Comments
 (0)