diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 34770e4164d..ab7b9b54551 100755 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -1789,6 +1789,23 @@ ServerResource { return new Answer(cmd, true, result); } + private void vifHotUnPlug (Connect conn, String vmName, String macAddr) throws InternalErrorException, LibvirtException { + + Domain vm = null; + vm = getDomain(conn, vmName); + List pluggedNics = getInterfaces(conn, vmName); + for (InterfaceDef pluggedNic : pluggedNics) { + if (pluggedNic.getMacAddress().equalsIgnoreCase(macAddr)) { + vm.detachDevice(pluggedNic.toString()); + // We don't know which "traffic type" is associated with + // each interface at this point, so inform all vif drivers + for (VifDriver vifDriver : getAllVifDrivers()) { + vifDriver.unplug(pluggedNic); + } + } + } + } + private void VifHotPlug(Connect conn, String vmName, String broadcastUri, String macAddr) throws InternalErrorException, LibvirtException { NicTO nicTO = new NicTO(); @@ -2103,6 +2120,12 @@ ServerResource { String result = null; int nicNum = 0; boolean newNic = false; + int numOfIps = 0; + + if (ips != null) { + numOfIps = ips.length; + } + for (IpAddressTO ip : ips) { if (!broadcastUriAllocatedToVM.containsKey(ip.getBroadcastUri())) { /* plug a vif into router */ @@ -2121,6 +2144,14 @@ ServerResource { if (result == null) { results[i++] = ip.getPublicIp() + " - success"; } + + //there is only only ip in public subnet and it is deleted so unplug the vif + if (numOfIps == 1 && !ip.isAdd()) { + // There are no ips on the vm so delete the vif + networkUsage(routerIp, "deleteVif", "eth" + nicNum); + vifHotUnPlug(conn, routerName, ip.getVifMacAddress()); + } + } return new IpAssocAnswer(cmd, results); } catch (LibvirtException e) { diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index b398ca517b7..7199d287ac0 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -2372,7 +2372,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe protected void assignPublicIpAddress(Connection conn, String vmName, String privateIpAddress, String publicIpAddress, boolean add, boolean firstIP, - boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress, Integer networkRate, TrafficType trafficType, String name) throws InternalErrorException { + boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress, Integer networkRate, TrafficType trafficType, String name, + int numOfips) throws InternalErrorException { try { VM router = getVM(conn, vmName); @@ -2463,6 +2464,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe throw new InternalErrorException("Xen plugin \"ipassoc\" failed."); } + //there is only only ip in public subnet and it is deleted so unplug the vif + if (numOfips == 1 && !add) { + removeVif = true; + } + if (removeVif) { network = correctVif.getNetwork(conn); @@ -2564,14 +2570,19 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe Connection conn = getConnection(); String[] results = new String[cmd.getIpAddresses().length]; int i = 0; + int numOfIps = 0; String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); try { IpAddressTO[] ips = cmd.getIpAddresses(); + if (ips != null) { + numOfIps = ips.length; + } + for (IpAddressTO ip : ips) { assignPublicIpAddress(conn, routerName, routerIp, ip.getPublicIp(), ip.isAdd(), ip.isFirstIP(), ip.isSourceNat(), ip.getBroadcastUri(), - ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress(), ip.getNetworkRate(), ip.getTrafficType(), ip.getNetworkName()); + ip.getVlanGateway(), ip.getVlanNetmask(), ip.getVifMacAddress(), ip.getNetworkRate(), ip.getTrafficType(), ip.getNetworkName(), numOfIps); results[i++] = ip.getPublicIp() + " - success"; } } catch (InternalErrorException e) {