|
73 | 73 | import com.cloud.vm.VirtualMachine; |
74 | 74 | import com.cloud.vm.VirtualMachineProfile; |
75 | 75 | import com.cloud.vm.dao.NicDao; |
| 76 | +import com.cloud.network.Network.Provider; |
| 77 | +import com.cloud.network.Network.Service; |
76 | 78 |
|
77 | 79 | @Local(value = NetworkGuru.class) |
78 | 80 | public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGuru { |
@@ -361,16 +363,29 @@ public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfil |
361 | 363 | if (nic.getIp4Address() == null) { |
362 | 364 | nic.setBroadcastUri(network.getBroadcastUri()); |
363 | 365 | nic.setIsolationUri(network.getBroadcastUri()); |
| 366 | + nic.setGateway(network.getGateway()); |
364 | 367 |
|
365 | 368 | String guestIp = null; |
366 | 369 | if (network.getSpecifyIpRanges()) { |
367 | 370 | _networkMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIp()); |
368 | 371 | } else { |
369 | | - //if Vm is router vm, set ip4 to the network gateway |
| 372 | + //if Vm is router vm and source nat is enabled in the network, set ip4 to the network gateway |
| 373 | + boolean isGateway = false; |
370 | 374 | if (vm.getVirtualMachine().getType() == VirtualMachine.Type.DomainRouter) { |
| 375 | + if (network.getVpcId() != null) { |
| 376 | + if (_networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.SourceNat, Provider.VPCVirtualRouter)) { |
| 377 | + isGateway = true; |
| 378 | + } |
| 379 | + } else { |
| 380 | + if (_networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.SourceNat, Provider.VirtualRouter)) { |
| 381 | + isGateway = true; |
| 382 | + } |
| 383 | + } |
| 384 | + } |
| 385 | + |
| 386 | + if (isGateway) { |
371 | 387 | guestIp = network.getGateway(); |
372 | 388 | } else { |
373 | | - nic.setGateway(network.getGateway()); |
374 | 389 | guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIp()); |
375 | 390 | if (guestIp == null) { |
376 | 391 | throw new InsufficientVirtualNetworkCapcityException("Unable to acquire Guest IP" + |
|
0 commit comments