|
37 | 37 | import com.cloud.dc.dao.VlanDao; |
38 | 38 | import com.cloud.deploy.DeployDestination; |
39 | 39 | import com.cloud.exception.ConcurrentOperationException; |
40 | | -import com.cloud.exception.InsufficientAddressCapacityException; |
41 | 40 | import com.cloud.exception.InsufficientCapacityException; |
42 | 41 | import com.cloud.exception.ResourceUnavailableException; |
43 | 42 | import com.cloud.host.dao.HostDao; |
@@ -449,21 +448,12 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin |
449 | 448 | // Step 3: Configure source NAT if supported. |
450 | 449 | if (canHandle(network, Service.SourceNat)) { |
451 | 450 | try { |
452 | | - Account owner = context != null ? context.getAccount() : null; |
| 451 | + Account owner = accountService.getAccount(network.getAccountId()); |
453 | 452 | 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)); |
456 | 456 | } |
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()); |
467 | 457 | } catch (Exception e) { |
468 | 458 | logger.warn("Failed to configure source NAT IP for network {}: {}", network.getId(), e.getMessage(), e); |
469 | 459 | } |
|
0 commit comments