Skip to content

Commit 2ec82d4

Browse files
committed
framework: configure allocated source NAT when implement a network
1 parent ebafe47 commit 2ec82d4

1 file changed

Lines changed: 4 additions & 14 deletions

File tree

framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/network/NetworkExtensionElement.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import com.cloud.dc.dao.VlanDao;
3838
import com.cloud.deploy.DeployDestination;
3939
import com.cloud.exception.ConcurrentOperationException;
40-
import com.cloud.exception.InsufficientAddressCapacityException;
4140
import com.cloud.exception.InsufficientCapacityException;
4241
import com.cloud.exception.ResourceUnavailableException;
4342
import com.cloud.host.dao.HostDao;
@@ -449,21 +448,12 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
449448
// Step 3: Configure source NAT if supported.
450449
if (canHandle(network, Service.SourceNat)) {
451450
try {
452-
Account owner = context != null ? context.getAccount() : null;
451+
Account owner = accountService.getAccount(network.getAccountId());
453452
PublicIp sourceNatIp = null;
454-
if (owner != null) {
455-
sourceNatIp = ipAddressManager.assignSourceNatIpAddressToGuestNetwork(owner, network);
453+
PublicIpAddress existingIp = networkModel.getSourceNatIpAddressForGuestNetwork(owner, network);
454+
if (existingIp != null) {
455+
applyIps(network, List.of(existingIp), Set.of(Service.SourceNat));
456456
}
457-
if (sourceNatIp == null) {
458-
PublicIpAddress existingIp = networkModel.getSourceNatIpAddressForGuestNetwork(owner, network);
459-
if (existingIp != null) {
460-
applyIps(network, List.of(existingIp), Set.of(Service.SourceNat));
461-
}
462-
} else {
463-
applyIps(network, List.of(sourceNatIp), Set.of(Service.SourceNat));
464-
}
465-
} catch (InsufficientAddressCapacityException e) {
466-
logger.warn("Could not assign source NAT IP for network {}: {}", network.getId(), e.getMessage());
467457
} catch (Exception e) {
468458
logger.warn("Failed to configure source NAT IP for network {}: {}", network.getId(), e.getMessage(), e);
469459
}

0 commit comments

Comments
 (0)