Skip to content

Commit 98ae204

Browse files
JayapalUradiAbhinandan Prateek
authored andcommitted
giving diff ip to VR
Signed-off-by: Abhinandan Prateek <aprateek@apache.org>
1 parent 63f47e4 commit 98ae204

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

server/src/com/cloud/network/guru/GuestNetworkGuru.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
import com.cloud.vm.VirtualMachine;
7474
import com.cloud.vm.VirtualMachineProfile;
7575
import com.cloud.vm.dao.NicDao;
76+
import com.cloud.network.Network.Provider;
77+
import com.cloud.network.Network.Service;
7678

7779
@Local(value = NetworkGuru.class)
7880
public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
@@ -361,16 +363,29 @@ public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfil
361363
if (nic.getIp4Address() == null) {
362364
nic.setBroadcastUri(network.getBroadcastUri());
363365
nic.setIsolationUri(network.getBroadcastUri());
366+
nic.setGateway(network.getGateway());
364367

365368
String guestIp = null;
366369
if (network.getSpecifyIpRanges()) {
367370
_networkMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIp());
368371
} 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;
370374
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) {
371387
guestIp = network.getGateway();
372388
} else {
373-
nic.setGateway(network.getGateway());
374389
guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIp());
375390
if (guestIp == null) {
376391
throw new InsufficientVirtualNetworkCapcityException("Unable to acquire Guest IP" +

0 commit comments

Comments
 (0)