Search in sources :

Example 11 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project cloudstack by apache.

the class LibvirtComputingResource method attachOrDetachDisk.

public synchronized String attachOrDetachDisk(final Connect conn, final boolean attach, final String vmName, final KVMPhysicalDisk attachingDisk, final int devId, final Long bytesReadRate, final Long bytesWriteRate, final Long iopsReadRate, final Long iopsWriteRate, final String cacheMode) throws LibvirtException, InternalErrorException {
    List<DiskDef> disks = null;
    Domain dm = null;
    DiskDef diskdef = null;
    final KVMStoragePool attachingPool = attachingDisk.getPool();
    try {
        dm = conn.domainLookupByName(vmName);
        final LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
        final String domXml = dm.getXMLDesc(0);
        parser.parseDomainXML(domXml);
        disks = parser.getDisks();
        if (!attach) {
            for (final DiskDef disk : disks) {
                final String file = disk.getDiskPath();
                if (file != null && file.equalsIgnoreCase(attachingDisk.getPath())) {
                    diskdef = disk;
                    break;
                }
            }
            if (diskdef == null) {
                throw new InternalErrorException("disk: " + attachingDisk.getPath() + " is not attached before");
            }
        } else {
            DiskDef.DiskBus busT = DiskDef.DiskBus.VIRTIO;
            for (final DiskDef disk : disks) {
                if (disk.getDeviceType() == DeviceType.DISK) {
                    if (disk.getBusType() == DiskDef.DiskBus.SCSI) {
                        busT = DiskDef.DiskBus.SCSI;
                    }
                    break;
                }
            }
            diskdef = new DiskDef();
            if (busT == DiskDef.DiskBus.SCSI) {
                diskdef.setQemuDriver(true);
                diskdef.setDiscard(DiscardType.UNMAP);
            }
            if (attachingPool.getType() == StoragePoolType.RBD) {
                diskdef.defNetworkBasedDisk(attachingDisk.getPath(), attachingPool.getSourceHost(), attachingPool.getSourcePort(), attachingPool.getAuthUserName(), attachingPool.getUuid(), devId, busT, DiskProtocol.RBD, DiskDef.DiskFmtType.RAW);
            } else if (attachingPool.getType() == StoragePoolType.Gluster) {
                diskdef.defNetworkBasedDisk(attachingDisk.getPath(), attachingPool.getSourceHost(), attachingPool.getSourcePort(), null, null, devId, busT, DiskProtocol.GLUSTER, DiskDef.DiskFmtType.QCOW2);
            } else if (attachingDisk.getFormat() == PhysicalDiskFormat.QCOW2) {
                diskdef.defFileBasedDisk(attachingDisk.getPath(), devId, busT, DiskDef.DiskFmtType.QCOW2);
            } else if (attachingDisk.getFormat() == PhysicalDiskFormat.RAW) {
                diskdef.defBlockBasedDisk(attachingDisk.getPath(), devId, busT);
            }
            if (bytesReadRate != null && bytesReadRate > 0) {
                diskdef.setBytesReadRate(bytesReadRate);
            }
            if (bytesWriteRate != null && bytesWriteRate > 0) {
                diskdef.setBytesWriteRate(bytesWriteRate);
            }
            if (iopsReadRate != null && iopsReadRate > 0) {
                diskdef.setIopsReadRate(iopsReadRate);
            }
            if (iopsWriteRate != null && iopsWriteRate > 0) {
                diskdef.setIopsWriteRate(iopsWriteRate);
            }
            if (cacheMode != null) {
                diskdef.setCacheMode(DiskDef.DiskCacheMode.valueOf(cacheMode.toUpperCase()));
            }
        }
        final String xml = diskdef.toString();
        return attachOrDetachDevice(conn, attach, vmName, xml);
    } finally {
        if (dm != null) {
            dm.free();
        }
    }
}
Also used : DiskDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) InternalErrorException(com.cloud.exception.InternalErrorException) Domain(org.libvirt.Domain)

Example 12 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project cloudstack by apache.

the class ConfigurationServerImpl method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    try {
        persistDefaultValues();
        _configDepotAdmin.populateConfigurations();
    } catch (InternalErrorException e) {
        throw new RuntimeException("Unhandled configuration exception", e);
    }
    return true;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InternalErrorException(com.cloud.exception.InternalErrorException)

Example 13 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project cloudstack by apache.

the class LibvirtComputingResource method createVbd.

public void createVbd(final Connect conn, final VirtualMachineTO vmSpec, final String vmName, final LibvirtVMDef vm) throws InternalErrorException, LibvirtException, URISyntaxException {
    final List<DiskTO> disks = Arrays.asList(vmSpec.getDisks());
    Collections.sort(disks, new Comparator<DiskTO>() {

        @Override
        public int compare(final DiskTO arg0, final DiskTO arg1) {
            return arg0.getDiskSeq() > arg1.getDiskSeq() ? 1 : -1;
        }
    });
    for (final DiskTO volume : disks) {
        KVMPhysicalDisk physicalDisk = null;
        KVMStoragePool pool = null;
        final DataTO data = volume.getData();
        if (volume.getType() == Volume.Type.ISO && data.getPath() != null) {
            final NfsTO nfsStore = (NfsTO) data.getDataStore();
            final String volPath = nfsStore.getUrl() + File.separator + data.getPath();
            final int index = volPath.lastIndexOf("/");
            final String volDir = volPath.substring(0, index);
            final String volName = volPath.substring(index + 1);
            final KVMStoragePool secondaryStorage = _storagePoolMgr.getStoragePoolByURI(volDir);
            physicalDisk = secondaryStorage.getPhysicalDisk(volName);
        } else if (volume.getType() != Volume.Type.ISO) {
            final PrimaryDataStoreTO store = (PrimaryDataStoreTO) data.getDataStore();
            physicalDisk = _storagePoolMgr.getPhysicalDisk(store.getPoolType(), store.getUuid(), data.getPath());
            pool = physicalDisk.getPool();
        }
        String volPath = null;
        if (physicalDisk != null) {
            volPath = physicalDisk.getPath();
        }
        // check for disk activity, if detected we should exit because vm is running elsewhere
        if (_diskActivityCheckEnabled && physicalDisk != null && physicalDisk.getFormat() == PhysicalDiskFormat.QCOW2) {
            s_logger.debug("Checking physical disk file at path " + volPath + " for disk activity to ensure vm is not running elsewhere");
            try {
                HypervisorUtils.checkVolumeFileForActivity(volPath, _diskActivityCheckTimeoutSeconds, _diskActivityInactiveThresholdMilliseconds, _diskActivityCheckFileSizeMin);
            } catch (final IOException ex) {
                throw new CloudRuntimeException("Unable to check physical disk file for activity", ex);
            }
            s_logger.debug("Disk activity check cleared");
        }
        // if params contains a rootDiskController key, use its value (this is what other HVs are doing)
        DiskDef.DiskBus diskBusType = getDiskModelFromVMDetail(vmSpec);
        if (diskBusType == null) {
            diskBusType = getGuestDiskModel(vmSpec.getPlatformEmulator());
        }
        // I'm not sure why previously certain DATADISKs were hard-coded VIRTIO and others not, however this
        // maintains existing functionality with the exception that SCSI will override VIRTIO.
        DiskDef.DiskBus diskBusTypeData = (diskBusType == DiskDef.DiskBus.SCSI) ? diskBusType : DiskDef.DiskBus.VIRTIO;
        final DiskDef disk = new DiskDef();
        if (volume.getType() == Volume.Type.ISO) {
            if (volPath == null) {
                /* Add iso as placeholder */
                disk.defISODisk(null);
            } else {
                disk.defISODisk(volPath);
            }
        } else {
            final int devId = volume.getDiskSeq().intValue();
            if (diskBusType == DiskDef.DiskBus.SCSI) {
                disk.setQemuDriver(true);
                disk.setDiscard(DiscardType.UNMAP);
            }
            if (pool.getType() == StoragePoolType.RBD) {
                /*
                            For RBD pools we use the secret mechanism in libvirt.
                            We store the secret under the UUID of the pool, that's why
                            we pass the pool's UUID as the authSecret
                     */
                disk.defNetworkBasedDisk(physicalDisk.getPath().replace("rbd:", ""), pool.getSourceHost(), pool.getSourcePort(), pool.getAuthUserName(), pool.getUuid(), devId, diskBusType, DiskProtocol.RBD, DiskDef.DiskFmtType.RAW);
            } else if (pool.getType() == StoragePoolType.Gluster) {
                final String mountpoint = pool.getLocalPath();
                final String path = physicalDisk.getPath();
                final String glusterVolume = pool.getSourceDir().replace("/", "");
                disk.defNetworkBasedDisk(glusterVolume + path.replace(mountpoint, ""), pool.getSourceHost(), pool.getSourcePort(), null, null, devId, diskBusType, DiskProtocol.GLUSTER, DiskDef.DiskFmtType.QCOW2);
            } else if (pool.getType() == StoragePoolType.CLVM || physicalDisk.getFormat() == PhysicalDiskFormat.RAW) {
                disk.defBlockBasedDisk(physicalDisk.getPath(), devId, diskBusType);
            } else {
                if (volume.getType() == Volume.Type.DATADISK) {
                    disk.defFileBasedDisk(physicalDisk.getPath(), devId, diskBusTypeData, DiskDef.DiskFmtType.QCOW2);
                } else {
                    disk.defFileBasedDisk(physicalDisk.getPath(), devId, diskBusType, DiskDef.DiskFmtType.QCOW2);
                }
            }
        }
        if (data instanceof VolumeObjectTO) {
            final VolumeObjectTO volumeObjectTO = (VolumeObjectTO) data;
            disk.setSerial(diskUuidToSerial(volumeObjectTO.getUuid()));
            if (volumeObjectTO.getBytesReadRate() != null && volumeObjectTO.getBytesReadRate() > 0) {
                disk.setBytesReadRate(volumeObjectTO.getBytesReadRate());
            }
            if (volumeObjectTO.getBytesWriteRate() != null && volumeObjectTO.getBytesWriteRate() > 0) {
                disk.setBytesWriteRate(volumeObjectTO.getBytesWriteRate());
            }
            if (volumeObjectTO.getIopsReadRate() != null && volumeObjectTO.getIopsReadRate() > 0) {
                disk.setIopsReadRate(volumeObjectTO.getIopsReadRate());
            }
            if (volumeObjectTO.getIopsWriteRate() != null && volumeObjectTO.getIopsWriteRate() > 0) {
                disk.setIopsWriteRate(volumeObjectTO.getIopsWriteRate());
            }
            if (volumeObjectTO.getCacheMode() != null) {
                disk.setCacheMode(DiskDef.DiskCacheMode.valueOf(volumeObjectTO.getCacheMode().toString().toUpperCase()));
            }
        }
        vm.getDevices().addDevice(disk);
    }
    if (vmSpec.getType() != VirtualMachine.Type.User) {
        if (_sysvmISOPath != null) {
            final DiskDef iso = new DiskDef();
            iso.defISODisk(_sysvmISOPath);
            vm.getDevices().addDevice(iso);
        }
    }
    // For LXC, find and add the root filesystem, rbd data disks
    if (HypervisorType.LXC.toString().toLowerCase().equals(vm.getHvsType())) {
        for (final DiskTO volume : disks) {
            final DataTO data = volume.getData();
            final PrimaryDataStoreTO store = (PrimaryDataStoreTO) data.getDataStore();
            if (volume.getType() == Volume.Type.ROOT) {
                final KVMPhysicalDisk physicalDisk = _storagePoolMgr.getPhysicalDisk(store.getPoolType(), store.getUuid(), data.getPath());
                final FilesystemDef rootFs = new FilesystemDef(physicalDisk.getPath(), "/");
                vm.getDevices().addDevice(rootFs);
            } else if (volume.getType() == Volume.Type.DATADISK) {
                final KVMPhysicalDisk physicalDisk = _storagePoolMgr.getPhysicalDisk(store.getPoolType(), store.getUuid(), data.getPath());
                final KVMStoragePool pool = physicalDisk.getPool();
                if (StoragePoolType.RBD.equals(pool.getType())) {
                    final int devId = volume.getDiskSeq().intValue();
                    final String device = mapRbdDevice(physicalDisk);
                    if (device != null) {
                        s_logger.debug("RBD device on host is: " + device);
                        final DiskDef diskdef = new DiskDef();
                        diskdef.defBlockBasedDisk(device, devId, DiskDef.DiskBus.VIRTIO);
                        diskdef.setQemuDriver(false);
                        vm.getDevices().addDevice(diskdef);
                    } else {
                        throw new InternalErrorException("Error while mapping RBD device on host");
                    }
                }
            }
        }
    }
}
Also used : KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) FilesystemDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.FilesystemDef) IOException(java.io.IOException) InternalErrorException(com.cloud.exception.InternalErrorException) NfsTO(com.cloud.agent.api.to.NfsTO) DiskDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef) DataTO(com.cloud.agent.api.to.DataTO) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 14 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project cloudstack by apache.

the class BridgeVifDriver method createVnet.

private void createVnet(String vnetId, String pif, String brName, String protocol) throws InternalErrorException {
    synchronized (_vnetBridgeMonitor) {
        String script = _modifyVlanPath;
        if (protocol.equals(Networks.BroadcastDomainType.Vxlan.scheme())) {
            script = _modifyVxlanPath;
        }
        final Script command = new Script(script, _timeout, s_logger);
        command.add("-v", vnetId);
        command.add("-p", pif);
        command.add("-b", brName);
        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 15 with InternalErrorException

use of com.cloud.exception.InternalErrorException in project cloudstack by apache.

the class BridgeVifDriver method plug.

@Override
public LibvirtVMDef.InterfaceDef plug(NicTO nic, String guestOsType, String nicAdapter) throws InternalErrorException, LibvirtException {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("nic=" + nic);
        if (nicAdapter != null && !nicAdapter.isEmpty()) {
            s_logger.debug("custom nic adapter=" + nicAdapter);
        }
    }
    LibvirtVMDef.InterfaceDef intf = new LibvirtVMDef.InterfaceDef();
    String vNetId = null;
    String protocol = null;
    if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan || nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan) {
        vNetId = Networks.BroadcastDomainType.getValue(nic.getBroadcastUri());
        protocol = Networks.BroadcastDomainType.getSchemeValue(nic.getBroadcastUri()).scheme();
    } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
        throw new InternalErrorException("Nicira NVP Logicalswitches are not supported by the BridgeVifDriver");
    }
    String trafficLabel = nic.getName();
    Integer networkRateKBps = 0;
    if (libvirtVersion > ((10 * 1000 + 10))) {
        networkRateKBps = (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) ? nic.getNetworkRateMbps().intValue() * 128 : 0;
    }
    if (nic.getType() == Networks.TrafficType.Guest) {
        if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) && (vNetId != null) && (protocol != null) && (!vNetId.equalsIgnoreCase("untagged")) || (nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan)) {
            if (trafficLabel != null && !trafficLabel.isEmpty()) {
                s_logger.debug("creating a vNet dev and bridge for guest traffic per traffic label " + trafficLabel);
                String brName = createVnetBr(vNetId, trafficLabel, protocol);
                intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
            } else {
                String brName = createVnetBr(vNetId, "private", protocol);
                intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
            }
        } else {
            String brname = "";
            if (trafficLabel != null && !trafficLabel.isEmpty()) {
                brname = trafficLabel;
            } else {
                brname = _bridges.get("guest");
            }
            intf.defBridgeNet(brname, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
        }
    } else if (nic.getType() == Networks.TrafficType.Control) {
        /* Make sure the network is still there */
        createControlNetwork();
        intf.defBridgeNet(_bridges.get("linklocal"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter));
    } else if (nic.getType() == Networks.TrafficType.Public) {
        if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) && (vNetId != null) && (protocol != null) && (!vNetId.equalsIgnoreCase("untagged")) || (nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan)) {
            if (trafficLabel != null && !trafficLabel.isEmpty()) {
                s_logger.debug("creating a vNet dev and bridge for public traffic per traffic label " + trafficLabel);
                String brName = createVnetBr(vNetId, trafficLabel, protocol);
                intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
            } else {
                String brName = createVnetBr(vNetId, "public", protocol);
                intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
            }
        } else {
            intf.defBridgeNet(_bridges.get("public"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
        }
    } else if (nic.getType() == Networks.TrafficType.Management) {
        intf.defBridgeNet(_bridges.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter));
    } else if (nic.getType() == Networks.TrafficType.Storage) {
        String storageBrName = nic.getName() == null ? _bridges.get("private") : nic.getName();
        intf.defBridgeNet(storageBrName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter));
    }
    if (nic.getPxeDisable() == true) {
        intf.setPxeDisable(true);
    }
    return intf;
}
Also used : 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