Skip to content

Commit 7ff49cb

Browse files
author
Jayapal
committed
CLOUDSTACK-6240 Fixed updating advanced SG rules for vm nic secondary ip
1 parent 63563b7 commit 7ff49cb

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

‎api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ private NetworkType getNetworkType() {
9292
return dc.getNetworkType();
9393
}
9494

95+
private boolean isZoneSGEnabled() {
96+
Network ntwk = _entityMgr.findById(Network.class, getNetworkId());
97+
DataCenter dc = _entityMgr.findById(DataCenter.class, ntwk.getDataCenterId());
98+
return dc.isSecurityGroupEnabled();
99+
}
100+
95101
@Override
96102
public String getEventType() {
97103
return EventTypes.EVENT_NET_IP_ASSIGN;
@@ -136,7 +142,7 @@ public void execute() throws ResourceUnavailableException, ResourceAllocationExc
136142

137143
if (result != null) {
138144
secondaryIp = result.getIp4Address();
139-
if (getNetworkType() == NetworkType.Basic) {
145+
if (isZoneSGEnabled()) {
140146
// add security group rules for the secondary ip addresses
141147
boolean success = false;
142148
success = _securityGroupService.securityGroupRulesForVmSecIp(getNicId(), secondaryIp, true);

‎api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ public NetworkType getNetworkType() {
131131
return null;
132132
}
133133

134+
135+
private boolean isZoneSGEnabled() {
136+
Network ntwk = _entityMgr.findById(Network.class, getNetworkId());
137+
DataCenter dc = _entityMgr.findById(DataCenter.class, ntwk.getDataCenterId());
138+
return dc.isSecurityGroupEnabled();
139+
}
140+
134141
@Override
135142
public void execute() throws InvalidParameterValueException {
136143
CallContext.current().setEventDetails("Ip Id: " + id);
@@ -140,7 +147,7 @@ public void execute() throws InvalidParameterValueException {
140147
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Invalid IP id is passed");
141148
}
142149

143-
if (getNetworkType() == NetworkType.Basic) {
150+
if (isZoneSGEnabled()) {
144151
//remove the security group rules for this secondary ip
145152
boolean success = false;
146153
success = _securityGroupService.securityGroupRulesForVmSecIp(nicSecIp.getNicId(), nicSecIp.getIp4Address(), false);

‎server/src/com/cloud/network/security/SecurityGroupManagerImpl.java‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,16 +1350,17 @@ public boolean securityGroupRulesForVmSecIp(long nicId, String secondaryIp, bool
13501350

13511351
// Validate parameters
13521352
List<SecurityGroupVO> vmSgGrps = getSecurityGroupsForVm(vmId);
1353-
if (vmSgGrps == null) {
1353+
if (vmSgGrps.isEmpty()) {
13541354
s_logger.debug("Vm is not in any Security group ");
13551355
return true;
13561356
}
13571357

1358-
for (SecurityGroupVO securityGroup : vmSgGrps) {
1359-
Account owner = _accountMgr.getAccount(securityGroup.getAccountId());
1360-
if (owner == null) {
1361-
throw new InvalidParameterValueException("Unable to find security group owner by id=" + securityGroup.getAccountId());
1362-
}
1358+
//If network does not support SG service, no need add SG rules for secondary ip
1359+
Network network = _networkModel.getNetwork(nic.getNetworkId());
1360+
if (!_networkModel.isSecurityGroupSupportedInNetwork(network)) {
1361+
s_logger.debug("Network " + network + " is not enabled with security group service, "+
1362+
"so not applying SG rules for secondary ip");
1363+
return true;
13631364
}
13641365

13651366
String vmMac = vm.getPrivateMacAddress();

0 commit comments

Comments
 (0)