Examples of KVMStoragePool


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

    public Answer execute(DestroyCommand cmd) {
        VolumeTO vol = cmd.getVolume();

        try {
            KVMStoragePool pool = _storagePoolMgr.getStoragePool(
                    vol.getPoolType(),
                    vol.getPoolUuid());
            pool.deletePhysicalDisk(vol.getPath());
            return new Answer(cmd, true, "Success");
        } catch (CloudRuntimeException e) {
            s_logger.debug("Failed to delete volume: " + e.toString());
            return new Answer(cmd, false, e.toString());
        }
View Full Code Here

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

                } catch (LibvirtException e) {
                    s_logger.trace("Ignoring libvirt error.", e);
                }
            }

            KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool(
                    cmd.getPool().getType(),
                    cmd.getPool().getUuid());

            KVMPhysicalDisk disk = primaryPool.getPhysicalDisk(cmd
                    .getVolumePath());
            if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING
                    && !primaryPool.isExternalSnapshot()) {
                String vmUuid = vm.getUUIDString();
                Object[] args = new Object[] { snapshotName, vmUuid };
                String snapshot = SnapshotXML.format(args);
                s_logger.debug(snapshot);
                if (cmd.getCommandSwitch().equalsIgnoreCase(
                        ManageSnapshotCommand.CREATE_SNAPSHOT)) {
                    vm.snapshotCreateXML(snapshot);
                } else {
                    DomainSnapshot snap = vm.snapshotLookupByName(snapshotName);
                    snap.delete(0);
                }

                /*
                 * libvirt on RHEL6 doesn't handle resume event emitted from
                 * qemu
                 */
                vm = getDomain(conn, cmd.getVmName());
                state = vm.getInfo().state;
                if (state == DomainInfo.DomainState.VIR_DOMAIN_PAUSED) {
                    vm.resume();
                }
            } else {
                /**
                 * For RBD we can't use libvirt to do our snapshotting or any Bash scripts.
                 * libvirt also wants to store the memory contents of the Virtual Machine,
                 * but that's not possible with RBD since there is no way to store the memory
                 * contents in RBD.
                 *
                 * So we rely on the Java bindings for RBD to create our snapshot
                 *
                 * This snapshot might not be 100% consistent due to writes still being in the
                 * memory of the Virtual Machine, but if the VM runs a kernel which supports
                 * barriers properly (>2.6.32) this won't be any different then pulling the power
                 * cord out of a running machine.
                 */
                if (primaryPool.getType() == StoragePoolType.RBD) {
                    try {
                        Rados r = new Rados(primaryPool.getAuthUserName());
                        r.confSet("mon_host", primaryPool.getSourceHost() + ":" + primaryPool.getSourcePort());
                        r.confSet("key", primaryPool.getAuthSecret());
                        r.connect();
                        s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));

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

                        if (cmd.getCommandSwitch().equalsIgnoreCase(
                            ManageSnapshotCommand.CREATE_SNAPSHOT)) {
View Full Code Here

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

        String secondaryStoragePoolUrl = cmd.getSecondaryStorageUrl();
        String snapshotName = cmd.getSnapshotName();
        String snapshotDestPath = null;
        String snapshotRelPath = null;
        String vmName = cmd.getVmName();
        KVMStoragePool secondaryStoragePool = null;
        try {
            Connect conn = LibvirtConnection.getConnectionByVmName(vmName);

            secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
                    secondaryStoragePoolUrl);

            String ssPmountPath = secondaryStoragePool.getLocalPath();
            snapshotRelPath = File.separator + "snapshots" + File.separator
                    + dcId + File.separator + accountId + File.separator
                    + volumeId;

            snapshotDestPath = ssPmountPath + File.separator + "snapshots"
                    + File.separator + dcId + File.separator + accountId
                    + File.separator + volumeId;
            KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool(
                    cmd.getPool().getType(),
                    cmd.getPrimaryStoragePoolNameLabel());
            KVMPhysicalDisk snapshotDisk = primaryPool.getPhysicalDisk(cmd
                    .getVolumePath());

            /**
             * RBD snapshots can't be copied using qemu-img, so we have to use
             * the Java bindings for librbd here.
             *
             * These bindings will read the snapshot and write the contents to
             * the secondary storage directly
             *
             * It will stop doing so if the amount of time spend is longer then
             * cmds.timeout
             */
            if (primaryPool.getType() == StoragePoolType.RBD) {
                try {
                    Rados r = new Rados(primaryPool.getAuthUserName());
                    r.confSet("mon_host", primaryPool.getSourceHost() + ":" + primaryPool.getSourcePort());
                    r.confSet("key", primaryPool.getAuthSecret());
                    r.connect();
                    s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));

                    IoCTX io = r.ioCtxCreate(primaryPool.getSourceDir());
                    Rbd rbd = new Rbd(io);
                    RbdImage image = rbd.open(snapshotDisk.getName(), snapshotName);

                    File fh = new File(snapshotDestPath);
                    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fh));
                    int chunkSize = 4194304;
                    long offset = 0;
                    s_logger.debug("Backuping up RBD snapshot " + snapshotName + " to  " + snapshotDestPath);
                    while(true) {
                        byte[] buf = new byte[chunkSize];

                        int bytes = image.read(offset, buf, chunkSize);
                        if (bytes <= 0) {
                            break;
                        }
                        bos.write(buf, 0, bytes);
                        offset += bytes;
                    }
                    s_logger.debug("Completed backing up RBD snapshot " + snapshotName + " to  " + snapshotDestPath + ". Bytes written: " + offset);
                    bos.close();
                    r.ioCtxDestroy(io);
                } catch (RadosException e) {
                    s_logger.error("A RADOS operation failed. The error was: " + e.getMessage());
                    return new BackupSnapshotAnswer(cmd, false, e.toString(), null, true);
                } catch (RbdException e) {
                    s_logger.error("A RBD operation on " + snapshotDisk.getName() + " failed. The error was: " + e.getMessage());
                    return new BackupSnapshotAnswer(cmd, false, e.toString(), null, true);
                } catch (FileNotFoundException e) {
                    s_logger.error("Failed to open " + snapshotDestPath + ". The error was: " + e.getMessage());
                    return new BackupSnapshotAnswer(cmd, false, e.toString(), null, true);
                } catch (IOException e) {
                    s_logger.debug("An I/O error occured during a snapshot operation on " + snapshotDestPath);
                    return new BackupSnapshotAnswer(cmd, false, e.toString(), null, true);
                }
            } else {
                Script command = new Script(_manageSnapshotPath, _cmdsTimeout,
                        s_logger);
                command.add("-b", snapshotDisk.getPath());
                command.add("-n", snapshotName);
                command.add("-p", snapshotDestPath);
                command.add("-t", snapshotName);
                String result = command.execute();
                if (result != null) {
                    s_logger.debug("Failed to backup snaptshot: " + result);
                    return new BackupSnapshotAnswer(cmd, false, result, null, true);
                }
            }
            /* Delete the snapshot on primary */

            DomainInfo.DomainState state = null;
            Domain vm = null;
            if (vmName != null) {
                try {
                    vm = getDomain(conn, cmd.getVmName());
                    state = vm.getInfo().state;
                } catch (LibvirtException e) {
                    s_logger.trace("Ignoring libvirt error.", e);
                }
            }

            KVMStoragePool primaryStorage = _storagePoolMgr.getStoragePool(
                    cmd.getPool().getType(),
                    cmd.getPool().getUuid());
            if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING
                    && !primaryStorage.isExternalSnapshot()) {
                String vmUuid = vm.getUUIDString();
                Object[] args = new Object[] { snapshotName, vmUuid };
                String snapshot = SnapshotXML.format(args);
                s_logger.debug(snapshot);
                DomainSnapshot snap = vm.snapshotLookupByName(snapshotName);
View Full Code Here

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

        try {

            String snapshotPath = cmd.getSnapshotUuid();
            int index = snapshotPath.lastIndexOf("/");
            snapshotPath = snapshotPath.substring(0, index);
            KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(
                    cmd.getSecondaryStorageUrl()
                    + snapshotPath);
            KVMPhysicalDisk snapshot = secondaryPool.getPhysicalDisk(cmd
                    .getSnapshotName());

            String primaryUuid = cmd.getPrimaryStoragePoolNameLabel();
            KVMStoragePool primaryPool = _storagePoolMgr
                    .getStoragePool(cmd.getPool().getType(),
                            primaryUuid);
            String volUuid = UUID.randomUUID().toString();
            KVMPhysicalDisk disk = _storagePoolMgr.copyPhysicalDisk(snapshot,
                    volUuid, primaryPool, 0);
View Full Code Here

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

        String templateFolder = cmd.getAccountId() + File.separator
                + cmd.getNewTemplateId();
        String templateInstallFolder = "template/tmpl/" + templateFolder;
        String tmplName = UUID.randomUUID().toString();
        String tmplFileName = tmplName + ".qcow2";
        KVMStoragePool secondaryPool = null;
        KVMStoragePool snapshotPool = null;
        try {
            String snapshotPath = cmd.getSnapshotUuid();
            int index = snapshotPath.lastIndexOf("/");
            snapshotPath = snapshotPath.substring(0, index);
            snapshotPool = _storagePoolMgr.getStoragePoolByURI(cmd
                    .getSecondaryStorageUrl() + snapshotPath);
            KVMPhysicalDisk snapshot = snapshotPool.getPhysicalDisk(cmd
                    .getSnapshotName());

            secondaryPool = _storagePoolMgr.getStoragePoolByURI(
                    cmd.getSecondaryStorageUrl());

            String templatePath = secondaryPool.getLocalPath() + File.separator
                    + templateInstallFolder;

            _storage.mkdirs(templatePath);

            String tmplPath = templateInstallFolder + File.separator
                    + tmplFileName;
            Script command = new Script(_createTmplPath, _cmdsTimeout, s_logger);
            command.add("-t", templatePath);
            command.add("-n", tmplFileName);
            command.add("-f", snapshot.getPath());
            command.execute();

            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(templatePath, null,
                    tmplName);

            TemplateLocation loc = new TemplateLocation(_storage, templatePath);
            loc.create(1, true, tmplName);
            loc.addFormat(info);
            loc.save();

            return new CreatePrivateTemplateAnswer(cmd, true, "", tmplPath,
                    info.virtualSize, info.size, tmplName, info.format);
        } catch (ConfigurationException e) {
            return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
        } catch (InternalErrorException e) {
            return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
        } catch (IOException e) {
            return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
        } catch (CloudRuntimeException e) {
            return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
        } finally {
            if (secondaryPool != null) {
                _storagePoolMgr.deleteStoragePool(secondaryPool.getType(), secondaryPool.getUuid());
            }
            if (snapshotPool != null) {
                _storagePoolMgr.deleteStoragePool(snapshotPool.getType(), snapshotPool.getUuid());
            }
        }
    }
View Full Code Here

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

        }
    }

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

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

    protected CreatePrivateTemplateAnswer execute(
            CreatePrivateTemplateFromVolumeCommand cmd) {
        String secondaryStorageURL = cmd.getSecondaryStorageUrl();

        KVMStoragePool secondaryStorage = null;
        KVMStoragePool primary = null;
        try {
            String templateFolder = cmd.getAccountId() + File.separator
                    + cmd.getTemplateId() + File.separator;
            String templateInstallFolder = "/template/tmpl/" + templateFolder;

            secondaryStorage = _storagePoolMgr.getStoragePoolByURI(
                    secondaryStorageURL);

            try {
                primary = _storagePoolMgr.getStoragePool(
                    cmd.getPool().getType(),
                    cmd.getPrimaryStoragePoolNameLabel());
            } catch (CloudRuntimeException e) {
                if (e.getMessage().contains("not found")) {
                    primary = _storagePoolMgr.createStoragePool(cmd.getPool().getUuid(),
                                      cmd.getPool().getHost(), cmd.getPool().getPort(),
                                      cmd.getPool().getPath(), cmd.getPool().getUserInfo(),
                                      cmd.getPool().getType());
                } else {
                    return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage());
                }
            }

            KVMPhysicalDisk disk = primary.getPhysicalDisk(cmd.getVolumePath());
            String tmpltPath = secondaryStorage.getLocalPath() + File.separator
                    + templateInstallFolder;
            _storage.mkdirs(tmpltPath);

            if (primary.getType() != StoragePoolType.RBD) {
                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);
                }
            } else {
                s_logger.debug("Converting RBD disk " + disk.getPath() + " into template " + cmd.getUniqueName());

                QemuImgFile srcFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(),
                                primary.getSourcePort(),
                                primary.getAuthUserName(),
                                primary.getAuthSecret(),
                                disk.getPath()));
                srcFile.setFormat(PhysicalDiskFormat.RAW);

                QemuImgFile destFile = new QemuImgFile(tmpltPath + "/" + cmd.getUniqueName() + ".qcow2");
                destFile.setFormat(PhysicalDiskFormat.QCOW2);
View Full Code Here

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

        if (index < tmplturl.length() - 1) {
            tmpltname = tmplturl.substring(index + 1);
        }

        KVMPhysicalDisk tmplVol = null;
        KVMStoragePool secondaryPool = null;
        try {
            secondaryPool = _storagePoolMgr.getStoragePoolByURI(mountpoint);

            /* Get template vol */
            if (tmpltname == null) {
                secondaryPool.refresh();
                List<KVMPhysicalDisk> disks = secondaryPool.listPhysicalDisks();
                if (disks == null || disks.isEmpty()) {
                    return new PrimaryStorageDownloadAnswer(
                            "Failed to get volumes from pool: "
                                    + secondaryPool.getUuid());
                }
                for (KVMPhysicalDisk disk : disks) {
                    if (disk.getName().endsWith("qcow2")) {
                        tmplVol = disk;
                        break;
                    }
                }
                if (tmplVol == null) {
                    return new PrimaryStorageDownloadAnswer(
                            "Failed to get template from pool: "
                                    + secondaryPool.getUuid());
                }
            } else {
                tmplVol = secondaryPool.getPhysicalDisk(tmpltname);
            }

            /* Copy volume to primary storage */
            KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool(
                    cmd.getPool().getType(),
                    cmd.getPoolUuid());

            KVMPhysicalDisk primaryVol = _storagePoolMgr.copyPhysicalDisk(
                    tmplVol, UUID.randomUUID().toString(), primaryPool, 0);
View Full Code Here

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

    protected Answer execute(CreateStoragePoolCommand cmd) {
        return new Answer(cmd, true, "success");
    }

    protected Answer execute(ModifyStoragePoolCommand cmd) {
        KVMStoragePool storagepool = _storagePoolMgr.createStoragePool(cmd
                .getPool().getUuid(), cmd.getPool().getHost(),
                cmd.getPool().getPort(), cmd.getPool().getPath(),
                cmd.getPool().getUserInfo(), cmd.getPool().getType());
        if (storagepool == null) {
            return new Answer(cmd, false, " Failed to create storage pool");
        }

        Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
        ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd,
                storagepool.getCapacity(), storagepool.getAvailable(), tInfo);

        return answer;
    }
View Full Code Here

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

    }

    private AttachVolumeAnswer execute(AttachVolumeCommand cmd) {
        try {
            Connect conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName());
            KVMStoragePool primary = _storagePoolMgr.getStoragePool(
                    cmd.getPooltype(),
                    cmd.getPoolUuid());
            KVMPhysicalDisk disk = primary.getPhysicalDisk(cmd.getVolumePath());
            attachOrDetachDisk(conn, cmd.getAttach(), cmd.getVmName(), disk,
                    cmd.getDeviceId().intValue(), cmd.getBytesReadRate(), cmd.getBytesWriteRate(), cmd.getIopsReadRate(), cmd.getIopsWriteRate());
        } catch (LibvirtException e) {
            return new AttachVolumeAnswer(cmd, e.toString());
        } catch (InternalErrorException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.