use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.
the class CloudZonesComputingResource method execute.
protected Answer execute(StopCommand cmd) {
final String vmName = cmd.getVmName();
Long bytesReceived = new Long(0);
Long bytesSent = new Long(0);
State state = null;
synchronized (_vms) {
state = _vms.get(vmName);
_vms.put(vmName, State.Stopping);
}
try {
Connect conn = LibvirtConnection.getConnection();
try {
Domain dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName.getBytes()));
} catch (LibvirtException e) {
state = State.Stopped;
return new StopAnswer(cmd, null, 0, bytesSent, bytesReceived);
}
String macAddress = null;
if (vmName.startsWith("i-")) {
List<InterfaceDef> nics = getInterfaces(conn, vmName);
if (!nics.isEmpty()) {
macAddress = nics.get(0).getMacAddress();
}
}
destroy_network_rules_for_vm(conn, vmName);
String result = stopVM(conn, vmName, defineOps.UNDEFINE_VM);
try {
cleanupVnet(conn, cmd.getVnet());
_dhcpSnooper.cleanup(macAddress, vmName);
_vmDataServer.handleVmStopped(cmd.getVmName());
} catch (Exception e) {
}
state = State.Stopped;
return new StopAnswer(cmd, result, 0, bytesSent, bytesReceived);
} catch (LibvirtException e) {
return new StopAnswer(cmd, e.getMessage());
} finally {
synchronized (_vms) {
if (state != null) {
_vms.put(vmName, state);
} else {
_vms.remove(vmName);
}
}
}
}
use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.
the class LibvirtStorageAdaptor method listPhysicalDisks.
@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 = this.getPhysicalDisk(volName, pool);
disks.add(disk);
}
return disks;
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
}
use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.
the class LibvirtStorageAdaptor method deleteStoragePool.
@Override
public boolean deleteStoragePool(KVMStoragePool pool) {
LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
StoragePool virtPool = libvirtPool.getPool();
try {
virtPool.destroy();
virtPool.undefine();
virtPool.free();
} catch (LibvirtException e) {
return false;
}
return true;
}
use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.
the class LibvirtStorageAdaptor method getVolumeFromURI.
public StorageVol getVolumeFromURI(Connect conn, String volPath) throws LibvirtException, URISyntaxException {
int index = volPath.lastIndexOf("/");
URI volDir = null;
StoragePool sp = null;
StorageVol vol = null;
try {
volDir = new URI(volPath.substring(0, index));
String volName = volPath.substring(index + 1);
sp = getStoragePoolbyURI(conn, volDir);
vol = sp.storageVolLookupByName(volName);
return vol;
} catch (LibvirtException e) {
s_logger.debug("Faild to get vol path: " + e.toString());
throw e;
} finally {
try {
if (sp != null) {
sp.free();
}
} catch (LibvirtException e) {
}
}
}
use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method stop.
@Override
public boolean stop() {
try {
Connect conn = LibvirtConnection.getConnection();
conn.close();
} catch (LibvirtException e) {
}
return true;
}
Aggregations