Skip to content

Commit bd78030

Browse files
ustcweizhouyadvr
authored andcommitted
server: update dhcp configurations in vrs while update default nic of running vms (#3205)
In virtual routers, there are different dnsmasq settings for default nic and non-default nic on vm. We need to update dhcp informations on network vrs when default nic is changed. For example, if 172.16.1.135 is non-default nic of vm VPC1-001-001, then root@r-22-VM:~# cat /etc/dhcphosts.txt 02:00:1d:15:00:05,set:172_16_1_135,172.16.1.135,VPC1-001-001,710h root@r-22-VM:~# cat /etc/dhcpopts.txt 172_16_1_135,3 172_16_1_135,6 172_16_1_135,15 If it is default nic,then root@r-22-VM:~# cat /etc/dhcpopts.txt root@r-22-VM:~# cat /etc/dhcphosts.txt 02:00:1d:15:00:05,172.16.1.135,VPC1-001-001,757h Fixes #3201
1 parent 8c387f9 commit bd78030

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

server/src/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,19 @@ public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) th
14481448
newNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid(), vmInstance.isDisplay());
14491449
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmInstance.getAccountId(), vmInstance.getDataCenterId(), vmInstance.getId(),
14501450
oldNicIdString, oldNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid(), vmInstance.isDisplay());
1451+
1452+
if (vmInstance.getState() != State.Stopped) {
1453+
try {
1454+
VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance);
1455+
User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
1456+
ReservationContext context = new ReservationContextImpl(null, null, callerUser, caller);
1457+
DeployDestination dest = new DeployDestination(dc, null, null, null);
1458+
_networkMgr.prepare(vmProfile, dest, context);
1459+
} catch (final Exception e) {
1460+
s_logger.info("Got exception: ", e);
1461+
}
1462+
}
1463+
14511464
return _vmDao.findById(vmInstance.getId());
14521465
}
14531466

0 commit comments

Comments
 (0)