Search in sources :

Example 46 with InternalErrorException

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);
    }
}
Also used : Script(com.cloud.utils.script.Script) InternalErrorException(com.cloud.exception.InternalErrorException)

Example 47 with InternalErrorException

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;
}
Also used : LibvirtException(org.libvirt.LibvirtException) InternalErrorException(com.cloud.exception.InternalErrorException) Domain(org.libvirt.Domain) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) LibvirtException(org.libvirt.LibvirtException) FileNotFoundException(java.io.FileNotFoundException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException)

Example 48 with InternalErrorException

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);
    }
}
Also used : Script(com.cloud.utils.script.Script) InternalErrorException(com.cloud.exception.InternalErrorException)

Example 49 with InternalErrorException

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);
}
Also used : Script(com.cloud.utils.script.Script) DiskDef(com.cloud.agent.resource.computing.LibvirtVMDef.DiskDef) VolumeTO(com.cloud.agent.api.to.VolumeTO) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) InternalErrorException(com.cloud.exception.InternalErrorException)

Example 50 with InternalErrorException

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());
    }
}
Also used : ExtractResponse(com.cloud.api.response.ExtractResponse) ServerApiException(com.cloud.api.ServerApiException) InternalErrorException(com.cloud.exception.InternalErrorException)

Aggregations

InternalErrorException (com.cloud.exception.InternalErrorException)86 IOException (java.io.IOException)28 LibvirtException (org.libvirt.LibvirtException)27 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)25 Connect (org.libvirt.Connect)23 URISyntaxException (java.net.URISyntaxException)21 ConfigurationException (javax.naming.ConfigurationException)21 Answer (com.cloud.agent.api.Answer)17 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)16 NicTO (com.cloud.agent.api.to.NicTO)15 URI (java.net.URI)15 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)14 Script (com.cloud.utils.script.Script)14 Test (org.junit.Test)14 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)12 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)12 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)12 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)12 Processor (com.cloud.storage.template.Processor)11 TemplateLocation (com.cloud.storage.template.TemplateLocation)11