use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method execute.
private Answer execute(CheckVirtualMachineCommand cmd) {
try {
Connect conn = LibvirtConnection.getConnection();
final State state = getVmState(conn, cmd.getVmName());
Integer vncPort = null;
if (state == State.Running) {
vncPort = getVncPort(conn, cmd.getVmName());
synchronized (_vms) {
_vms.put(cmd.getVmName(), State.Running);
}
}
return new CheckVirtualMachineAnswer(cmd, state, vncPort);
} catch (LibvirtException e) {
return new CheckVirtualMachineAnswer(cmd, e.getMessage());
}
}
use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method getHypervisorPath.
private String getHypervisorPath(Connect conn) {
File f = new File("/usr/bin/cloud-qemu-kvm");
if (f.exists()) {
return "/usr/bin/cloud-qemu-kvm";
} else {
f = new File("/usr/libexec/cloud-qemu-kvm");
if (f.exists()) {
return "/usr/libexec/cloud-qemu-kvm";
}
LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
try {
parser.parseCapabilitiesXML(conn.getCapabilities());
} catch (LibvirtException e) {
}
return parser.getEmulator();
}
}
use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method getHostInfo.
protected List<Object> getHostInfo() {
final ArrayList<Object> info = new ArrayList<Object>();
long speed = 0;
long cpus = 0;
long ram = 0;
String cap = null;
try {
Connect conn = LibvirtConnection.getConnection();
final NodeInfo hosts = conn.nodeInfo();
boolean result = false;
try {
BufferedReader in = new BufferedReader(new FileReader("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"));
speed = Long.parseLong(in.readLine()) / 1000;
result = true;
} catch (FileNotFoundException e) {
} catch (IOException e) {
} catch (NumberFormatException e) {
}
if (!result) {
speed = hosts.mhz;
}
cpus = hosts.cpus;
ram = hosts.memory * 1024L;
LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
parser.parseCapabilitiesXML(conn.getCapabilities());
ArrayList<String> oss = parser.getGuestOsType();
for (String s : oss) {
/*
* Even host supports guest os type more than hvm, we only
* report hvm to management server
*/
if (s.equalsIgnoreCase("hvm")) {
cap = "hvm";
}
}
} catch (LibvirtException e) {
}
if (isSnapshotSupported()) {
cap = cap + ",snapshot";
}
info.add((int) cpus);
info.add(speed);
info.add(ram);
info.add(cap);
// save a maximum
long dom0ram = Math.min(ram / 10, 768 * 1024 * 1024L);
// of 10% of
// system ram or
// 768M
dom0ram = Math.max(dom0ram, _dom0MinMem);
info.add(dom0ram);
s_logger.debug("cpus=" + cpus + ", speed=" + speed + ", ram=" + ram + ", dom0ram=" + dom0ram);
return info;
}
use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method execute.
private Answer execute(AttachIsoCommand cmd) {
try {
Connect conn = LibvirtConnection.getConnection();
attachOrDetachISO(conn, cmd.getVmName(), cmd.getIsoPath(), cmd.isAttach());
} catch (LibvirtException e) {
return new Answer(cmd, false, e.toString());
} catch (URISyntaxException e) {
return new Answer(cmd, false, e.toString());
} catch (InternalErrorException e) {
return new Answer(cmd, false, e.toString());
}
return new Answer(cmd);
}
use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method getDisks.
protected List<DiskDef> getDisks(Connect conn, String vmName) {
LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
Domain dm = null;
try {
dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName.getBytes()));
parser.parseDomainXML(dm.getXMLDesc(0));
return parser.getDisks();
} catch (LibvirtException e) {
s_logger.debug("Failed to get dom xml: " + e.toString());
return new ArrayList<DiskDef>();
} catch (Exception e) {
s_logger.debug("Failed to get dom xml: " + e.toString());
return new ArrayList<DiskDef>();
} finally {
try {
if (dm != null) {
dm.free();
}
} catch (LibvirtException e) {
}
}
}
Aggregations