Search in sources :

Example 1 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method attachOrDetachDevice.

protected synchronized String attachOrDetachDevice(Connect conn, boolean attach, String vmName, String xml) throws LibvirtException, InternalErrorException {
    Domain dm = null;
    try {
        dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes((vmName.getBytes())));
        if (attach) {
            s_logger.debug("Attaching device: " + xml);
            dm.attachDevice(xml);
        } else {
            s_logger.debug("Detaching device: " + xml);
            dm.detachDevice(xml);
        }
    } catch (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;
    } catch (Exception e) {
        throw new InternalErrorException(e.toString());
    } finally {
        if (dm != null) {
            try {
                dm.free();
            } catch (LibvirtException l) {
            }
        }
    }
    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 2 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

protected CreatePrivateTemplateAnswer execute(CreatePrivateTemplateFromVolumeCommand cmd) {
    String secondaryStorageURL = cmd.getSecondaryStorageUrl();
    KVMStoragePool secondaryStorage = null;
    try {
        Connect conn = LibvirtConnection.getConnection();
        String templateFolder = cmd.getAccountId() + File.separator + cmd.getTemplateId() + File.separator;
        String templateInstallFolder = "/template/tmpl/" + templateFolder;
        secondaryStorage = _storagePoolMgr.getStoragePoolByURI(secondaryStorageURL);
        KVMStoragePool primary = _storagePoolMgr.getStoragePool(cmd.getPrimaryStoragePoolNameLabel());
        KVMPhysicalDisk disk = primary.getPhysicalDisk(cmd.getVolumePath());
        String tmpltPath = secondaryStorage.getLocalPath() + File.separator + templateInstallFolder;
        _storage.mkdirs(tmpltPath);
        Script command = new Script(_createTmplPath, _cmdsTimeout, s_logger);
        command.add("-f", disk.getPath());
        command.add("-t", tmpltPath);
        command.add("-n", cmd.getUniqueName() + ".qcow2");
        String result = command.execute();
        if (result != null) {
            s_logger.debug("failed to create template: " + result);
            return new CreatePrivateTemplateAnswer(cmd, false, result);
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(StorageLayer.InstanceConfigKey, _storage);
        Processor qcow2Processor = new QCOW2Processor();
        qcow2Processor.configure("QCOW2 Processor", params);
        FormatInfo info = qcow2Processor.process(tmpltPath, null, cmd.getUniqueName());
        TemplateLocation loc = new TemplateLocation(_storage, tmpltPath);
        loc.create(1, true, cmd.getUniqueName());
        loc.addFormat(info);
        loc.save();
        return new CreatePrivateTemplateAnswer(cmd, true, null, templateInstallFolder + cmd.getUniqueName() + ".qcow2", info.virtualSize, info.size, cmd.getUniqueName(), ImageFormat.QCOW2);
    } catch (LibvirtException e) {
        s_logger.debug("Failed to get secondary storage pool: " + e.toString());
        return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
    } catch (InternalErrorException e) {
        return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
    } catch (IOException e) {
        return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
    } catch (ConfigurationException e) {
        return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
    } catch (CloudRuntimeException e) {
        return new CreatePrivateTemplateAnswer(cmd, false, e.toString());
    } finally {
        if (secondaryStorage != null) {
            secondaryStorage.delete();
        }
    }
}
Also used : Script(com.cloud.utils.script.Script) QCOW2Processor(com.cloud.storage.template.QCOW2Processor) Processor(com.cloud.storage.template.Processor) LibvirtException(org.libvirt.LibvirtException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) Connect(org.libvirt.Connect) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) QCOW2Processor(com.cloud.storage.template.QCOW2Processor) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) ConfigurationException(javax.naming.ConfigurationException) TemplateLocation(com.cloud.storage.template.TemplateLocation) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) FormatInfo(com.cloud.storage.template.Processor.FormatInfo)

Example 3 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

private AttachVolumeAnswer execute(AttachVolumeCommand cmd) {
    try {
        Connect conn = LibvirtConnection.getConnection();
        KVMStoragePool primary = _storagePoolMgr.getStoragePool(cmd.getPoolUuid());
        KVMPhysicalDisk disk = primary.getPhysicalDisk(cmd.getVolumePath());
        attachOrDetachDisk(conn, cmd.getAttach(), cmd.getVmName(), disk, cmd.getDeviceId().intValue());
    } catch (LibvirtException e) {
        return new AttachVolumeAnswer(cmd, e.toString());
    } catch (InternalErrorException e) {
        return new AttachVolumeAnswer(cmd, e.toString());
    }
    return new AttachVolumeAnswer(cmd, cmd.getDeviceId());
}
Also used : AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) LibvirtException(org.libvirt.LibvirtException) KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) Connect(org.libvirt.Connect) InternalErrorException(com.cloud.exception.InternalErrorException)

Example 4 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

private synchronized Answer execute(PrepareForMigrationCommand cmd) {
    VirtualMachineTO vm = cmd.getVirtualMachine();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Preparing host for migrating " + vm);
    }
    NicTO[] nics = vm.getNics();
    try {
        Connect conn = LibvirtConnection.getConnection();
        for (NicTO nic : nics) {
            String vlanId = null;
            if (nic.getBroadcastType() == BroadcastDomainType.Vlan) {
                URI broadcastUri = nic.getBroadcastUri();
                vlanId = broadcastUri.getHost();
            }
            if (nic.getType() == TrafficType.Guest) {
                if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) {
                    createVlanBr(vlanId, _pifs.first());
                }
            } else if (nic.getType() == TrafficType.Control) {
                /* Make sure the network is still there */
                createControlNetwork(conn);
            } else if (nic.getType() == TrafficType.Public) {
                if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) {
                    createVlanBr(vlanId, _pifs.second());
                }
            }
        }
        /* setup disks, e.g for iso */
        VolumeTO[] volumes = vm.getDisks();
        for (VolumeTO volume : volumes) {
            if (volume.getType() == Volume.Type.ISO) {
                getVolumePath(conn, volume);
            }
        }
        synchronized (_vms) {
            _vms.put(vm.getName(), State.Migrating);
        }
        return new PrepareForMigrationAnswer(cmd);
    } catch (LibvirtException e) {
        return new PrepareForMigrationAnswer(cmd, e.toString());
    } catch (InternalErrorException e) {
        return new PrepareForMigrationAnswer(cmd, e.toString());
    } catch (URISyntaxException e) {
        return new PrepareForMigrationAnswer(cmd, e.toString());
    }
}
Also used : VolumeTO(com.cloud.agent.api.to.VolumeTO) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) InternalErrorException(com.cloud.exception.InternalErrorException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) NicTO(com.cloud.agent.api.to.NicTO) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer)

Example 5 with InternalErrorException

use of com.cloud.exception.InternalErrorException 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);
}
Also used : FenceAnswer(com.cloud.agent.api.FenceAnswer) ConsoleProxyLoadAnswer(com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer) DeleteSnapshotBackupAnswer(com.cloud.agent.api.DeleteSnapshotBackupAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) URISyntaxException(java.net.URISyntaxException) InternalErrorException(com.cloud.exception.InternalErrorException)

Aggregations

InternalErrorException (com.cloud.exception.InternalErrorException)143 LibvirtException (org.libvirt.LibvirtException)50 Connect (org.libvirt.Connect)41 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)40 IOException (java.io.IOException)40 URISyntaxException (java.net.URISyntaxException)34 Answer (com.cloud.agent.api.Answer)33 NicTO (com.cloud.agent.api.to.NicTO)31 Test (org.junit.Test)28 ConfigurationException (javax.naming.ConfigurationException)27 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)26 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)26 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)26 URI (java.net.URI)23 Script (com.cloud.utils.script.Script)21 Processor (com.cloud.storage.template.Processor)20 FormatInfo (com.cloud.storage.template.Processor.FormatInfo)19 TemplateLocation (com.cloud.storage.template.TemplateLocation)19 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)18 File (java.io.File)18