Package org.libvirt

Examples of org.libvirt.StorageVol


    public boolean deleteVbdByPath(String diskPath) {
        Connect conn;
        try {
            conn = LibvirtConnection.getConnection();
            StorageVol vol = conn.storageVolLookupByPath(diskPath);
            if(vol != null) {
                s_logger.debug("requested delete disk " + diskPath);
                vol.delete(0);
            }
        } catch (LibvirtException e) {
            s_logger.debug("Libvirt error in attempting to find and delete patch disk:" + e.toString());
            return false;
        }
View Full Code Here


        }
        return true;
    }

    public StorageVol getVolume(StoragePool pool, String volName) {
        StorageVol vol = null;

        try {
            vol = pool.storageVolLookupByName(volName);
        } catch (LibvirtException e) {
View Full Code Here

    }

    public StorageVol copyVolume(StoragePool destPool,
            LibvirtStorageVolumeDef destVol, StorageVol srcVol, int timeout)
            throws LibvirtException {
        StorageVol vol = destPool.storageVolCreateXML(destVol.toString(), 0);
        String srcPath = srcVol.getKey();
        String destPath = vol.getKey();
        Script.runSimpleBashScript("cp " + srcPath + " " + destPath, timeout);
        return vol;
    }
View Full Code Here

    public KVMPhysicalDisk getPhysicalDisk(String volumeUuid,
            KVMStoragePool pool) {
        LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;

        try {
            StorageVol vol = this.getVolume(libvirtPool.getPool(), volumeUuid);
            KVMPhysicalDisk disk;
            LibvirtStorageVolumeDef voldef = getStorageVolumeDef(libvirtPool
                    .getPool().getConnect(), vol);
            disk = new KVMPhysicalDisk(vol.getPath(), vol.getName(), pool);
            disk.setSize(vol.getInfo().allocation);
            disk.setVirtualSize(vol.getInfo().capacity);
            if (voldef.getFormat() == null) {
                disk.setFormat(pool.getDefaultFormat());
            } else if (pool.getType() == StoragePoolType.RBD) {
                disk.setFormat(KVMPhysicalDisk.PhysicalDiskFormat.RAW);
            } else if (voldef.getFormat() == LibvirtStorageVolumeDef.volFormat.QCOW2) {
View Full Code Here

        LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(name,
                size, libvirtformat, null, null);
        s_logger.debug(volDef.toString());
        try {
            StorageVol vol = virtPool.storageVolCreateXML(volDef.toString(), 0);
            KVMPhysicalDisk disk = new KVMPhysicalDisk(vol.getPath(),
                    vol.getName(), pool);
            disk.setFormat(format);
            disk.setSize(vol.getInfo().allocation);
            disk.setVirtualSize(vol.getInfo().capacity);
            return disk;
        } catch (LibvirtException e) {
            throw new CloudRuntimeException(e.toString());
        }
    }
View Full Code Here

    @Override
    public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool) {
        LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
        try {
            StorageVol vol = this.getVolume(libvirtPool.getPool(), uuid);
            vol.delete(0);
            vol.free();
            return true;
        } catch (LibvirtException e) {
            throw new CloudRuntimeException(e.toString());
        }
    }
View Full Code Here

            /* libvirt doesn't support resizing (C)LVM devices, so we have to do that via a Bash script */
            if (pool.getType() != StoragePoolType.CLVM) {
                s_logger.debug("Volume " + path +  " can be resized by libvirt. Asking libvirt to resize the volume.");
                try {
                    Connect conn = LibvirtConnection.getConnection();
                    StorageVol v = conn.storageVolLookupByPath(path);
                    int flags = 0;

                    if (conn.getLibVirVersion() > 1001000 && vol.getFormat() == PhysicalDiskFormat.RAW) {
                        flags = 1;
                    }
                    if (shrinkOk) {
                        flags = 4;
                    }

                    v.resize(newSize, flags);
                } catch (LibvirtException e) {
                    return new ResizeVolumeAnswer(cmd, false, e.toString());
                }
            } else {
                s_logger.debug("Volume " + path + " is of the type LVM and can not be resized using libvirt. Invoking resize script.");
View Full Code Here

        }
        return true;
    }

    public StorageVol getVolume(StoragePool pool, String volName) {
        StorageVol vol = null;

        try {
            vol = pool.storageVolLookupByName(volName);
        } catch (LibvirtException e) {
            s_logger.debug("Can't find volume: " + e.toString());
View Full Code Here

            return null;
        }
    }

    public StorageVol copyVolume(StoragePool destPool, LibvirtStorageVolumeDef destVol, StorageVol srcVol, int timeout) throws LibvirtException {
        StorageVol vol = destPool.storageVolCreateXML(destVol.toString(), 0);
        String srcPath = srcVol.getKey();
        String destPath = vol.getKey();
        Script.runSimpleBashScript("cp " + srcPath + " " + destPath, timeout);
        return vol;
    }
View Full Code Here

    @Override
    public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
        LibvirtStoragePool libvirtPool = (LibvirtStoragePool)pool;

        try {
            StorageVol vol = getVolume(libvirtPool.getPool(), volumeUuid);
            KVMPhysicalDisk disk;
            LibvirtStorageVolumeDef voldef = getStorageVolumeDef(libvirtPool.getPool().getConnect(), vol);
            disk = new KVMPhysicalDisk(vol.getPath(), vol.getName(), pool);
            disk.setSize(vol.getInfo().allocation);
            disk.setVirtualSize(vol.getInfo().capacity);

            /**
             * libvirt returns format = 'unknow', so we have to force
             * the format to RAW for RBD storage volumes
             */
 
View Full Code Here

TOP

Related Classes of org.libvirt.StorageVol

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.