@Override public boolean disconnectPhysicalDisk(String volumeUuid, KVMStoragePool pool) { try { return disconnectPhysicalDisk(pool, volumeUuid); } catch (LibvirtException e) { throw new CloudRuntimeException(e.getMessage()); } }
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 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; }
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; }
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; }
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(); }
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; }
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; }
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");
@Override public Answer execute(final GetVolumeStatsCommand cmd, final LibvirtComputingResource libvirtComputingResource) { try { Connect conn = LibvirtConnection.getConnection(); String storeUuid = cmd.getPoolUuid(); StoragePoolType poolType = cmd.getPoolType(); HashMap<String, VolumeStatsEntry> statEntry = new HashMap<String, VolumeStatsEntry>(); for (String volumeUuid : cmd.getVolumeUuids()) { statEntry.put(volumeUuid, getVolumeStat(libvirtComputingResource, conn, volumeUuid, storeUuid, poolType)); } return new GetVolumeStatsAnswer(cmd, "", statEntry); } catch (LibvirtException e) { return new GetVolumeStatsAnswer(cmd, "Can't get vm disk stats: " + e.getMessage(), null); } }
protected ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd) { Connect conn; final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); try { conn = getLibvirtUtilitiesHelper().getConnectionByVmName(routerName); final IpAddressTO[] ips = cmd.getIpAddresses(); Integer devNum = 0; final List<InterfaceDef> pluggedNics = getInterfaces(conn, routerName); final Map<String, Integer> macAddressToNicNum = new HashMap<>(pluggedNics.size()); for (final InterfaceDef pluggedNic : pluggedNics) { final String pluggedVlan = pluggedNic.getBrName(); macAddressToNicNum.put(pluggedNic.getMacAddress(), devNum); devNum++; } for (final IpAddressTO ip : ips) { ip.setNicDevId(macAddressToNicNum.get(ip.getVifMacAddress())); } return new ExecutionResult(true, null); } catch (final LibvirtException e) { s_logger.error("Ip Assoc failure on applying one ip due to exception: ", e); return new ExecutionResult(false, e.getMessage()); } }
cleanVMSnapshotMetadata(dm); } catch (LibvirtException e) { s_logger.debug("Failed to get vm :" + e.getMessage()); } finally { try { break; } catch (final LibvirtException e) { s_logger.debug("Failed to get vm status:" + e.getMessage()); } finally { try {
} catch (final LibvirtException e) { s_logger.warn("Failed to create vm", e); msg = e.getMessage(); } catch (final InternalErrorException e) { s_logger.warn("Failed to create vm", e);
s_logger.debug("unable to stop VM:"+vmName+" due to"+e.getMessage()); try{ if(vmName.startsWith("s-") || vmName.startsWith("v-")) s_logger.debug("unable to restore cmdline due to:"+ex.getMessage()); return new StopAnswer(command, e.getMessage(), false);
} catch (final LibvirtException e) { s_logger.error("ipassoccmd failed", e); return new ExecutionResult(false, e.getMessage()); } catch (final InternalErrorException e) { s_logger.error("ipassoccmd failed", e);
return new ExecutionResult(false, e.getMessage()); } catch (final InternalErrorException e) { s_logger.error("ipassoccmd failed", e);
s_logger.error("Internal error occurred when attempting to mount:" + e.getMessage());
s_logger.error("Error whislt executing OVS Setup command! ==> " + e.getMessage()); return new Answer(command, false, e.getMessage());
@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()); } } }
@Override public Answer execute(final RebootCommand command, final LibvirtComputingResource libvirtComputingResource) { final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper(); try { final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName()); final String result = libvirtComputingResource.rebootVM(conn, command.getVmName()); if (result == null) { Integer vncPort = null; try { vncPort = libvirtComputingResource.getVncPort(conn, command.getVmName()); } catch (final LibvirtException e) { s_logger.trace("Ignoring libvirt error.", e); } libvirtComputingResource.getRuleLogsForVms(); return new RebootAnswer(command, null, vncPort); } else { return new RebootAnswer(command, result, false); } } catch (final LibvirtException e) { return new RebootAnswer(command, e.getMessage(), false); } } }