本文整理汇总了Java中org.libvirt.LibvirtException类的典型用法代码示例。如果您正苦于以下问题:Java LibvirtException类的具体用法?Java LibvirtException怎么用?Java LibvirtException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LibvirtException类属于org.libvirt包,在下文中一共展示了LibvirtException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getConnectionByVmName
import org.libvirt.LibvirtException; //导入依赖的package包/类
public static Connect getConnectionByVmName(final String vmName) throws LibvirtException {
final HypervisorType[] hypervisors = new HypervisorType[]{HypervisorType.KVM};
for (final HypervisorType hypervisor : hypervisors) {
try {
final Connect conn = LibvirtConnection.getConnectionByType(hypervisor.toString());
if (conn.domainLookupByName(vmName) != null) {
return conn;
}
} catch (final Exception e) {
LOGGER.debug(
"Can not find " + hypervisor.toString() + " connection for Instance: " + vmName + ", continuing.");
}
}
LOGGER.warn("Can not find a connection for Instance " + vmName + ". Assuming the default connection.");
// return the default connection
return getConnection();
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:20,代码来源:LibvirtConnection.java
示例2: execute
import org.libvirt.LibvirtException; //导入依赖的package包/类
@Override
public Answer execute(final NetworkRulesVmSecondaryIpCommand command,
final LibvirtComputingResource libvirtComputingResource) {
boolean result = false;
try {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName());
result = libvirtComputingResource.configureNetworkRulesVmSecondaryIp(conn, command.getVmName(),
command.getVmSecIp(), command.getAction());
} catch (final LibvirtException e) {
s_logger.debug("Could not configure VM secondary IP! => " + e.getLocalizedMessage());
}
return new Answer(command, result, "");
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:LibvirtNetworkRulesVmSecondaryIpCommandWrapper.java
示例3: execute
import org.libvirt.LibvirtException; //导入依赖的package包/类
@Override
public Answer execute(final CheckVirtualMachineCommand command,
final LibvirtComputingResource libvirtComputingResource) {
try {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName());
final PowerState state = libvirtComputingResource.getVmState(conn, command.getVmName());
Integer vncPort = null;
if (state == PowerState.PowerOn) {
vncPort = libvirtComputingResource.getVncPort(conn, command.getVmName());
}
return new CheckVirtualMachineAnswer(command, state, vncPort);
} catch (final LibvirtException e) {
return new CheckVirtualMachineAnswer(command, e.getMessage());
}
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:19,代码来源:LibvirtCheckVirtualMachineCommandWrapper.java
示例4: prepareNetworkElementCommand
import org.libvirt.LibvirtException; //导入依赖的package包/类
protected ExecutionResult prepareNetworkElementCommand(final UpdateNetworkOverviewCommand cmd) {
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
try {
final Connect conn = LibvirtConnection.getConnectionByVmName(routerName);
final Map<String, Integer> bridgeToNicNum = new HashMap<>();
final List<InterfaceDef> pluggedNics = getInterfaces(conn, routerName);
buildBridgeToNicNumHashMap(bridgeToNicNum, pluggedNics);
return new ExecutionResult(true, null);
} catch (final LibvirtException e) {
logger.error("Ip Assoc failure on applying one ip due to exception: ", e);
return new ExecutionResult(false, e.getMessage());
}
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:LibvirtComputingResource.java
示例5: vifHotPlug
import org.libvirt.LibvirtException; //导入依赖的package包/类
private void vifHotPlug(final Connect conn, final String vmName, final String broadcastUri, final String macAddr)
throws InternalErrorException, LibvirtException {
final NicTO nicTo = new NicTO();
nicTo.setMac(macAddr);
nicTo.setType(TrafficType.Public);
if (broadcastUri == null) {
nicTo.setBroadcastType(BroadcastDomainType.Native);
} else {
final URI uri = BroadcastDomainType.fromString(broadcastUri);
nicTo.setBroadcastType(BroadcastDomainType.getSchemeValue(uri));
nicTo.setBroadcastUri(uri);
}
final Domain vm = getDomain(conn, vmName);
vm.attachDevice(getVifDriver(nicTo.getType()).plug(nicTo, "Default - VirtIO capable OS (64-bit)", "").toString());
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:LibvirtComputingResource.java
示例6: initConnectionToLibvirtDaemon
import org.libvirt.LibvirtException; //导入依赖的package包/类
private void initConnectionToLibvirtDaemon(final LibvirtComputingResourceProperties libvirtComputingResourceProperties) throws ConfigurationException {
LibvirtConnection.initialize(getHypervisorUri());
final Connect conn = connectToHypervisor();
checkIsHvmEnabled(conn);
hypervisorPath = getHypervisorPath(conn);
try {
hvVersion = conn.getVersion();
hvVersion = hvVersion % 1000000 / 1000;
hypervisorLibvirtVersion = conn.getLibVirVersion();
hypervisorQemuVersion = conn.getVersion();
} catch (final LibvirtException e) {
logger.trace("Ignoring libvirt error.", e);
}
if (libvirtComputingResourceProperties.hasGuestCpuMode()) {
if (hypervisorLibvirtVersion < 9 * 1000 + 10) {
logger.warn("Libvirt version 0.9.10 required for guest cpu mode, but version {} detected, so it will be disabled", prettyVersion(hypervisorLibvirtVersion));
libvirtComputingResourceProperties.unsetGuestCpuMode();
libvirtComputingResourceProperties.unsetGuestCpuModel();
}
}
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:25,代码来源:LibvirtComputingResource.java
示例7: connectToHypervisor
import org.libvirt.LibvirtException; //导入依赖的package包/类
private Connect connectToHypervisor() throws ConfigurationException {
Connect conn = null;
try {
conn = LibvirtConnection.getConnection();
if (getBridgeType() == OPENVSWITCH) {
if (conn.getLibVirVersion() < 10 * 1000 + 0) {
throw new ConfigurationException("Libvirt version 0.10.0 required for openvswitch support, but version "
+ conn.getLibVirVersion() + " detected");
}
}
} catch (final LibvirtException e) {
throw new CloudRuntimeException(e.getMessage());
}
return conn;
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:LibvirtComputingResource.java
示例8: getVmState
import org.libvirt.LibvirtException; //导入依赖的package包/类
public PowerState getVmState(final Connect conn, final String vmName) {
int retry = 3;
Domain vms = null;
while (retry-- > 0) {
try {
vms = conn.domainLookupByName(vmName);
final PowerState s = convertToPowerState(vms.getInfo().state);
return s;
} catch (final LibvirtException e) {
logger.warn("Can't get vm state " + vmName + e.getMessage() + "retry:" + retry);
} finally {
try {
if (vms != null) {
vms.free();
}
} catch (final LibvirtException l) {
logger.trace("Ignoring libvirt error.", l);
}
}
}
return PowerState.PowerOff;
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:23,代码来源:LibvirtComputingResource.java
示例9: createVifs
import org.libvirt.LibvirtException; //导入依赖的package包/类
public void createVifs(final VirtualMachineTO vmSpec, final LibvirtVmDef vm)
throws InternalErrorException, LibvirtException {
final NicTO[] nics = vmSpec.getNics();
final Map<String, String> params = vmSpec.getDetails();
String nicAdapter = "";
if (params != null && params.get("nicAdapter") != null && !params.get("nicAdapter").isEmpty()) {
nicAdapter = params.get("nicAdapter");
}
for (int i = 0; i < nics.length; i++) {
for (final NicTO nic : vmSpec.getNics()) {
if (nic.getDeviceId() == i) {
createVif(vm, nic, nicAdapter);
}
}
}
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:LibvirtComputingResource.java
示例10: createVif
import org.libvirt.LibvirtException; //导入依赖的package包/类
private void createVif(final LibvirtVmDef vm, final NicTO nic, final String nicAdapter)
throws InternalErrorException, LibvirtException {
if (nic.getType().equals(TrafficType.Guest) && nic.getBroadcastType().equals(BroadcastDomainType.Vsp)) {
final String vrIp = nic.getBroadcastUri().getPath().substring(1);
if (logger.isDebugEnabled()) {
logger.debug("NIC with MAC " + nic.getMac() + " and BroadcastDomainType " + nic.getBroadcastType()
+ " in network(" + nic.getGateway() + "/" + nic.getNetmask() + ") is " + nic.getType()
+ " traffic type. So, vsp-vr-ip " + vrIp + " is set in the metadata");
}
}
vm.getDevices().addDevice(
getVifDriver(nic.getType()).plug(nic, vm.getPlatformEmulator().toString(), nicAdapter).toString());
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:LibvirtComputingResource.java
示例11: getVolumePath
import org.libvirt.LibvirtException; //导入依赖的package包/类
public String getVolumePath(final Connect conn, final DiskTO volume) throws LibvirtException, URISyntaxException {
final DataTO data = volume.getData();
final DataStoreTO store = data.getDataStore();
if (volume.getType() == Volume.Type.ISO && data.getPath() != null) {
final NfsTO nfsStore = (NfsTO) store;
final String isoPath = nfsStore.getUrl() + File.separator + data.getPath();
final int index = isoPath.lastIndexOf("/");
final String path = isoPath.substring(0, index);
final String name = isoPath.substring(index + 1);
final KvmStoragePool secondaryPool = storagePoolMgr.getStoragePoolByUri(path);
final KvmPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
return isoVol.getPath();
} else {
return data.getPath();
}
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:18,代码来源:LibvirtComputingResource.java
示例12: restoreVMSnapshotMetadata
import org.libvirt.LibvirtException; //导入依赖的package包/类
public void restoreVMSnapshotMetadata(final Domain dm, final String vmName, final List<Ternary<String, Boolean, String>> vmsnapshots) {
logger.debug("Restoring the metadata of vm snapshots of vm " + vmName);
for (final Ternary<String, Boolean, String> vmsnapshot : vmsnapshots) {
final String snapshotName = vmsnapshot.first();
final Boolean isCurrent = vmsnapshot.second();
final String snapshotXML = vmsnapshot.third();
logger.debug("Restoring vm snapshot " + snapshotName + " on " + vmName + " with XML:\n " + snapshotXML);
try {
int flags = 1; // VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE = 1
if (isCurrent) {
flags += 2; // VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT = 2
}
dm.snapshotCreateXML(snapshotXML, flags);
} catch (final LibvirtException e) {
logger.debug("Failed to restore vm snapshot " + snapshotName + ", continue");
}
}
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:19,代码来源:LibvirtComputingResource.java
示例13: getVncPort
import org.libvirt.LibvirtException; //导入依赖的package包/类
public Integer getVncPort(final Connect conn, final String vmName) throws LibvirtException {
final LibvirtDomainXmlParser parser = new LibvirtDomainXmlParser();
Domain dm = null;
try {
dm = conn.domainLookupByName(vmName);
final String xmlDesc = dm.getXMLDesc(0);
parser.parseDomainXml(xmlDesc);
return parser.getVncPort();
} finally {
try {
if (dm != null) {
dm.free();
}
} catch (final LibvirtException l) {
logger.trace("Ignoring libvirt error.", l);
}
}
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:19,代码来源:LibvirtComputingResource.java
示例14: listPhysicalDisks
import org.libvirt.LibvirtException; //导入依赖的package包/类
@Override
public List<KvmPhysicalDisk> listPhysicalDisks(final String storagePoolUuid, final KvmStoragePool pool) {
final LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
final StoragePool virtPool = libvirtPool.getPool();
final List<KvmPhysicalDisk> disks = new ArrayList<>();
try {
final String[] vols = virtPool.listVolumes();
for (final String volName : vols) {
final KvmPhysicalDisk disk = getPhysicalDisk(volName, pool);
disks.add(disk);
}
return disks;
} catch (final LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:LibvirtStorageAdaptor.java
示例15: attachIso
import org.libvirt.LibvirtException; //导入依赖的package包/类
@Override
public Answer attachIso(final AttachCommand cmd) {
final DiskTO disk = cmd.getDisk();
final TemplateObjectTO isoTo = (TemplateObjectTO) disk.getData();
final DataStoreTO store = isoTo.getDataStore();
if (!(store instanceof NfsTO)) {
return new AttachAnswer("unsupported protocol");
}
final NfsTO nfsStore = (NfsTO) store;
try {
final Connect conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName());
attachOrDetachIso(conn, cmd.getVmName(), nfsStore.getUrl() + File.separator + isoTo.getPath(), true);
} catch (final LibvirtException | URISyntaxException | InternalErrorException e) {
return new Answer(cmd, false, e.toString());
}
return new Answer(cmd);
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:19,代码来源:KvmStorageProcessor.java
示例16: getConnect
import org.libvirt.LibvirtException; //导入依赖的package包/类
private Connect getConnect(org.jtestplatform.cloud.configuration.Connection connection) throws DomainException {
synchronized (getLock(connection)) {
ConnectData connectData = connections.get(connection);
if (connectData == null) {
try {
Connect connect = new Connect(connection.getUri(), false);
connectData = new ConnectData(connect);
} catch (LibvirtException e) {
throw new DomainException(e);
}
connections.put(connection, connectData);
}
connectData.incrementReferenceCounter();
return connectData.getConnect();
}
}
开发者ID:fduminy,项目名称:jtestplatform,代码行数:17,代码来源:ConnectManager.java
示例17: closeConnect
import org.libvirt.LibvirtException; //导入依赖的package包/类
private void closeConnect(org.jtestplatform.cloud.configuration.Connection connection) {
ConnectData connectData = connections.remove(connection);
if (connectData != null) {
try {
LOGGER.info("closing connection to {}", connection.getUri());
if (connectData.getReferenceCounter() > 0) {
LOGGER.warn("The connection to {} has {} unreleased references", connection.getUri(),
connectData.getReferenceCounter());
}
// note : return -1 on error, or >= 0 on success where the value is the number of references to the connection
int result = connectData.getConnect().close();
LOGGER.debug("Connect.close() returned {}", result);
LOGGER.info("closed connection to {}", connection.getUri());
} catch (LibvirtException e) {
LOGGER.error("failed to close connection to " + connection.getUri(), e);
}
}
}
开发者ID:fduminy,项目名称:jtestplatform,代码行数:19,代码来源:ConnectManager.java
示例18: listAllDomains
import org.libvirt.LibvirtException; //导入依赖的package包/类
private List<Domain> listAllDomains(Connect connect) throws LibvirtException {
List<Domain> domains = new ArrayList<Domain>();
// get defined but inactive domains
for (String name : connect.listDefinedDomains()) {
if (name != null) {
domains.add(connect.domainLookupByName(name));
}
}
// get active domains
for (int id : connect.listDomains()) {
domains.add(connect.domainLookupByID(id));
}
return domains;
}
开发者ID:fduminy,项目名称:jtestplatform,代码行数:18,代码来源:DomainCache.java
示例19: findFreeDomainId
import org.libvirt.LibvirtException; //导入依赖的package包/类
@Nullable
private Integer findFreeDomainId(List<Domain> domains) throws LibvirtException {
Set<Integer> domainIds = new HashSet<Integer>(domains.size());
for (Domain domain : domains) {
if (domain.getName().startsWith(DOMAIN_NAME_PREFIX)) {
domainIds.add(Integer.parseInt(domain.getName().substring(DOMAIN_NAME_PREFIX.length())));
}
}
Integer domainId = null;
for (int id = networkConfig.getMinSubNetIpAddress(); id <= networkConfig.getMaxSubNetIpAddress(); id++) {
if (!domainIds.contains(id)) {
domainId = id;
break;
}
}
return domainId;
}
开发者ID:fduminy,项目名称:jtestplatform,代码行数:19,代码来源:DomainCache.java
示例20: getMacAddress
import org.libvirt.LibvirtException; //导入依赖的package包/类
private static String getMacAddress(Domain domain) throws LibvirtException {
String macAddress = null;
String xml = domain.getXMLDesc(0);
//TODO it's bad, we should use an xml parser. create and add it in the libvirt-model project.
String begin = "<mac address='";
int idx = xml.indexOf(begin);
if (idx >= 0) {
idx += begin.length();
int idx2 = xml.indexOf('\'', idx);
if (idx2 >= 0) {
macAddress = xml.substring(idx, idx2);
}
}
return macAddress;
}
开发者ID:fduminy,项目名称:jtestplatform,代码行数:19,代码来源:DomainCache.java
注:本文中的org.libvirt.LibvirtException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论