当前位置: 首页>>代码示例>>Java>>正文


Java LibvirtException.toString方法代码示例

本文整理汇总了Java中org.libvirt.LibvirtException.toString方法的典型用法代码示例。如果您正苦于以下问题:Java LibvirtException.toString方法的具体用法?Java LibvirtException.toString怎么用?Java LibvirtException.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.libvirt.LibvirtException的用法示例。


在下文中一共展示了LibvirtException.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: listPhysicalDisks

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
@Override
public List<KvmPhysicalDisk> listPhysicalDisks(final String storagePoolUuid, final KvmStoragePool pool) {
    final LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    final StoragePool virtPool = libvirtPool.getPool();
    final List<KvmPhysicalDisk> disks = new ArrayList<>();
    try {
        final String[] vols = virtPool.listVolumes();
        for (final String volName : vols) {
            final KvmPhysicalDisk disk = getPhysicalDisk(volName, pool);
            disks.add(disk);
        }
        return disks;
    } catch (final LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:LibvirtStorageAdaptor.java

示例2: listPhysicalDisks

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
@Override
public List<KVMPhysicalDisk> listPhysicalDisks(String storagePoolUuid, KVMStoragePool pool) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool)pool;
    StoragePool virtPool = libvirtPool.getPool();
    List<KVMPhysicalDisk> disks = new ArrayList<KVMPhysicalDisk>();
    try {
        String[] vols = virtPool.listVolumes();
        for (String volName : vols) {
            KVMPhysicalDisk disk = getPhysicalDisk(volName, pool);
            disks.add(disk);
        }
        return disks;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:17,代码来源:LibvirtStorageAdaptor.java

示例3: execute

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
@Override
public Answer execute(final GetVncPortCommand command, final LibvirtComputingResource libvirtComputingResource) {
    try {
        final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();

        final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getName());
        final Integer vncPort = libvirtComputingResource.getVncPort(conn, command.getName());
        return new GetVncPortAnswer(command, libvirtComputingResource.getPrivateIp(), 5900 + vncPort);
    } catch (final LibvirtException e) {
        return new GetVncPortAnswer(command, e.toString());
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:13,代码来源:LibvirtGetVncPortCommandWrapper.java

示例4: execute

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
@Override
public Answer execute(final CreateVMSnapshotCommand cmd, final LibvirtComputingResource libvirtComputingResource) {
    final String vmName = cmd.getVmName();
    final String vmSnapshotName = cmd.getTarget().getSnapshotName();

    Domain dm = null;
    try {
        final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
        final Connect conn = libvirtUtilitiesHelper.getConnection();
        dm = libvirtComputingResource.getDomain(conn, vmName);

        if (dm == null) {
            return new CreateVMSnapshotAnswer(cmd, false, "Create VM Snapshot Failed due to can not find vm: " + vmName);
        }

        final DomainState domainState = dm.getInfo().state;
        if (domainState != DomainState.VIR_DOMAIN_RUNNING) {
            return new CreateVMSnapshotAnswer(cmd, false, "Create VM Snapshot Failed due to  vm is not running: " + vmName + " with domainState = " + domainState);
        }

        final String vmSnapshotXML = "<domainsnapshot><name>" + vmSnapshotName + "</name><memory snapshot='internal' /></domainsnapshot>";

        dm.snapshotCreateXML(vmSnapshotXML);

        return new CreateVMSnapshotAnswer(cmd, cmd.getTarget(), cmd.getVolumeTOs());
    } catch (final LibvirtException e) {
        final String msg = " Create VM snapshot failed due to " + e.toString();
        s_logger.warn(msg, e);
        return new CreateVMSnapshotAnswer(cmd, false, msg);
    } finally {
        if (dm != null) {
            try {
                dm.free();
            } catch (final LibvirtException l) {
                s_logger.trace("Ignoring libvirt error.", l);
            }
        }
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:40,代码来源:LibvirtCreateVMSnapshotCommandWrapper.java

示例5: execute

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
@Override
public Answer execute(final UnPlugNicCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final NicTO nic = command.getNic();
    final String vmName = command.getVmName();
    Domain vm = null;
    try {
        final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();

        final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vmName);
        vm = libvirtComputingResource.getDomain(conn, vmName);
        final List<InterfaceDef> pluggedNics = libvirtComputingResource.getInterfaces(conn, vmName);

        for (final InterfaceDef pluggedNic : pluggedNics) {
            if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) {
                vm.detachDevice(pluggedNic.toString());
                // We don't know which "traffic type" is associated with
                // each interface at this point, so inform all vif drivers
                for (final VifDriver vifDriver : libvirtComputingResource.getAllVifDrivers()) {
                    vifDriver.unplug(pluggedNic);
                }
                return new UnPlugNicAnswer(command, true, "success");
            }
        }
        return new UnPlugNicAnswer(command, true, "success");
    } catch (final LibvirtException e) {
        final String msg = " Unplug Nic failed due to " + e.toString();
        s_logger.warn(msg, e);
        return new UnPlugNicAnswer(command, false, msg);
    } finally {
        if (vm != null) {
            try {
                vm.free();
            } catch (final LibvirtException l) {
                s_logger.trace("Ignoring libvirt error.", l);
            }
        }
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:39,代码来源:LibvirtUnPlugNicCommandWrapper.java

示例6: execute

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
@Override
public Answer execute(final SecurityGroupRulesCmd command, final LibvirtComputingResource libvirtComputingResource) {
    String vif = null;
    String brname = null;
    try {
        final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();

        final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName());
        final List<InterfaceDef> nics = libvirtComputingResource.getInterfaces(conn, command.getVmName());

        vif = nics.get(0).getDevName();
        brname = nics.get(0).getBrName();
    } catch (final LibvirtException e) {
        return new SecurityGroupRuleAnswer(command, false, e.toString());
    }

    final boolean result = libvirtComputingResource.addNetworkRules(command.getVmName(),
            Long.toString(command.getVmId()), command.getGuestIp(), command.getSignature(),
            Long.toString(command.getSeqNum()), command.getGuestMac(), command.stringifyRules(), vif, brname,
            command.getSecIpsString());

    if (!result) {
        s_logger.warn("Failed to program network rules for vm " + command.getVmName());
        return new SecurityGroupRuleAnswer(command, false, "programming network rules failed");
    } else {
        s_logger.debug("Programmed network rules for vm " + command.getVmName() + " guestIp=" + command.getGuestIp()
                + ",ingress numrules="
                + command.getIngressRuleSet().length + ",egress numrules=" + command.getEgressRuleSet().length);
        return new SecurityGroupRuleAnswer(command);
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:32,代码来源:LibvirtSecurityGroupRulesCommandWrapper.java

示例7: getPhysicalDisk

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
@Override
public KvmPhysicalDisk getPhysicalDisk(final String volumeUuid, final KvmStoragePool pool) {
    final LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;

    try {
        final StorageVol vol = getVolume(libvirtPool.getPool(), volumeUuid);
        final KvmPhysicalDisk disk;
        final 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 (pool.getType() == StoragePoolType.RBD) {
            disk.setFormat(PhysicalDiskFormat.RAW);
        } else if (voldef.getFormat() == null) {
            final File diskDir = new File(disk.getPath());
            if (diskDir.exists() && diskDir.isDirectory()) {
                disk.setFormat(PhysicalDiskFormat.DIR);
            } else if (volumeUuid.endsWith("tar") || volumeUuid.endsWith("TAR")) {
                disk.setFormat(PhysicalDiskFormat.TAR);
            } else if (volumeUuid.endsWith("raw") || volumeUuid.endsWith("RAW")) {
                disk.setFormat(PhysicalDiskFormat.RAW);
            } else {
                disk.setFormat(pool.getDefaultFormat());
            }
        } else if (voldef.getFormat() == LibvirtStorageVolumeDef.VolumeFormat.QCOW2) {
            disk.setFormat(PhysicalDiskFormat.QCOW2);
        } else if (voldef.getFormat() == LibvirtStorageVolumeDef.VolumeFormat.RAW) {
            disk.setFormat(PhysicalDiskFormat.RAW);
        }
        return disk;
    } catch (final LibvirtException e) {
        logger.debug("Failed to get physical disk:", e);
        throw new CloudRuntimeException(e.toString());
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:37,代码来源:LibvirtStorageAdaptor.java

示例8: createPhysicalDiskByLibVirt

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
private KvmPhysicalDisk createPhysicalDiskByLibVirt(final String name, final KvmStoragePool pool,
                                                    final PhysicalDiskFormat format, final Storage.ProvisioningType provisioningType, final long size) {
    final LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    final StoragePool virtPool = libvirtPool.getPool();
    final LibvirtStorageVolumeDef.VolumeFormat libvirtformat = LibvirtStorageVolumeDef.VolumeFormat.getFormat(format);

    String volPath = null;
    String volName = null;
    long volAllocation = 0;
    long volCapacity = 0;

    final LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(name,
            size, libvirtformat, null, null);
    logger.debug(volDef.toString());
    try {
        final StorageVol vol = virtPool.storageVolCreateXML(volDef.toString(), 0);
        volPath = vol.getPath();
        volName = vol.getName();
        volAllocation = vol.getInfo().allocation;
        volCapacity = vol.getInfo().capacity;
    } catch (final LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }

    final KvmPhysicalDisk disk = new KvmPhysicalDisk(volPath, volName, pool);
    disk.setFormat(format);
    disk.setSize(volAllocation);
    disk.setVirtualSize(volCapacity);
    return disk;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:31,代码来源:LibvirtStorageAdaptor.java

示例9: getPhysicalDisk

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
@Override
public KvmPhysicalDisk getPhysicalDisk(final String volumeUuid, final KvmStoragePool pool) {
    // now create the volume upon the given storage pool in kvm
    final Connect conn;
    StoragePool virtPool = null;
    try {
        conn = LibvirtConnection.getConnection();
        virtPool = conn.storagePoolLookupByName("/" + volumeUuid);
    } catch (final LibvirtException e1) {
        throw new CloudRuntimeException(e1.toString());
    }

    LibvirtStorageVolumeDef.VolumeFormat libvirtformat = null;
    long volCapacity = 0;
    // check whether the volume is present on the given pool
    StorageVol vol = getVolume(virtPool, volumeUuid);
    try {
        if (vol == null) {

            libvirtformat = LibvirtStorageVolumeDef.VolumeFormat.QCOW2;

            final StoragePoolInfo poolinfo = virtPool.getInfo();
            volCapacity = poolinfo.available;

            final LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(volumeUuid, volCapacity, libvirtformat, null,
                    null);
            logger.debug(volDef.toString());

            vol = virtPool.storageVolCreateXML(volDef.toString(), 0);
        }
        final KvmPhysicalDisk disk = new KvmPhysicalDisk(vol.getPath(), volumeUuid, pool);
        disk.setFormat(PhysicalDiskFormat.QCOW2);
        disk.setSize(vol.getInfo().allocation);
        disk.setVirtualSize(vol.getInfo().capacity);
        return disk;
    } catch (final LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:40,代码来源:ManagedNfsStorageAdaptor.java

示例10: execute

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
@Override
public Answer execute(final SecurityGroupRulesCmd command, final LibvirtComputingResource libvirtComputingResource) {
    String vif = null;
    String brname = null;
    try {
        final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();

        final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName());
        final List<InterfaceDef> nics = libvirtComputingResource.getInterfaces(conn, command.getVmName());

        vif = nics.get(0).getDevName();
        brname = nics.get(0).getBrName();
    } catch (final LibvirtException e) {
        return new SecurityGroupRuleAnswer(command, false, e.toString());
    }

    final boolean result = libvirtComputingResource.addNetworkRules(command.getVmName(), Long.toString(command.getVmId()), command.getGuestIp(), command.getGuestIp6(), command.getSignature(),
            Long.toString(command.getSeqNum()), command.getGuestMac(), command.stringifyRules(), vif, brname, command.getSecIpsString());

    if (!result) {
        s_logger.warn("Failed to program network rules for vm " + command.getVmName());
        return new SecurityGroupRuleAnswer(command, false, "programming network rules failed");
    } else {
        s_logger.debug("Programmed network rules for vm " + command.getVmName() + " guestIp=" + command.getGuestIp() + ",ingress numrules="
                + command.getIngressRuleSet().size() + ",egress numrules=" + command.getEgressRuleSet().size());
        return new SecurityGroupRuleAnswer(command);
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:29,代码来源:LibvirtSecurityGroupRulesCommandWrapper.java

示例11: prepareNetworkElementCommand

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
private ExecutionResult prepareNetworkElementCommand(final SetupGuestNetworkCommand cmd) {
    Connect conn;
    final NicTO nic = cmd.getNic();
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);

    try {
        conn = LibvirtConnection.getConnectionByVmName(routerName);
        final List<InterfaceDef> pluggedNics = getInterfaces(conn, routerName);
        InterfaceDef routerNic = null;

        for (final InterfaceDef pluggedNic : pluggedNics) {
            if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) {
                routerNic = pluggedNic;
                break;
            }
        }

        if (routerNic == null) {
            return new ExecutionResult(false, "Can not find nic with mac " + nic.getMac() + " for VM " + routerName);
        }

        return new ExecutionResult(true, null);
    } catch (final LibvirtException e) {
        final String msg = "Creating guest network failed due to " + e.toString();
        s_logger.warn(msg, e);
        return new ExecutionResult(false, msg);
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:29,代码来源:LibvirtComputingResource.java

示例12: createPhysicalDiskByLibVirt

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
private KVMPhysicalDisk createPhysicalDiskByLibVirt(String name, KVMStoragePool pool,
        PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) {
    LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
    StoragePool virtPool = libvirtPool.getPool();
    LibvirtStorageVolumeDef.VolumeFormat libvirtformat = LibvirtStorageVolumeDef.VolumeFormat.getFormat(format);

    String volPath = null;
    String volName = null;
    long volAllocation = 0;
    long volCapacity = 0;

    LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(name,
            size, libvirtformat, null, null);
    s_logger.debug(volDef.toString());
    try {
        StorageVol vol = virtPool.storageVolCreateXML(volDef.toString(), 0);
        volPath = vol.getPath();
        volName = vol.getName();
        volAllocation = vol.getInfo().allocation;
        volCapacity = vol.getInfo().capacity;
    } catch (LibvirtException e) {
        throw new CloudRuntimeException(e.toString());
    }

    KVMPhysicalDisk disk = new KVMPhysicalDisk(volPath, volName, pool);
    disk.setFormat(format);
    disk.setSize(volAllocation);
    disk.setVirtualSize(volCapacity);
    return disk;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:31,代码来源:LibvirtStorageAdaptor.java

示例13: execute

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
@Override
public Answer execute(final DeleteVMSnapshotCommand cmd, final LibvirtComputingResource libvirtComputingResource) {
    final String vmName = cmd.getVmName();

    final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    Domain dm = null;
    DomainSnapshot snapshot = null;
    try {
        final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
        final Connect conn = libvirtUtilitiesHelper.getConnection();
        dm = libvirtComputingResource.getDomain(conn, vmName);

        snapshot = dm.snapshotLookupByName(cmd.getTarget().getSnapshotName());

        snapshot.delete(0); // only remove this snapshot, not children

        return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs());
    } catch (final LibvirtException e) {
        final String msg = " Delete VM snapshot failed due to " + e.toString();

        if (dm == null) {
            s_logger.debug("Can not find running vm: " + vmName + ", now we are trying to delete the vm snapshot using qemu-img if the format of root volume is QCOW2");
            VolumeObjectTO rootVolume = null;
            for (VolumeObjectTO volume: cmd.getVolumeTOs()) {
                if (volume.getVolumeType() == Volume.Type.ROOT) {
                    rootVolume = volume;
                    break;
                }
            }
            if (rootVolume != null && ImageFormat.QCOW2.equals(rootVolume.getFormat())) {
                final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) rootVolume.getDataStore();
                final KvmPhysicalDisk rootDisk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), rootVolume.getPath());
                final String command = "qemu-img snapshot -l " + rootDisk.getPath() + " | tail -n +3 | awk -F ' ' '{print $2}' | grep ^" + cmd.getTarget().getSnapshotName() + "$";
                final String qemu_img_snapshot = Script.runSimpleBashScript(command);
                if (qemu_img_snapshot == null) {
                    s_logger.info("Cannot find snapshot " + cmd.getTarget().getSnapshotName() + " in file " + rootDisk.getPath() + ", return true");
                    return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs());
                }
                int result = Script.runSimpleBashScriptForExitValue("qemu-img snapshot -d " + cmd.getTarget().getSnapshotName() + " " + rootDisk.getPath());
                if (result != 0) {
                    return new DeleteVMSnapshotAnswer(cmd, false, "Delete VM Snapshot Failed due to can not remove snapshot from image file " +
                            rootDisk.getPath()  + " : " + result);
                } else {
                    return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs());
                }
            }
        } else if (snapshot == null) {
            s_logger.debug("Can not find vm snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + ", return true");
            return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs());
        }

        s_logger.warn(msg, e);
        return new DeleteVMSnapshotAnswer(cmd, false, msg);
    } finally {
        if (dm != null) {
            try {
                dm.free();
            } catch (final LibvirtException l) {
                s_logger.trace("Ignoring libvirt error.", l);
            }
        }
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:64,代码来源:LibvirtDeleteVMSnapshotCommandWrapper.java

示例14: execute

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
@Override
public Answer execute(final RevertToVMSnapshotCommand cmd, final LibvirtComputingResource libvirtComputingResource) {
    final String vmName = cmd.getVmName();
    final List<VolumeObjectTO> listVolumeTo = cmd.getVolumeTOs();
    final VMSnapshot.Type vmSnapshotType = cmd.getTarget().getType();
    final Boolean snapshotMemory = vmSnapshotType == VMSnapshot.Type.DiskAndMemory;
    PowerState vmState;

    Domain dm = null;
    try {
        final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
        final Connect conn = libvirtUtilitiesHelper.getConnection();
        dm = libvirtComputingResource.getDomain(conn, vmName);

        if (dm == null) {
            return new RevertToVMSnapshotAnswer(cmd, false, "Revert to VM Snapshot Failed due to can not find vm: " + vmName);
        }

        final DomainSnapshot snapshot = dm.snapshotLookupByName(cmd.getTarget().getSnapshotName());
        if (snapshot == null) {
            return new RevertToVMSnapshotAnswer(cmd, false, "Cannot find vmSnapshot with name: " + cmd.getTarget().getSnapshotName());
        }

        dm.revertToSnapshot(snapshot);
        snapshot.free();

        if (!snapshotMemory) {
            dm.destroy();
            if (dm.isPersistent() == 1) {
                dm.undefine();
            }
            vmState = PowerState.PowerOff;
        } else {
            vmState = PowerState.PowerOn;
        }

        return new RevertToVMSnapshotAnswer(cmd, listVolumeTo, vmState);
    } catch (final LibvirtException e) {
        final String msg = " Revert to VM snapshot failed due to " + e.toString();
        s_logger.warn(msg, e);
        return new RevertToVMSnapshotAnswer(cmd, false, msg);
    } finally {
        if (dm != null) {
            try {
                dm.free();
            } catch (LibvirtException l) {
                s_logger.trace("Ignoring libvirt error.", l);
            };
        }
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:52,代码来源:LibvirtRevertToVMSnapshotCommandWrapper.java

示例15: getStoragePool

import org.libvirt.LibvirtException; //导入方法依赖的package包/类
@Override
public KvmStoragePool getStoragePool(final String uuid, final boolean refreshInfo) {
    logger.info("Trying to fetch storage pool " + uuid + " from libvirt");
    StoragePool storage = null;
    try {
        final Connect conn = LibvirtConnection.getConnection();
        storage = conn.storagePoolLookupByUUIDString(uuid);

        if (storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
            logger.warn("Storage pool " + uuid + " is not in running state. Attempting to start it.");
            storage.create(0);
        }
        final LibvirtStoragePoolDef spd = getStoragePoolDef(conn, storage);
        if (spd == null) {
            throw new CloudRuntimeException("Unable to parse the storage pool definition for storage pool " + uuid);
        }
        StoragePoolType type = null;
        if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.NETFS) {
            type = StoragePoolType.NetworkFilesystem;
        } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.DIR) {
            type = StoragePoolType.Filesystem;
        } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.RBD) {
            type = StoragePoolType.RBD;
        } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.LOGICAL) {
            type = StoragePoolType.CLVM;
        } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.GLUSTERFS) {
            type = StoragePoolType.Gluster;
        }

        final LibvirtStoragePool pool = new LibvirtStoragePool(uuid, storage.getName(), type, this, storage);

        if (pool.getType() != StoragePoolType.RBD) {
            pool.setLocalPath(spd.getTargetPath());
        } else {
            pool.setLocalPath("");
        }

        if (pool.getType() == StoragePoolType.RBD
                || pool.getType() == StoragePoolType.Gluster) {
            pool.setSourceHost(spd.getSourceHost());
            pool.setSourcePort(spd.getSourcePort());
            pool.setSourceDir(spd.getSourceDir());
            final String authUsername = spd.getAuthUserName();
            if (authUsername != null) {
                final Secret secret = conn.secretLookupByUUIDString(spd.getSecretUuid());
                final String secretValue = new String(Base64.encodeBase64(secret.getByteValue()), Charset.defaultCharset());
                pool.setAuthUsername(authUsername);
                pool.setAuthSecret(secretValue);
            }
        }

        if (refreshInfo) {
            logger.info("Asking libvirt to refresh storage pool " + uuid);
            pool.refresh();
        }
        pool.setCapacity(storage.getInfo().capacity);
        pool.setUsed(storage.getInfo().allocation);
        pool.setAvailable(storage.getInfo().available);

        logger.debug("Succesfully refreshed pool " + uuid
                + " Capacity: " + storage.getInfo().capacity
                + " Used: " + storage.getInfo().allocation
                + " Available: " + storage.getInfo().available);

        return pool;
    } catch (final LibvirtException e) {
        logger.debug("Could not find storage pool " + uuid + " in libvirt");
        throw new CloudRuntimeException(e.toString(), e);
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:71,代码来源:LibvirtStorageAdaptor.java


注:本文中的org.libvirt.LibvirtException.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。