use of com.cloud.exception.InternalErrorException in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method patchSystemVm.
private void patchSystemVm(String cmdLine, String dataDiskPath, String vmName) throws InternalErrorException {
String result;
final Script command = new Script(_patchdomrPath, _timeout, s_logger);
command.add("-l", vmName);
command.add("-t", "all");
command.add("-d", dataDiskPath);
command.add("-p", cmdLine.replaceAll(" ", "%"));
result = command.execute();
if (result != null) {
throw new InternalErrorException(result);
}
}
use of com.cloud.exception.InternalErrorException in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method startDomain.
protected String startDomain(Connect conn, String vmName, String domainXML) throws LibvirtException, InternalErrorException {
/* No duplicated vm, we will success, or failed */
boolean failed = false;
Domain dm = null;
try {
dm = conn.domainDefineXML(domainXML);
} catch (final LibvirtException e) {
/* Duplicated defined vm */
s_logger.warn("Failed to define domain " + vmName + ": " + e.getMessage());
failed = true;
} finally {
try {
if (dm != null) {
dm.free();
}
} catch (final LibvirtException e) {
}
}
/* If failed, undefine the vm */
Domain dmOld = null;
Domain dmNew = null;
try {
if (failed) {
dmOld = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName.getBytes()));
dmOld.undefine();
dmNew = conn.domainDefineXML(domainXML);
}
} catch (final LibvirtException e) {
s_logger.warn("Failed to define domain (second time) " + vmName + ": " + e.getMessage());
throw e;
} catch (Exception e) {
s_logger.warn("Failed to define domain (second time) " + vmName + ": " + e.getMessage());
throw new InternalErrorException(e.toString());
} finally {
try {
if (dmOld != null) {
dmOld.free();
}
if (dmNew != null) {
dmNew.free();
}
} catch (final LibvirtException e) {
}
}
/* Start the VM */
try {
dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName.getBytes()));
dm.create();
} catch (LibvirtException e) {
s_logger.warn("Failed to start domain: " + vmName + ": " + e.getMessage());
throw e;
} finally {
try {
if (dm != null) {
dm.free();
}
} catch (final LibvirtException e) {
}
}
return null;
}
use of com.cloud.exception.InternalErrorException in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method createVnet.
public void createVnet(String vnetId, String pif) throws InternalErrorException {
final Script command = new Script(_modifyVlanPath, _timeout, s_logger);
command.add("-v", vnetId);
command.add("-p", pif);
command.add("-o", "add");
final String result = command.execute();
if (result != null) {
throw new InternalErrorException("Failed to create vnet " + vnetId + ": " + result);
}
}
use of com.cloud.exception.InternalErrorException in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method createPatchVbd.
private void createPatchVbd(Connect conn, String vmName, LibvirtVMDef vm, VirtualMachineTO vmSpec) throws LibvirtException, InternalErrorException {
List<DiskDef> disks = vm.getDevices().getDisks();
DiskDef rootDisk = disks.get(0);
VolumeTO rootVol = getVolume(vmSpec, Volume.Type.ROOT);
KVMStoragePool pool = _storagePoolMgr.getStoragePool(rootVol.getPoolUuid());
KVMPhysicalDisk disk = pool.createPhysicalDisk(UUID.randomUUID().toString(), KVMPhysicalDisk.PhysicalDiskFormat.RAW, 10L * 1024 * 1024);
/* Format/create fs on this disk */
final Script command = new Script(_createvmPath, _timeout, s_logger);
command.add("-f", disk.getPath());
String result = command.execute();
if (result != null) {
s_logger.debug("Failed to create data disk: " + result);
throw new InternalErrorException("Failed to create data disk: " + result);
}
String datadiskPath = disk.getPath();
/* add patch disk */
DiskDef patchDisk = new DiskDef();
patchDisk.defFileBasedDisk(datadiskPath, 1, rootDisk.getBusType(), DiskDef.diskFmtType.RAW);
disks.add(patchDisk);
String bootArgs = vmSpec.getBootArgs();
patchSystemVm(bootArgs, datadiskPath, vmName);
}
use of com.cloud.exception.InternalErrorException in project CloudStack-archive by CloudStack-extras.
the class ExtractTemplateCmd method execute.
@Override
public void execute() {
try {
UserContext.current().setEventDetails(getEventDescription());
Long uploadId = _templateService.extract(this);
if (uploadId != null) {
ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getEntityOwnerId(), mode);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to extract template");
}
} catch (InternalErrorException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
}
}
Aggregations