本文整理汇总了Java中org.libvirt.Domain.detachDevice方法的典型用法代码示例。如果您正苦于以下问题:Java Domain.detachDevice方法的具体用法?Java Domain.detachDevice怎么用?Java Domain.detachDevice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.libvirt.Domain
的用法示例。
在下文中一共展示了Domain.detachDevice方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: vifHotUnPlug
import org.libvirt.Domain; //导入方法依赖的package包/类
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);
}
}
}
}
示例2: execute
import org.libvirt.Domain; //导入方法依赖的package包/类
@Override
public Answer execute(final UnPlugNicCommand command, final LibvirtComputingResource libvirtComputingResource) {
final NicTO nic = command.getNic();
final String vmName = command.getVmName();
Domain vm = null;
try {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vmName);
vm = libvirtComputingResource.getDomain(conn, vmName);
final List<InterfaceDef> pluggedNics = libvirtComputingResource.getInterfaces(conn, vmName);
for (final InterfaceDef pluggedNic : pluggedNics) {
if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) {
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 : libvirtComputingResource.getAllVifDrivers()) {
vifDriver.unplug(pluggedNic);
}
return new UnPlugNicAnswer(command, true, "success");
}
}
return new UnPlugNicAnswer(command, true, "success");
} catch (final LibvirtException e) {
final String msg = " Unplug Nic failed due to " + e.toString();
s_logger.warn(msg, e);
return new UnPlugNicAnswer(command, false, msg);
} finally {
if (vm != null) {
try {
vm.free();
} catch (final LibvirtException l) {
s_logger.trace("Ignoring libvirt error.", l);
}
}
}
}
示例3: attachOrDetachDevice
import org.libvirt.Domain; //导入方法依赖的package包/类
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) {
logger.debug("Attaching device: " + xml);
dm.attachDevice(xml);
} else {
logger.debug("Detaching device: " + xml);
dm.detachDevice(xml);
}
} catch (final LibvirtException e) {
if (attach) {
logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage());
} else {
logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage());
}
throw e;
} finally {
if (dm != null) {
try {
dm.free();
} catch (final LibvirtException l) {
logger.trace("Ignoring libvirt error.", l);
}
}
}
return null;
}
示例4: attachOrDetachDevice
import org.libvirt.Domain; //导入方法依赖的package包/类
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) {
logger.debug("Attaching device: " + xml);
dm.attachDevice(xml);
} else {
logger.debug("Detaching device: " + xml);
dm.detachDevice(xml);
}
} catch (final LibvirtException e) {
if (attach) {
logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage());
} else {
logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage());
}
throw e;
} finally {
if (dm != null) {
try {
dm.free();
} catch (final LibvirtException l) {
logger.trace("Ignoring libvirt error.", l);
}
}
}
return null;
}
示例5: attachOrDetachDevice
import org.libvirt.Domain; //导入方法依赖的package包/类
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;
}
示例6: attachOrDetachDevice
import org.libvirt.Domain; //导入方法依赖的package包/类
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;
}
示例7: detachDevice
import org.libvirt.Domain; //导入方法依赖的package包/类
@Override
public void detachDevice(String domainName, String deviceXml) throws LibvirtException {
LOG.debug(String.format("detachDevice(%s, %s)", domainName, deviceXml));
Domain domain = this.domainLookupByName(domainName);
if (null == domain)
throw new DomainNotFoundException();
domain.detachDevice(deviceXml);
}
示例8: execute
import org.libvirt.Domain; //导入方法依赖的package包/类
@Override
public Answer execute(final ReplugNicCommand command, final LibvirtComputingResource libvirtComputingResource) {
final NicTO nic = command.getNic();
final String vmName = command.getVmName();
Domain vm = null;
try {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vmName);
vm = libvirtComputingResource.getDomain(conn, vmName);
InterfaceDef oldPluggedNic = findPluggedNic(libvirtComputingResource, nic, vmName, conn);
final VifDriver newVifDriver = libvirtComputingResource.getVifDriver(nic.getType(), nic.getName());
final InterfaceDef interfaceDef = newVifDriver.plug(nic, "Other PV", oldPluggedNic.getModel().toString());
interfaceDef.setSlot(oldPluggedNic.getSlot());
interfaceDef.setDevName(oldPluggedNic.getDevName());
interfaceDef.setLinkStateUp(false);
oldPluggedNic.setSlot(null);
int i = 0;
do {
i++;
s_logger.debug("ReplugNic: Detaching interface" + oldPluggedNic + " (Attempt: " + i + ")");
vm.detachDevice(oldPluggedNic.toString());
} while (findPluggedNic(libvirtComputingResource, nic, vmName, conn) != null && i <= 10);
s_logger.debug("ReplugNic: Attaching interface" + interfaceDef);
vm.attachDevice(interfaceDef.toString());
interfaceDef.setLinkStateUp(true);
s_logger.debug("ReplugNic: Updating interface" + interfaceDef);
vm.updateDeviceFlags(interfaceDef.toString(), DomainAffect.LIVE.getValue());
// We don't know which "traffic type" is associated with
// each interface at this point, so inform all vif drivers
for (final VifDriver vifDriver : libvirtComputingResource.getAllVifDrivers()) {
vifDriver.unplug(oldPluggedNic);
}
return new ReplugNicAnswer(command, true, "success");
} catch (final LibvirtException | InternalErrorException e) {
final String msg = " Plug Nic failed due to " + e.toString();
s_logger.warn(msg, e);
return new ReplugNicAnswer(command, false, msg);
} finally {
if (vm != null) {
try {
vm.free();
} catch (final LibvirtException l) {
s_logger.trace("Ignoring libvirt error.", l);
}
}
}
}