Skip to content

Commit 8015100

Browse files
committed
Address review comments
1 parent 1367e43 commit 8015100

File tree

13 files changed

+235
-16
lines changed

13 files changed

+235
-16
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ jobs:
146146
smoke/test_vm_snapshot_kvm
147147
smoke/test_vm_snapshots
148148
smoke/test_volumes
149+
smoke/test_vpc_conserve_mode
149150
smoke/test_vpc_ipv6
150151
smoke/test_vpc_redundant
151152
smoke/test_vpc_router_nics

api/src/main/java/com/cloud/network/NetworkService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,6 @@ Network createPrivateNetwork(String networkName, String displayText, long physic
275275
IpAddresses getIpAddressesFromIps(String ipAddress, String ip6Address, String macAddress);
276276

277277
String getNicVlanValueForExternalVm(NicTO nic);
278+
279+
Long getPreferredNetworkIdForPublicIpRuleAssignment(IpAddress ip, Long networkId);
278280
}

api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd {
163163

164164
@Parameter(name = ApiConstants.CONSERVE_MODE, type = CommandType.BOOLEAN,
165165
since = "4.23.0",
166-
description = "True if the VPC offering is IP conserve mode enabled, allowing public IP services to be used across multiple VPC tiers")
166+
description = "True if the VPC offering is IP conserve mode enabled, allowing public IPs to be used across multiple VPC tiers. Default value is false")
167167
private Boolean conserveMode;
168168

169169

api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
5555
public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements PortForwardingRule {
5656

57-
5857
// ///////////////////////////////////////////////////
5958
// ////////////// API parameters /////////////////////
6059
// ///////////////////////////////////////////////////
@@ -278,13 +277,7 @@ public State getState() {
278277
@Override
279278
public long getNetworkId() {
280279
IpAddress ip = _entityMgr.findById(IpAddress.class, getIpAddressId());
281-
Long ntwkId = null;
282-
283-
if (ip.getVpcId() == null && ip.getAssociatedWithNetworkId() != null) {
284-
ntwkId = ip.getAssociatedWithNetworkId();
285-
} else {
286-
ntwkId = networkId;
287-
}
280+
Long ntwkId = _networkService.getPreferredNetworkIdForPublicIpRuleAssignment(ip, networkId);
288281
if (ntwkId == null) {
289282
throw new InvalidParameterValueException("Unable to create port forwarding rule for the ipAddress id=" + ipAddressId +
290283
" as ip is not associated with any network and no networkId is passed in");

api/src/main/java/org/apache/cloudstack/api/response/VpcOfferingResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public class VpcOfferingResponse extends BaseResponse {
103103
private String routingMode;
104104

105105
@SerializedName(ApiConstants.CONSERVE_MODE)
106-
@Param(description = "True if the VPC offering is IP conserve mode enabled, allowing public IP services to be used across multiple VPC tiers.")
106+
@Param(description = "True if the VPC offering is IP conserve mode enabled, allowing public IP services to be used across multiple VPC tiers.", since = "4.23.0")
107107
private Boolean conserveMode;
108108

109109
public void setId(String id) {

engine/components-api/src/main/java/com/cloud/network/IpAddressManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,6 @@ List<IPAddressVO> listAvailablePublicIps(final long dcId,
288288
PublicIpQuarantine updatePublicIpAddressInQuarantine(Long quarantineProcessId, Date endDate);
289289

290290
void updateSourceNatIpAddress(IPAddressVO requestedIp, List<IPAddressVO> userIps) throws Exception;
291+
292+
Long getPreferredNetworkIdForPublicIpRuleAssignment(IpAddress ip, Long networkId);
291293
}

server/src/main/java/com/cloud/network/IpAddressManagerImpl.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,4 +2659,31 @@ public void updateSourceNatIpAddress(IPAddressVO requestedIp, List<IPAddressVO>
26592659
});
26602660
}
26612661

2662+
@Override
2663+
public Long getPreferredNetworkIdForPublicIpRuleAssignment(IpAddress ip, Long networkId) {
2664+
boolean vpcConserveMode = isPublicIpOnVpcConserveMode(ip);
2665+
return getPreferredNetworkIdForRule(ip, vpcConserveMode, networkId);
2666+
}
2667+
2668+
protected Long getPreferredNetworkIdForRule(IpAddress ip, boolean vpcConserveModeEnabled, Long networkId) {
2669+
if (vpcConserveModeEnabled) {
2670+
// Since VPC Conserve mode allows rules from multiple VPC tiers, always check the networkId parameter first
2671+
return networkId != null ? networkId : ip.getAssociatedWithNetworkId();
2672+
} else {
2673+
// In case of Guest Networks or VPC Tier Networks VPC Conserve mode disabled prefer the associated networkId
2674+
return ip.getAssociatedWithNetworkId() != null ? ip.getAssociatedWithNetworkId() : networkId;
2675+
}
2676+
}
2677+
2678+
protected boolean isPublicIpOnVpcConserveMode(IpAddress ip) {
2679+
if (ip.getVpcId() == null) {
2680+
return false;
2681+
}
2682+
Vpc vpc = _vpcMgr.getActiveVpc(ip.getVpcId());
2683+
if (vpc == null) {
2684+
return false;
2685+
}
2686+
VpcOffering vpcOffering = vpcOfferingDao.findById(vpc.getVpcOfferingId());
2687+
return vpcOffering != null && vpcOffering.isConserveMode();
2688+
}
26622689
}

server/src/main/java/com/cloud/network/NetworkServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6415,6 +6415,11 @@ public String getNicVlanValueForExternalVm(NicTO nic) {
64156415
return Networks.BroadcastDomainType.getValue(nic.getBroadcastUri());
64166416
}
64176417

6418+
@Override
6419+
public Long getPreferredNetworkIdForPublicIpRuleAssignment(IpAddress ip, Long networkId) {
6420+
return _ipAddrMgr.getPreferredNetworkIdForPublicIpRuleAssignment(ip, networkId);
6421+
}
6422+
64186423
@Override
64196424
public Network.IpAddresses getIpAddressesFromIps(String ipAddress, String ip6Address, String macAddress) {
64206425
if (ip6Address != null) {

server/src/main/java/com/cloud/network/firewall/FirewallManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ public void detectRulesConflict(FirewallRule newRule) throws NetworkRuleConflict
457457
&& rule.getNetworkId() != newRule.getNetworkId() && rule.getState() != State.Revoke) {
458458
String errMsg = String.format("New rule is for a different network than what's specified in rule %s", rule.getXid());
459459
if (newRuleIsOnVpcNetwork) {
460-
errMsg += String.format(" - VPC id=%s is not using conserve mode", newRuleNetwork.getVpcId());
460+
Vpc vpc = _vpcMgr.getActiveVpc(newRuleNetwork.getVpcId());
461+
errMsg += String.format(" - VPC id=%s is not using conserve mode", vpc.getUuid());
461462
}
462463
throw new NetworkRuleConflictException(errMsg);
463464
}

server/src/main/java/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@ public LoadBalancer createPublicLoadBalancer(final String xId, final String name
18531853

18541854
_accountMgr.checkAccess(caller.getCallingAccount(), null, true, ipAddr);
18551855

1856-
final Long networkId = ipAddr.getVpcId() == null ? ipAddr.getAssociatedWithNetworkId() : networkIdParam;
1856+
final Long networkId = _ipAddrMgr.getPreferredNetworkIdForPublicIpRuleAssignment(ipAddr, networkIdParam);
18571857
if (networkId == null) {
18581858
InvalidParameterValueException ex =
18591859
new InvalidParameterValueException("Unable to create load balancer rule ; specified sourceip id is not associated with any network");

0 commit comments

Comments
 (0)