public Connect retrieveQemuConnection(final String qemuURI) throws LibvirtException { return new Connect(qemuURI); }
private void getHostInfoFromLibvirt() { try { final Connect conn = LibvirtConnection.getConnection(); final NodeInfo hosts = conn.nodeInfo(); this.cpuSpeed = getCpuSpeed(hosts); parser.parseCapabilitiesXML(conn.getCapabilities()); final ArrayList<String> oss = parser.getGuestOsType(); for (final String s : oss) { conn.close(); } catch (final LibvirtException e) { LOGGER.error("Caught libvirt exception while fetching host information", e);
ids = conn.listDomains(); } catch (final LibvirtException e) { s_logger.warn("Unable to listDomains", e); vms = conn.listDefinedDomains(); } catch (final LibvirtException e) { s_logger.warn("Unable to listDomains", e); for (int i = 0; i < ids.length; i++) { try { dm = conn.domainLookupByID(ids[i]); vmStates.put(vmName, new HostVmStateReportEntry(state, conn.getHostName())); try { dm = conn.domainLookupByName(vms[i]); vmStates.put(vmName, new HostVmStateReportEntry(state, conn.getHostName()));
static public Connect getConnection(String hypervisorURI) throws LibvirtException { s_logger.debug("Looking for libvirtd connection at: " + hypervisorURI); Connect conn = s_connections.get(hypervisorURI); if (conn == null) { s_logger.info("No existing libvirtd connection found. Opening a new one"); conn = new Connect(hypervisorURI, false); s_logger.debug("Successfully connected to libvirt at: " + hypervisorURI); s_connections.put(hypervisorURI, conn); } else { try { conn.getVersion(); } catch (LibvirtException e) { s_logger.error("Connection with libvirtd is broken: " + e.getMessage()); s_logger.debug("Opening a new libvirtd connection to: " + hypervisorURI); conn = new Connect(hypervisorURI, false); s_connections.put(hypervisorURI, conn); } } return conn; }
protected List<String> getAllVmNames(final Connect conn) { final ArrayList<String> la = new ArrayList<String>(); try { final String names[] = conn.listDefinedDomains(); for (int i = 0; i < names.length; i++) { la.add(names[i]); ids = conn.listDomains(); } catch (final LibvirtException e) { s_logger.warn("Failed to list domains", e); for (int i = 0; i < ids.length; i++) { try { dm = conn.domainLookupByID(ids[i]); la.add(dm.getName()); } catch (final LibvirtException e) {
dm = conn.domainLookupByName(vmName); if (dm != null && dm.isPersistent() == 1) { conn.domainCreateXML(domainXML, 0); } catch (final LibvirtException e) { throw e;
try { Stream<Domain> runningVms = IntStream.of(connect.listDomains()) .mapToObj(s -> { try { return connect.domainLookupByID(s); } catch (LibvirtException e) { logger().error("Couldn't get info for domain {}", s, e); Stream<Domain> definedVMs = Stream.of(connect.listDefinedDomains()) .map(s -> { try { return connect.domainLookupByName(s); } catch (LibvirtException e) { logger().error("Couldn't get info for domain {}", s, e); .collect(Collectors.toList()); } finally { connect.close();
public Domain getDomain(final Connect conn, final String vmName) throws LibvirtException { return conn.domainLookupByName(vmName); }
ifaces = libvirtComputingResource.getInterfaces(conn, vmName); disks = libvirtComputingResource.getDisks(conn, vmName); dm = conn.domainLookupByName(vmName); final int xmlFlag = conn.getLibVirVersion() >= 1000000 ? 8 : 1; // 1000000 equals v1.0.0 s_logger.info("Live migration of instance " + vmName + " initiated to destination host: " + dconn.getURI()); final ExecutorService executor = Executors.newFixedThreadPool(1); final Callable<Domain> worker = new MigrateKVMAsync(libvirtComputingResource, dm, dconn, xmlDesc, migrateStorage, dconn.close();
@Override public boolean stop() { try { final Connect conn = LibvirtConnection.getConnection(); conn.close(); } catch (final LibvirtException e) { s_logger.trace("Ignoring libvirt error.", e); } return true; }
Optional<Domain> domainOpt = Optional.ofNullable(conn.domainLookupByName(action.getDomain())); if (domainOpt.isPresent()) { Domain d = domainOpt.get(); conn.close();
delegate.commit(); committed = true; delegate.setTransactional(); commit(); delegate.close(); delegate.executeCommand();
@Override public Map<String, String> validateSettings(Map<String, String> settings) { Map<String, String> errors = new HashMap<>(); if (settings.containsKey(SETTINGS_URL)) { Connect conn = null; try { conn = connectToKVM(settings.get(SETTINGS_URL)); NodeInfo ni = conn.nodeInfo(); } catch (LibvirtException e) { logger().error("Couldn't connect to kvm host {}", settings.get(SETTINGS_URL), e); } finally { if (conn != null) { try { conn.close(); } catch (LibvirtException e) { logger().error("Couldn't close connection to kvm host {}", settings.get(SETTINGS_URL), e); } } } } else { errors.put("Empty", "Url is empty"); } return errors; }
/** * Count the amount of active VMs * * @return */ private int countRunningVMs() throws LibvirtException { Connect connect = connectToKVM(settings.get(SETTINGS_URL)); try { return connect.numOfDomains(); } finally { connect.close(); } }
/** Get list of the inactive domains. */ public static List<Domain> getDefinedDomains(Connect libvirt) { try { List<Domain> domains = new ArrayList<>(); String[] domainNames = libvirt.listDefinedDomains(); for (String name : domainNames) { domains.add(libvirt.domainLookupByName(name)); } return domains; } catch (LibvirtException e) { throw new LibvirtRuntimeException("Unable to list defined domains", e); } }
sp = conn.storagePoolLookupByUUIDString(name); if (sp != null && sp.isActive() == 0) { sp.undefine(); String[] poolnames = conn.listStoragePools(); for (String poolname : poolnames) { s_logger.debug("Checking path of existing pool " + poolname + " against pool we want to create"); StoragePool p = conn.storagePoolLookupByName(poolname); LibvirtStoragePoolDef pdef = getStoragePoolDef(conn, p); if (pdef == null) {
/** Get list of the active domains. */ public static List<Domain> getRunningDomains(Connect libvirt) { try { List<Domain> domains = new ArrayList<>(); int[] ids = libvirt.listDomains(); for (int id : ids) { domains.add(libvirt.domainLookupByID(id)); } return domains; } catch (LibvirtException e) { throw new LibvirtRuntimeException("Unable to list defined domains", e); } }
/** * * @param connectType * @param vmName * @param autoDestroy * @throws LibvirtException */ private VMInstanceProvider(ConnectType connectType) throws VMMgmtException { try { conn = new Connect(connectType.getValue()); // prevent libvirt error messages from cluttering the console: conn.setConnectionErrorCallback(new Libvirt.VirErrorCallback() { @Override public void errorCallback(Pointer userData, virError error) { } }); } catch (LibvirtException ex) { throw new VMMgmtException(ex); } }
public static StoragePool findStoragePoolWithFile(Connect conn, String path) throws LibvirtException { for (String spn : conn.listStoragePools()) { StoragePool sp = conn.storagePoolLookupByName(spn); if (findVolumeInPool(sp, path) != null) { log.debug("Found storage pool '{}' for image '{}'", sp.getName(), path); return sp; } } throw new LibvirtRuntimeException("pool with image " + path + " not found"); }
double utilization = (info.cpuTime - oldStats._usedTime) / ((double)elapsedTime * 1000000); final NodeInfo node = conn.nodeInfo(); utilization = utilization / node.cpus; if (utilization > 0) {