private void deleteVol(LibvirtStoragePool pool, StorageVol vol) throws LibvirtException { vol.delete(0); }
private void refreshPool(StoragePool pool) throws LibvirtException { pool.refresh(0); return; }
public Connect retrieveQemuConnection(final String qemuURI) throws LibvirtException { return new Connect(qemuURI); }
dm = conn.domainLookupByName(vmName); if (dm != null && dm.isPersistent() == 1) { dm.undefine(); dm.free(); conn.domainCreateXML(domainXML, 0); } catch (final LibvirtException e) { throw e;
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) { s_logger.warn("Can't get vm state " + vmName + e.getMessage() + "retry:" + retry); } finally { try { if (vms != null) { vms.free(); } } catch (final LibvirtException l) { s_logger.trace("Ignoring libvirt error.", l); } } } return PowerState.PowerOff; }
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) { s_logger.trace("Ignoring libvirt error.", l); } } }
public Domain getDomain(final Connect conn, final String vmName) throws LibvirtException { return conn.domainLookupByName(vmName); }
public StorageVol copyVolume(StoragePool destPool, LibvirtStorageVolumeDef destVol, StorageVol srcVol, int timeout) throws LibvirtException { StorageVol vol = destPool.storageVolCreateXML(destVol.toString(), 0); String srcPath = srcVol.getKey(); String destPath = vol.getKey(); Script.runSimpleBashScript("cp " + srcPath + " " + destPath, timeout); return vol; }
/** * Deletes the local volume from the storage pool. */ protected void deleteLocalVolume(String localPath) { try { Connect conn = LibvirtConnection.getConnection(); StorageVol storageVolLookupByPath = conn.storageVolLookupByPath(localPath); storageVolLookupByPath.delete(0); } catch (LibvirtException e) { s_logger.error(String.format("Cannot delete local volume [%s] due to: %s", localPath, e)); } }
public StorageVol getVolume(StoragePool pool, String volName) { StorageVol vol = null; try { vol = pool.storageVolLookupByName(volName); } catch (LibvirtException e) { s_logger.debug("Can't find volume: " + e.toString()); } if (vol == null) { try { refreshPool(pool); } catch (LibvirtException e) { s_logger.debug("failed to refresh pool: " + e.toString()); } s_logger.debug("no volume is present on the pool, creating a new one"); } return vol; }
/** * This method retrieves the memory statistics from the domain given as parameters. * If no memory statistic is found, it will return {@link NumberUtils#LONG_ZERO} as the value of free memory in the domain. * If it can retrieve the domain memory statistics, it will return the free memory statistic; that means, it returns the value at the first position of the array returned by {@link Domain#memoryStats(int)}. * * @return the amount of free memory in KBs */ protected long getMemoryFreeInKBs(Domain dm) throws LibvirtException { MemoryStatistic[] mems = dm.memoryStats(NUMMEMSTATS); if (ArrayUtils.isEmpty(mems)) { return NumberUtils.LONG_ZERO; } return mems[0].getValue(); }
@Override public Domain call() throws LibvirtException { long flags = VIR_MIGRATE_LIVE; if (dconn.getLibVirVersion() >= LIBVIRT_VERSION_SUPPORTS_MIGRATE_COMPRESSED) { flags += VIR_MIGRATE_COMPRESSED; } if (migrateStorage) { flags += VIR_MIGRATE_NON_SHARED_DISK; } if (autoConvergence && dconn.getLibVirVersion() >= 1002003) { flags += VIR_MIGRATE_AUTO_CONVERGE; } return dm.migrate(dconn, flags, dxml, vmName, "tcp:" + destIp, libvirtComputingResource.getMigrateSpeed()); } }
public void storagePoolRefresh(StoragePool pool) { try { synchronized (getStoragePool(pool.getUUIDString())) { refreshPool(pool); } } catch (LibvirtException e) { s_logger.debug("refresh storage pool failed: " + e.toString()); } }
private void deleteDirVol(LibvirtStoragePool pool, StorageVol vol) throws LibvirtException { Script.runSimpleBashScript("rm -r --interactive=never " + vol.getPath()); }
private String getHypervisorPath(final Connect conn) { final LibvirtCapXMLParser parser = new LibvirtCapXMLParser(); try { parser.parseCapabilitiesXML(conn.getCapabilities()); } catch (final LibvirtException e) { s_logger.debug(e.getMessage()); } return parser.getEmulator(); }
public LibvirtStorageVolumeDef getStorageVolumeDef(Connect conn, StorageVol vol) throws LibvirtException { String volDefXML = vol.getXMLDesc(0); LibvirtStorageVolumeXMLParser parser = new LibvirtStorageVolumeXMLParser(); return parser.parseStorageVolumeXML(volDefXML); }
public boolean disconnectPhysicalDisk(KVMStoragePool pool, String mountpoint) throws LibvirtException { LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool; StoragePool sp = libvirtPool.getPool(); // destroy the pool sp.destroy(); return true; }
public LibvirtStoragePoolDef getStoragePoolDef(Connect conn, StoragePool pool) throws LibvirtException { String poolDefXML = pool.getXMLDesc(0); LibvirtStoragePoolXMLParser parser = new LibvirtStoragePoolXMLParser(); return parser.parseStoragePoolXML(poolDefXML); }
private void refreshPool(StoragePool pool) throws LibvirtException { pool.refresh(0); return; }
public LibvirtStorageVolumeDef getStorageVolumeDef(Connect conn, StorageVol vol) throws LibvirtException { String volDefXML = vol.getXMLDesc(0); LibvirtStorageVolumeXMLParser parser = new LibvirtStorageVolumeXMLParser(); return parser.parseStorageVolumeXML(volDefXML); }