Skip to content

Commit fe710ed

Browse files
committed
CLOUDSTACK-10212: Update Netmask/Gateway when Changing IPv4 address
This can otherwise cause problems in Basic Networking where multiple IPv4 ranges are configured in a POD. Signed-off-by: Wido den Hollander <wido@widodh.nl>
1 parent bf4f1bb commit fe710ed

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
import com.cloud.dc.dao.DedicatedResourceDao;
138138
import com.cloud.dc.dao.HostPodDao;
139139
import com.cloud.dc.dao.VlanDao;
140+
import com.cloud.dc.Vlan;
140141
import com.cloud.dc.Vlan.VlanType;
141142
import com.cloud.dc.VlanVO;
142143
import com.cloud.deploy.DataCenterDeployment;
@@ -1566,6 +1567,11 @@ public UserVm updateNicIpForVirtualMachine(UpdateVmNicIpCmd cmd) {
15661567
if (ipaddr == null) {
15671568
throw new InvalidParameterValueException("Allocating ip to guest nic " + nicVO.getUuid() + " failed, please choose another ip");
15681569
}
1570+
1571+
final Vlan vlan = _vlanDao.findById(_ipAddressDao.findByIpAndDcId(dc.getId(), ipaddr).getVlanId());
1572+
nicVO.setIPv4Gateway(vlan.getVlanGateway());
1573+
nicVO.setIPv4Netmask(vlan.getVlanNetmask());
1574+
15691575
final IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nicVO.getNetworkId(), nicVO.getIPv4Address());
15701576
if (ip != null) {
15711577
Transaction.execute(new TransactionCallbackNoReturn() {
@@ -1585,7 +1591,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
15851591
return null;
15861592
}
15871593

1588-
// update nic ipaddress
1594+
s_logger.debug("Updating IPv4 address of NIC " + nicVO + " to " + ipaddr + "/" + nicVO.getIPv4Netmask() + " with gateway " + nicVO.getIPv4Gateway());
15891595
nicVO.setIPv4Address(ipaddr);
15901596
_nicDao.persist(nicVO);
15911597

0 commit comments

Comments
 (0)