protected synchronized String attachOrDetachDevice(final Connect conn, final boolean attach, final String vmName, final String xml) throws LibvirtException, InternalErrorException { Domain dm = null; try { dm = conn.domainLookupByName(vmName); if (attach) { s_logger.debug("Attaching device: " + xml); dm.attachDevice(xml); } else { s_logger.debug("Detaching device: " + xml); dm.detachDevice(xml); } } catch (final LibvirtException e) { if (attach) { s_logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage()); } else { s_logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage()); } throw e; } finally { if (dm != null) { try { dm.free(); } catch (final LibvirtException l) { s_logger.trace("Ignoring libvirt error.", l); } } } return null; }
protected synchronized String attachOrDetachDevice(final Connect conn, final boolean attach, final String vmName, final String xml) throws LibvirtException, InternalErrorException { Domain dm = null; try { dm = conn.domainLookupByName(vmName); if (attach) { s_logger.debug("Attaching device: " + xml); dm.attachDevice(xml); } else { s_logger.debug("Detaching device: " + xml); dm.detachDevice(xml); } } catch (final LibvirtException e) { if (attach) { s_logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage()); } else { s_logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage()); } throw e; } finally { if (dm != null) { try { dm.free(); } catch (final LibvirtException l) { s_logger.trace("Ignoring libvirt error.", l); } } } return null; }
private void vifHotUnPlug (final Connect conn, final String vmName, final String macAddr) throws InternalErrorException, LibvirtException { Domain vm = null; vm = getDomain(conn, vmName); final List<InterfaceDef> pluggedNics = getInterfaces(conn, vmName); for (final 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 (final VifDriver vifDriver : getAllVifDrivers()) { vifDriver.unplug(pluggedNic); } } } }
vm.detachDevice(pluggedNic.toString());
i++; s_logger.debug("ReplugNic: Detaching interface" + oldPluggedNic + " (Attempt: " + i + ")"); vm.detachDevice(oldPluggedNic.toString()); } while (findPluggedNic(libvirtComputingResource, nic, vmName, conn) != null && i <= 10);