Package org.libvirt

Examples of org.libvirt.StorageVol


        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

    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

      try {
         XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(client.domainLookupByUUIDString(id)
                  .getXMLDesc(0))));
         String diskFileName = builder.xpathFind("//devices/disk[@device='disk']/source").getElement().getAttribute(
                  "file");
         StorageVol storageVol = client.storageVolLookupByPath(diskFileName);
         storageVol.delete(0);
         client.domainLookupByUUIDString(id).undefine();
      } catch (Exception e) {
         Throwables.propagate(e);
      }
   }
View Full Code Here

         Document doc = builder.getDocument();
         String xpathString = "//devices/disk[@device='disk']/source/@file";
         XPathExpression expr = XPathFactory.newInstance().newXPath().compile(xpathString);
         NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
         String diskFileName = nodes.item(0).getNodeValue();
         StorageVol storageVol = client.storageVolLookupByPath(diskFileName);

         // cloning volume
         String poolName = storageVol.storagePoolLookupByVolume().getName();
         StoragePool storagePool = client.storagePoolLookupByName(poolName);
         StorageVol clonedVol = null;
         boolean cloned = false;
         int retry = 0;
         while (!cloned && retry < 10) {
            try {
               clonedVol = cloneVolume(storagePool, storageVol);
View Full Code Here

         XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(client.domainLookupByUUIDString(id)
                  .getXMLDesc(0))));
         String diskFileName = builder.xpathFind("//devices/disk[@device='disk']/source").getElement().getAttribute(
                  "file");
         StorageVol storageVol = client.storageVolLookupByPath(diskFileName);
         storageVol.delete(0);
         client.domainLookupByUUIDString(id).undefine();

      } catch (LibvirtException e) {
         Throwables.propagate(e);
      } catch (Exception e) {
View Full Code Here

      Document doc = xmlBuilder.getDocument();
      XPathExpression expr = XPathFactory.newInstance().newXPath().compile("//devices/disk[@device='disk']/source/@file");
      NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
      String diskFileName = nodes.item(0).getNodeValue();
      for (int i = 0; i < nodes.getLength(); i++) {
        StorageVol storageVol = from.getConnect().storageVolLookupByPath(diskFileName);
        String id = storageVol.getKey();
        float size = Long.valueOf(storageVol.getInfo().capacity).floatValue();
        volumes.add(new VolumeImpl(id, Volume.Type.LOCAL, size, null, true, false));
      }
      builder.volumes((List<Volume>) volumes);
    } catch (LibvirtException e) {
      Throwables.propagate(e);
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

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.