Skip to content

Commit ff7527f

Browse files
author
Jayapal
committed
CLOUDSTACK-4084 Fixed the static nat vm ip address in public ip address table in external network gc
In external network after network GC the network n/w cidr changes. In this case the static nat enable vm ip also chagnes. So updated the new vm ip address in user_ip_address table.
1 parent 41f7820 commit ff7527f

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import javax.inject.Inject;
2323

2424
import com.cloud.event.ActionEventUtils;
25+
import com.cloud.network.dao.IPAddressDao;
26+
import com.cloud.network.dao.IPAddressVO;
2527
import org.apache.log4j.Logger;
2628

2729
import com.cloud.configuration.Config;
@@ -70,6 +72,9 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
7072
DataCenterDao _zoneDao;
7173
@Inject
7274
PortForwardingRulesDao _pfRulesDao;
75+
@Inject
76+
IPAddressDao _ipAddressDao;
77+
7378

7479
public ExternalGuestNetworkGuru() {
7580
super();
@@ -191,6 +196,17 @@ public Network implement(Network config, NetworkOffering offering, DeployDestina
191196
_pfRulesDao.update(pfRule.getId(), pfRule);
192197
}
193198
}
199+
// Mask the destination address of all static nat rules in this network with the new guest VLAN offset
200+
// Here the private ip of the nic get updated. When secondary ip are present the gc will not triggered
201+
List <IPAddressVO> ipAddrsOfNw = _ipAddressDao.listStaticNatPublicIps(config.getId());
202+
for (IPAddressVO ip: ipAddrsOfNw) {
203+
if (ip.getVmIp() != null) {
204+
long ipMask = getIpMask(ip.getVmIp(), cidrSize);
205+
String maskedVmIp = NetUtils.long2Ip(newCidrAddress | ipMask);
206+
ip.setVmIp(maskedVmIp);
207+
_ipAddressDao.update(ip.getId(), ip);
208+
}
209+
}
194210

195211
return implemented;
196212
}

0 commit comments

Comments
 (0)