Package com.cloud.hypervisor.kvm.storage

Examples of com.cloud.hypervisor.kvm.storage.KVMStoragePool


            NfsTO nfsStore = (NfsTO)store;
            String isoPath = nfsStore.getUrl() + File.separator + data.getPath();
            int index = isoPath.lastIndexOf("/");
            String path = isoPath.substring(0, index);
            String name = isoPath.substring(index + 1);
            KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(
                    path);
            KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
            return isoVol.getPath();
        } else {
            return data.getPath();
        }
    }
View Full Code Here


            }
        });

        for (DiskTO volume : disks) {
            KVMPhysicalDisk physicalDisk = null;
            KVMStoragePool pool = null;
            DataTO data = volume.getData();
            if (volume.getType() == Volume.Type.ISO && data.getPath() != null) {
                NfsTO nfsStore = (NfsTO)data.getDataStore();
                String volPath = nfsStore.getUrl() + File.separator + data.getPath();
                int index = volPath.lastIndexOf("/");
                String volDir = volPath.substring(0, index);
                String volName = volPath.substring(index + 1);
                KVMStoragePool secondaryStorage = _storagePoolMgr.
                        getStoragePoolByURI(volDir);
                physicalDisk = secondaryStorage.getPhysicalDisk(volName);
            } else if (volume.getType() != Volume.Type.ISO) {
                PrimaryDataStoreTO store = (PrimaryDataStoreTO)data.getDataStore();
                physicalDisk = _storagePoolMgr.getPhysicalDiskstore.getPoolType(),
                        store.getUuid(),
                        data.getPath());
View Full Code Here

        String isoXml = null;
        if (isoPath != null && isAttach) {
            int index = isoPath.lastIndexOf("/");
            String path = isoPath.substring(0, index);
            String name = isoPath.substring(index + 1);
            KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(
                    path);
            KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
            isoPath = isoVol.getPath();

            DiskDef iso = new DiskDef();
            iso.defISODisk(isoPath);
            isoXml = iso.toString();
View Full Code Here

            boolean attach, String vmName, KVMPhysicalDisk attachingDisk,
            int devId, Long bytesReadRate, Long bytesWriteRate, Long iopsReadRate, Long iopsWriteRate) throws LibvirtException, InternalErrorException {
        List<DiskDef> disks = null;
        Domain dm = null;
        DiskDef diskdef = null;
        KVMStoragePool attachingPool = attachingDisk.getPool();
        try {
            if (!attach) {
                dm = conn.domainLookupByName(vmName);
                LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
                String xml = dm.getXMLDesc(0);
                parser.parseDomainXML(xml);
                disks = parser.getDisks();

                for (DiskDef disk : disks) {
                    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 = new DiskDef();
                if (attachingPool.getType() == StoragePoolType.RBD) {
                    diskdef.defNetworkBasedDisk(attachingDisk.getPath(),
                            attachingPool.getSourceHost(), attachingPool.getSourcePort(),
                            attachingPool.getAuthUserName(), attachingPool.getUuid(), devId,
                            DiskDef.diskBus.VIRTIO, diskProtocol.RBD);
                } else if (attachingDisk.getFormat() == PhysicalDiskFormat.QCOW2) {
                    diskdef.defFileBasedDisk(attachingDisk.getPath(), devId,
                            DiskDef.diskBus.VIRTIO, DiskDef.diskFmtType.QCOW2);
                } else if (attachingDisk.getFormat() == PhysicalDiskFormat.RAW) {
View Full Code Here

        cmd.setIqn(getIqn());

        StartupStorageCommand sscmd = null;
        try {

            KVMStoragePool localStoragePool = _storagePoolMgr
                    .createStoragePool(_localStorageUUID, "localhost", -1,
                            _localStoragePath, "", StoragePoolType.Filesystem);
            com.cloud.agent.api.StoragePoolInfo pi = new com.cloud.agent.api.StoragePoolInfo(
                    localStoragePool.getUuid(), cmd.getPrivateIpAddress(),
                    _localStoragePath, _localStoragePath,
                    StoragePoolType.Filesystem, localStoragePool.getCapacity(),
                    localStoragePool.getAvailable());

            sscmd = new StartupStorageCommand();
            sscmd.setPoolInfo(pi);
            sscmd.setGuid(pi.getUuid());
            sscmd.setDataCenter(_dcId);
View Full Code Here

         */
        boolean copyToSecondary = cmd.toSecondaryStorage();
        String volumePath = cmd.getVolumePath();
        StorageFilerTO pool = cmd.getPool();
        String secondaryStorageUrl = cmd.getSecondaryStorageURL();
        KVMStoragePool secondaryStoragePool = null;
        KVMStoragePool primaryPool = null;
        try {
            try {
                primaryPool = _storagePoolMgr.getStoragePool(
                     pool.getType(),
                     pool.getUuid());
            } catch (CloudRuntimeException e) {
                if (e.getMessage().contains("not found")) {
                    primaryPool = _storagePoolMgr.createStoragePool(cmd.getPool().getUuid(),
                                      cmd.getPool().getHost(), cmd.getPool().getPort(),
                                      cmd.getPool().getPath(), cmd.getPool().getUserInfo(),
                                      cmd.getPool().getType());
                } else {
                    return new CopyVolumeAnswer(cmd, false, e.getMessage(), null, null);
                }
            }

            String volumeName = UUID.randomUUID().toString();

            if (copyToSecondary) {
                String destVolumeName = volumeName + ".qcow2";
                KVMPhysicalDisk volume = primaryPool.getPhysicalDisk(cmd
                        .getVolumePath());
                String volumeDestPath = "/volumes/" + cmd.getVolumeId()
                        + File.separator;
                secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
                        secondaryStorageUrl);
View Full Code Here

    protected Answer execute(CreateCommand cmd) {
        StorageFilerTO pool = cmd.getPool();
        DiskProfile dskch = cmd.getDiskCharacteristics();
        KVMPhysicalDisk BaseVol = null;
        KVMStoragePool primaryPool = null;
        KVMPhysicalDisk vol = null;
        long disksize;
        try {
            primaryPool = _storagePoolMgr.getStoragePool(pool.getType(),
                    pool.getUuid());
            disksize = dskch.getSize();

            if (cmd.getTemplateUrl() != null) {
                if(primaryPool.getType() == StoragePoolType.CLVM) {
                    vol = templateToPrimaryDownload(cmd.getTemplateUrl(),primaryPool, dskch.getPath());
                } else {
                    BaseVol = primaryPool.getPhysicalDisk(cmd.getTemplateUrl());
                    vol = _storagePoolMgr.createDiskFromTemplate(BaseVol,
                            dskch.getPath(), primaryPool, 0);
                }
                if (vol == null) {
                    return new Answer(cmd, false,
                            " Can't create storage volume on storage pool");
                }
            } else {
                vol = primaryPool.createPhysicalDisk(dskch.getPath(), dskch.getSize());
            }
            VolumeTO volume = new VolumeTO(cmd.getVolumeId(), dskch.getType(),
                    pool.getType(), pool.getUuid(), pool.getPath(),
                    vol.getName(), vol.getName(), disksize, null);
            volume.setBytesReadRate(dskch.getBytesReadRate());
View Full Code Here

        if (index < templateUrl.length() - 1) {
            templateName = templateUrl.substring(index + 1);
        }

        KVMPhysicalDisk templateVol = null;
        KVMStoragePool secondaryPool = null;
        try {
            secondaryPool = _storagePoolMgr.getStoragePoolByURI(mountpoint);
            /* Get template vol */
            if (templateName == null) {
                secondaryPool.refresh();
                List<KVMPhysicalDisk> disks = secondaryPool.listPhysicalDisks();
                if (disks == null || disks.isEmpty()) {
                    s_logger.error("Failed to get volumes from pool: " + secondaryPool.getUuid());
                    return null;
                }
                for (KVMPhysicalDisk disk : disks) {
                    if (disk.getName().endsWith("qcow2")) {
                        templateVol = disk;
                        break;
                    }
                }
                if (templateVol == null) {
                    s_logger.error("Failed to get template from pool: " + secondaryPool.getUuid());
                    return null;
                }
            } else {
                templateVol = secondaryPool.getPhysicalDisk(templateName);
            }

            /* Copy volume to primary storage */

            KVMPhysicalDisk primaryVol = _storagePoolMgr.copyPhysicalDisk(templateVol, volUuid, primaryPool, 0);
            return primaryVol;
        } catch (CloudRuntimeException e) {
            s_logger.error("Failed to download template to primary storage",e);
            return null;
        } finally {
            if (secondaryPool != null) {
                _storagePoolMgr.deleteStoragePool(secondaryPool.getType(),secondaryPool.getUuid());
            }
        }
    }
View Full Code Here

        String vmInstanceName = cmd.getInstanceName();
        boolean shrinkOk = cmd.getShrinkOk();
        StorageFilerTO spool = cmd.getPool();

        try {
            KVMStoragePool pool = _storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid());
            KVMPhysicalDisk vol = pool.getPhysicalDisk(volid);
            String path = vol.getPath();
            String type = getResizeScriptType(pool, vol);

            /**
             * RBD volumes can't be resized via a Bash script or via libvirt
             *
             * libvirt-java doesn't implemented resizing volumes, so we have to do this manually
             *
             * Future fix would be to hand this over to libvirt
             */
            if (pool.getType() == StoragePoolType.RBD) {
                try {
                    Rados r = new Rados(pool.getAuthUserName());
                    r.confSet("mon_host", pool.getSourceHost() + ":" + pool.getSourcePort());
                    r.confSet("key", pool.getAuthSecret());
                    r.connect();
                    s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));

                    IoCTX io = r.ioCtxCreate(pool.getSourceDir());
                    Rbd rbd = new Rbd(io);
                    RbdImage image = rbd.open(vol.getName());

                    s_logger.debug("Resizing RBD volume " + vol.getName() " to " + newSize + " bytes");
                    image.resize(newSize);
                    rbd.close(image);

                    r.ioCtxDestroy(io);
                    s_logger.debug("Succesfully resized RBD volume " + vol.getName() " to " + newSize + " bytes");
                } catch (RadosException e) {
                    return new ResizeVolumeAnswer(cmd, false, e.toString());
                } catch (RbdException e) {
                    return new ResizeVolumeAnswer(cmd, false, e.toString());
                }
            } else {
                if (type == null) {
                    return new ResizeVolumeAnswer(cmd, false, "Unsupported volume format: pool type '"
                                    + pool.getType() + "' and volume format '" + vol.getFormat() + "'");
                } else if (type.equals("QCOW2") && shrinkOk) {
                    return new ResizeVolumeAnswer(cmd, false, "Unable to shrink volumes of type " + type);
                }

                s_logger.debug("got to the stage where we execute the volume resize, params:"
                            + path + "," + currentSize + "," + newSize + "," + type + "," + vmInstanceName + "," + shrinkOk);
                final Script resizecmd = new Script(_resizeVolumePath,
                            _cmdsTimeout, s_logger);
                resizecmd.add("-s",String.valueOf(newSize));
                resizecmd.add("-c",String.valueOf(currentSize));
                resizecmd.add("-p",path);
                resizecmd.add("-t",type);
                resizecmd.add("-r",String.valueOf(shrinkOk));
                resizecmd.add("-v",vmInstanceName);
                String result = resizecmd.execute();

                if (result != null) {
                    return new ResizeVolumeAnswer(cmd, false, result);
                }
            }

            /* fetch new size as seen from libvirt, don't want to assume anything */
            pool = _storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid());
            long finalSize = pool.getPhysicalDisk(volid).getVirtualSize();
            s_logger.debug("after resize, size reports as " + finalSize + ", requested " + newSize);
            return new ResizeVolumeAnswer(cmd, true, "success", finalSize);
        } catch (CloudRuntimeException e) {
            String error = "failed to resize volume: " + e;
            s_logger.debug(error);
View Full Code Here

        }
    }

    protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
        try {
            KVMStoragePool sp = _storagePoolMgr.getStoragePool(cmd
                    .getStorageId());
            return new GetStorageStatsAnswer(cmd, sp.getCapacity(),
                    sp.getUsed());
        } catch (CloudRuntimeException e) {
            return new GetStorageStatsAnswer(cmd, e.toString());
        }
    }
View Full Code Here

TOP

Related Classes of com.cloud.hypervisor.kvm.storage.KVMStoragePool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.