@Override public boolean disconnectPhysicalDisk(String volumeUuid, KVMStoragePool pool) { try { return disconnectPhysicalDisk(pool, volumeUuid); } catch (LibvirtException e) { throw new CloudRuntimeException(e.getMessage()); } }
conn = LibvirtConnection.getConnection(); } catch (LibvirtException e) { throw new CloudRuntimeException(e.toString()); } catch (LibvirtException e) { s_logger.error("Failed to create netfs mount: " + host + ":" + path , e); s_logger.error(e.getStackTrace()); throw new CloudRuntimeException(e.toString()); } catch (LibvirtException e) { s_logger.error("Failed to create glusterfs mount: " + host + ":" + path , e); s_logger.error(e.getStackTrace()); throw new CloudRuntimeException(e.toString()); String error = e.toString(); if (error.contains("Storage source conflict")) { throw new CloudRuntimeException("A pool matching this location already exists in libvirt, " +
String error = e.toString(); if (error.contains("Storage source conflict")) { throw new CloudRuntimeException("A pool matching this location already exists in libvirt, " + " but has a different UUID/Name. Cannot create new pool without first " s_logger.error(e.toString()); if (e.toString().contains("already mounted")) { s_logger.error("Attempting to unmount old mount libvirt is unaware of at " + targetPath); String result = Script.runSimpleBashScript("umount -l " + targetPath); s_logger.error("Internal error occurred when attempting to mount:" + e.getMessage()); e.printStackTrace(); throw new CloudRuntimeException(e.toString());
final String error = e.toString(); if (error.contains("Domain not found")) { s_logger.debug("successfully shut down vm " + vmName); if (e.getMessage().contains("Domain not found")) { s_logger.debug("VM " + vmName + " doesn't exist, no need to stop it"); return null; return e.getMessage(); } catch (final InterruptedException ie) { s_logger.debug("Interrupted sleep");
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; }
@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, ""); } }
public void storagePoolRefresh(StoragePool pool) { try { synchronized (getStoragePool(pool.getUUIDString())) { refreshPool(pool); } } catch (LibvirtException e) { s_logger.debug("refresh storage pool failed: " + e.toString()); } }
@Override public List<KVMPhysicalDisk> listPhysicalDisks(String storagePoolUuid, KVMStoragePool pool) { LibvirtStoragePool libvirtPool = (LibvirtStoragePool)pool; StoragePool virtPool = libvirtPool.getPool(); List<KVMPhysicalDisk> disks = new ArrayList<KVMPhysicalDisk>(); try { String[] vols = virtPool.listVolumes(); for (String volName : vols) { KVMPhysicalDisk disk = getPhysicalDisk(volName, pool); disks.add(disk); } return disks; } catch (LibvirtException e) { throw new CloudRuntimeException(e.toString()); } }
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; }
@Override public Answer execute(final GetVmStatsCommand command, final LibvirtComputingResource libvirtComputingResource) { final List<String> vmNames = command.getVmNames(); try { final HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>(); for (final String vmName : vmNames) { final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper(); final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vmName); try { final VmStatsEntry statEntry = libvirtComputingResource.getVmStat(conn, vmName); if (statEntry == null) { continue; } vmStatsNameMap.put(vmName, statEntry); } catch (LibvirtException e) { s_logger.warn("Can't get vm stats: " + e.toString() + ", continue"); } } return new GetVmStatsAnswer(command, vmStatsNameMap); } catch (final LibvirtException e) { s_logger.debug("Can't get vm stats: " + e.toString()); return new GetVmStatsAnswer(command, 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; }
@Override public Answer execute(final GetVmDiskStatsCommand command, final LibvirtComputingResource libvirtComputingResource) { final List<String> vmNames = command.getVmNames(); final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper(); try { final HashMap<String, List<VmDiskStatsEntry>> vmDiskStatsNameMap = new HashMap<String, List<VmDiskStatsEntry>>(); final Connect conn = libvirtUtilitiesHelper.getConnection(); for (final String vmName : vmNames) { try { final List<VmDiskStatsEntry> statEntry = libvirtComputingResource.getVmDiskStat(conn, vmName); if (statEntry == null) { continue; } vmDiskStatsNameMap.put(vmName, statEntry); } catch (LibvirtException e) { s_logger.warn("Can't get vm disk stats: " + e.toString() + ", continue"); } } return new GetVmDiskStatsAnswer(command, "", command.getHostName(), vmDiskStatsNameMap); } catch (final LibvirtException e) { s_logger.debug("Can't get vm disk stats: " + e.toString()); return new GetVmDiskStatsAnswer(command, null, null, 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; }
@Override public Answer execute(final GetVmNetworkStatsCommand command, final LibvirtComputingResource libvirtComputingResource) { final List<String> vmNames = command.getVmNames(); final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper(); try { final HashMap<String, List<VmNetworkStatsEntry>> vmNetworkStatsNameMap = new HashMap<String, List<VmNetworkStatsEntry>>(); final Connect conn = libvirtUtilitiesHelper.getConnection(); for (final String vmName : vmNames) { try { final List<VmNetworkStatsEntry> statEntry = libvirtComputingResource.getVmNetworkStat(conn, vmName); if (statEntry == null) { continue; } vmNetworkStatsNameMap.put(vmName, statEntry); } catch (LibvirtException e) { s_logger.warn("Can't get vm network stats: " + e.toString() + ", continue"); } } return new GetVmNetworkStatsAnswer(command, "", command.getHostName(), vmNetworkStatsNameMap); } catch (final LibvirtException e) { s_logger.debug("Can't get vm network stats: " + e.toString()); return new GetVmNetworkStatsAnswer(command, null, null, null); } } }
public StorageVol getVolume(StoragePool pool, String volName) { StorageVol vol = null; try { vol = pool.storageVolLookupByName(volName); } catch (LibvirtException e) { s_logger.debug("Could not find volume " + volName + ": " + e.getMessage()); } /** * The volume was not found in the storage pool * This can happen when a volume has just been created on a different host and * since then the libvirt storage pool has not been refreshed. */ if (vol == null) { try { s_logger.debug("Refreshing storage pool " + pool.getName()); refreshPool(pool); } catch (LibvirtException e) { s_logger.debug("Failed to refresh storage pool: " + e.getMessage()); } try { vol = pool.storageVolLookupByName(volName); s_logger.debug("Found volume " + volName + " in storage pool " + pool.getName() + " after refreshing the pool"); } catch (LibvirtException e) { throw new CloudRuntimeException("Could not find volume " + volName + ": " + e.getMessage()); } } return vol; }
public List<DiskDef> getDisks(final Connect conn, final String vmName) { final LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser(); Domain dm = null; try { dm = conn.domainLookupByName(vmName); parser.parseDomainXML(dm.getXMLDesc(0)); return parser.getDisks(); } catch (final LibvirtException e) { s_logger.debug("Failed to get dom xml: " + e.toString()); return new ArrayList<DiskDef>(); } finally { try { if (dm != null) { dm.free(); } } catch (final LibvirtException e) { s_logger.trace("Ignoring libvirt error.", e); } } }
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 List<InterfaceDef> getInterfaces(final Connect conn, final String vmName) { final LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser(); Domain dm = null; try { dm = conn.domainLookupByName(vmName); parser.parseDomainXML(dm.getXMLDesc(0)); return parser.getInterfaces(); } catch (final LibvirtException e) { s_logger.debug("Failed to get dom xml: " + e.toString()); return new ArrayList<InterfaceDef>(); } finally { try { if (dm != null) { dm.free(); } } catch (final LibvirtException e) { s_logger.trace("Ignoring libvirt error.", e); } } }
private HashMap<String, HostVmStateReportEntry> getHostVmStateReport() { final HashMap<String, HostVmStateReportEntry> vmStates = new HashMap<String, HostVmStateReportEntry>(); Connect conn = null; if (_hypervisorType == HypervisorType.LXC) { try { conn = LibvirtConnection.getConnectionByType(HypervisorType.LXC.toString()); vmStates.putAll(getHostVmStateReport(conn)); conn = LibvirtConnection.getConnectionByType(HypervisorType.KVM.toString()); vmStates.putAll(getHostVmStateReport(conn)); } catch (final LibvirtException e) { s_logger.debug("Failed to get connection: " + e.getMessage()); } } if (_hypervisorType == HypervisorType.KVM) { try { conn = LibvirtConnection.getConnectionByType(HypervisorType.KVM.toString()); vmStates.putAll(getHostVmStateReport(conn)); } catch (final LibvirtException e) { s_logger.debug("Failed to get connection: " + e.getMessage()); } } return vmStates; }
private StoragePool createCLVMStoragePool(Connect conn, String uuid, String host, String path) { String volgroupPath = "/dev/" + path; String volgroupName = path; volgroupName = volgroupName.replaceFirst("/", ""); LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(PoolType.LOGICAL, volgroupName, uuid, host, volgroupPath, volgroupPath); StoragePool sp = null; try { s_logger.debug(spd.toString()); sp = conn.storagePoolCreateXML(spd.toString(), 0); return sp; } catch (LibvirtException e) { s_logger.error(e.toString()); if (sp != null) { try { if (sp.isPersistent() == 1) { sp.destroy(); sp.undefine(); } else { sp.destroy(); } sp.free(); } catch (LibvirtException l) { s_logger.debug("Failed to define clvm storage pool with: " + l.toString()); } } return null; } }