Skip to content

Commit 7700a1b

Browse files
author
Jayapal
committed
CLOUDSTACK-6183: unplug the nic when all the ips of public vlan range is removed
1 parent 793a6a7 commit 7700a1b

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,23 @@ private Answer execute(PvlanSetupCommand cmd) {
17891789
return new Answer(cmd, true, result);
17901790
}
17911791

1792+
private void vifHotUnPlug (Connect conn, String vmName, String macAddr) throws InternalErrorException, LibvirtException {
1793+
1794+
Domain vm = null;
1795+
vm = getDomain(conn, vmName);
1796+
List<InterfaceDef> pluggedNics = getInterfaces(conn, vmName);
1797+
for (InterfaceDef pluggedNic : pluggedNics) {
1798+
if (pluggedNic.getMacAddress().equalsIgnoreCase(macAddr)) {
1799+
vm.detachDevice(pluggedNic.toString());
1800+
// We don't know which "traffic type" is associated with
1801+
// each interface at this point, so inform all vif drivers
1802+
for (VifDriver vifDriver : getAllVifDrivers()) {
1803+
vifDriver.unplug(pluggedNic);
1804+
}
1805+
}
1806+
}
1807+
}
1808+
17921809
private void VifHotPlug(Connect conn, String vmName, String broadcastUri,
17931810
String macAddr) throws InternalErrorException, LibvirtException {
17941811
NicTO nicTO = new NicTO();
@@ -2103,6 +2120,12 @@ public Answer execute(IpAssocCommand cmd) {
21032120
String result = null;
21042121
int nicNum = 0;
21052122
boolean newNic = false;
2123+
int numOfIps = 0;
2124+
2125+
if (ips != null) {
2126+
numOfIps = ips.length;
2127+
}
2128+
21062129
for (IpAddressTO ip : ips) {
21072130
if (!broadcastUriAllocatedToVM.containsKey(ip.getBroadcastUri())) {
21082131
/* plug a vif into router */
@@ -2121,6 +2144,14 @@ public Answer execute(IpAssocCommand cmd) {
21212144
if (result == null) {
21222145
results[i++] = ip.getPublicIp() + " - success";
21232146
}
2147+
2148+
//there is only only ip in public subnet and it is deleted so unplug the vif
2149+
if (numOfIps == 1 && !ip.isAdd()) {
2150+
// There are no ips on the vm so delete the vif
2151+
networkUsage(routerIp, "deleteVif", "eth" + nicNum);
2152+
vifHotUnPlug(conn, routerName, ip.getVifMacAddress());
2153+
}
2154+
21242155
}
21252156
return new IpAssocAnswer(cmd, results);
21262157
} catch (LibvirtException e) {

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,8 @@ protected Answer execute(final SavePasswordCommand cmd) {
23722372

23732373

23742374
protected void assignPublicIpAddress(Connection conn, String vmName, String privateIpAddress, String publicIpAddress, boolean add, boolean firstIP,
2375-
boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress, Integer networkRate, TrafficType trafficType, String name) throws InternalErrorException {
2375+
boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress, Integer networkRate, TrafficType trafficType, String name,
2376+
int numOfips) throws InternalErrorException {
23762377

23772378
try {
23782379
VM router = getVM(conn, vmName);
@@ -2463,6 +2464,11 @@ protected void assignPublicIpAddress(Connection conn, String vmName, String priv
24632464
throw new InternalErrorException("Xen plugin \"ipassoc\" failed.");
24642465
}
24652466

2467+
//there is only only ip in public subnet and it is deleted so unplug the vif
2468+
if (numOfips == 1 && !add) {
2469+
removeVif = true;
2470+
}
2471+
24662472
if (removeVif) {
24672473
network = correctVif.getNetwork(conn);
24682474

@@ -2564,14 +2570,19 @@ protected Answer execute(IpAssocCommand cmd) {
25642570
Connection conn = getConnection();
25652571
String[] results = new String[cmd.getIpAddresses().length];
25662572
int i = 0;
2573+
int numOfIps = 0;
25672574
String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
25682575
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
25692576
try {
25702577
IpAddressTO[] ips = cmd.getIpAddresses();
2578+
if (ips != null) {
2579+
numOfIps = ips.length;
2580+
}
2581+
25712582
for (IpAddressTO ip : ips) {
25722583

25732584
assignPublicIpAddress(conn, routerName, routerIp, ip.getPublicIp(), ip.isAdd(), ip.isFirstIP(), ip.isSourceNat(), ip.getBroadcastUri(),
2574-
ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress(), ip.getNetworkRate(), ip.getTrafficType(), ip.getNetworkName());
2585+
ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress(), ip.getNetworkRate(), ip.getTrafficType(), ip.getNetworkName(), numOfIps);
25752586
results[i++] = ip.getPublicIp() + " - success";
25762587
}
25772588
} catch (InternalErrorException e) {

0 commit comments

Comments
 (0)