• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Connect类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getConnectionByVmName

import org.libvirt.Connect; //导入依赖的package包/类
public static Connect getConnectionByVmName(final String vmName) throws LibvirtException {
    final HypervisorType[] hypervisors = new HypervisorType[]{HypervisorType.KVM};

    for (final HypervisorType hypervisor : hypervisors) {
        try {
            final Connect conn = LibvirtConnection.getConnectionByType(hypervisor.toString());
            if (conn.domainLookupByName(vmName) != null) {
                return conn;
            }
        } catch (final Exception e) {
            LOGGER.debug(
                    "Can not find " + hypervisor.toString() + " connection for Instance: " + vmName + ", continuing.");
        }
    }

    LOGGER.warn("Can not find a connection for Instance " + vmName + ". Assuming the default connection.");
    // return the default connection
    return getConnection();
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:20,代码来源:LibvirtConnection.java


示例2: execute

import org.libvirt.Connect; //导入依赖的package包/类
@Override
public Answer execute(final NetworkRulesVmSecondaryIpCommand command,
                      final LibvirtComputingResource libvirtComputingResource) {
    boolean result = false;
    try {
        final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();

        final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName());
        result = libvirtComputingResource.configureNetworkRulesVmSecondaryIp(conn, command.getVmName(),
                command.getVmSecIp(), command.getAction());
    } catch (final LibvirtException e) {
        s_logger.debug("Could not configure VM secondary IP! => " + e.getLocalizedMessage());
    }

    return new Answer(command, result, "");
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:LibvirtNetworkRulesVmSecondaryIpCommandWrapper.java


示例3: execute

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

        final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName());
        final PowerState state = libvirtComputingResource.getVmState(conn, command.getVmName());
        Integer vncPort = null;
        if (state == PowerState.PowerOn) {
            vncPort = libvirtComputingResource.getVncPort(conn, command.getVmName());
        }

        return new CheckVirtualMachineAnswer(command, state, vncPort);
    } catch (final LibvirtException e) {
        return new CheckVirtualMachineAnswer(command, e.getMessage());
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:19,代码来源:LibvirtCheckVirtualMachineCommandWrapper.java


示例4: getFreeMemory

import org.libvirt.Connect; //导入依赖的package包/类
private Long getFreeMemory(final Connect conn, final LibvirtComputingResource libvirtComputingResource) {
    try {
        long allocatedMem = 0;
        final int[] ids = conn.listDomains();
        for (final int id : ids) {
            final Domain dm = conn.domainLookupByID(id);
            allocatedMem += dm.getMaxMemory() * 1024L;
            s_logger.debug("vm: " + dm.getName() + " mem: " + dm.getMaxMemory() * 1024L);
        }
        final Long remainingMem = libvirtComputingResource.getTotalMemory() - allocatedMem;
        s_logger.debug("remaining mem" + remainingMem);
        return remainingMem;
    } catch (final Exception e) {
        s_logger.debug("failed to get free memory", e);
        return null;
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:18,代码来源:LibvirtStartCommandWrapper.java


示例5: prepareNetworkElementCommand

import org.libvirt.Connect; //导入依赖的package包/类
protected ExecutionResult prepareNetworkElementCommand(final UpdateNetworkOverviewCommand cmd) {
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);

    try {
        final Connect conn = LibvirtConnection.getConnectionByVmName(routerName);
        final Map<String, Integer> bridgeToNicNum = new HashMap<>();
        final List<InterfaceDef> pluggedNics = getInterfaces(conn, routerName);

        buildBridgeToNicNumHashMap(bridgeToNicNum, pluggedNics);

        return new ExecutionResult(true, null);
    } catch (final LibvirtException e) {
        logger.error("Ip Assoc failure on applying one ip due to exception:  ", e);
        return new ExecutionResult(false, e.getMessage());
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:LibvirtComputingResource.java


示例6: vifHotPlug

import org.libvirt.Connect; //导入依赖的package包/类
private void vifHotPlug(final Connect conn, final String vmName, final String broadcastUri, final String macAddr)
        throws InternalErrorException, LibvirtException {
    final NicTO nicTo = new NicTO();
    nicTo.setMac(macAddr);
    nicTo.setType(TrafficType.Public);
    if (broadcastUri == null) {
        nicTo.setBroadcastType(BroadcastDomainType.Native);
    } else {
        final URI uri = BroadcastDomainType.fromString(broadcastUri);
        nicTo.setBroadcastType(BroadcastDomainType.getSchemeValue(uri));
        nicTo.setBroadcastUri(uri);
    }

    final Domain vm = getDomain(conn, vmName);
    vm.attachDevice(getVifDriver(nicTo.getType()).plug(nicTo, "Default - VirtIO capable OS (64-bit)", "").toString());
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:LibvirtComputingResource.java


示例7: initConnectionToLibvirtDaemon

import org.libvirt.Connect; //导入依赖的package包/类
private void initConnectionToLibvirtDaemon(final LibvirtComputingResourceProperties libvirtComputingResourceProperties) throws ConfigurationException {
    LibvirtConnection.initialize(getHypervisorUri());
    final Connect conn = connectToHypervisor();

    checkIsHvmEnabled(conn);

    hypervisorPath = getHypervisorPath(conn);
    try {
        hvVersion = conn.getVersion();
        hvVersion = hvVersion % 1000000 / 1000;
        hypervisorLibvirtVersion = conn.getLibVirVersion();
        hypervisorQemuVersion = conn.getVersion();
    } catch (final LibvirtException e) {
        logger.trace("Ignoring libvirt error.", e);
    }

    if (libvirtComputingResourceProperties.hasGuestCpuMode()) {
        if (hypervisorLibvirtVersion < 9 * 1000 + 10) {
            logger.warn("Libvirt version 0.9.10 required for guest cpu mode, but version {} detected, so it will be disabled", prettyVersion(hypervisorLibvirtVersion));
            libvirtComputingResourceProperties.unsetGuestCpuMode();
            libvirtComputingResourceProperties.unsetGuestCpuModel();
        }
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:25,代码来源:LibvirtComputingResource.java


示例8: connectToHypervisor

import org.libvirt.Connect; //导入依赖的package包/类
private Connect connectToHypervisor() throws ConfigurationException {
    Connect conn = null;
    try {
        conn = LibvirtConnection.getConnection();

        if (getBridgeType() == OPENVSWITCH) {
            if (conn.getLibVirVersion() < 10 * 1000 + 0) {
                throw new ConfigurationException("Libvirt version 0.10.0 required for openvswitch support, but version "
                        + conn.getLibVirVersion() + " detected");
            }
        }
    } catch (final LibvirtException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
    return conn;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:LibvirtComputingResource.java


示例9: getVmState

import org.libvirt.Connect; //导入依赖的package包/类
public PowerState getVmState(final Connect conn, final String vmName) {
    int retry = 3;
    Domain vms = null;
    while (retry-- > 0) {
        try {
            vms = conn.domainLookupByName(vmName);
            final PowerState s = convertToPowerState(vms.getInfo().state);
            return s;
        } catch (final LibvirtException e) {
            logger.warn("Can't get vm state " + vmName + e.getMessage() + "retry:" + retry);
        } finally {
            try {
                if (vms != null) {
                    vms.free();
                }
            } catch (final LibvirtException l) {
                logger.trace("Ignoring libvirt error.", l);
            }
        }
    }
    return PowerState.PowerOff;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:23,代码来源:LibvirtComputingResource.java


示例10: getVolumePath

import org.libvirt.Connect; //导入依赖的package包/类
public String getVolumePath(final Connect conn, final DiskTO volume) throws LibvirtException, URISyntaxException {
    final DataTO data = volume.getData();
    final DataStoreTO store = data.getDataStore();

    if (volume.getType() == Volume.Type.ISO && data.getPath() != null) {
        final NfsTO nfsStore = (NfsTO) store;
        final String isoPath = nfsStore.getUrl() + File.separator + data.getPath();
        final int index = isoPath.lastIndexOf("/");
        final String path = isoPath.substring(0, index);
        final String name = isoPath.substring(index + 1);
        final KvmStoragePool secondaryPool = storagePoolMgr.getStoragePoolByUri(path);
        final KvmPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
        return isoVol.getPath();
    } else {
        return data.getPath();
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:18,代码来源:LibvirtComputingResource.java


示例11: getVncPort

import org.libvirt.Connect; //导入依赖的package包/类
public Integer getVncPort(final Connect conn, final String vmName) throws LibvirtException {
    final LibvirtDomainXmlParser parser = new LibvirtDomainXmlParser();
    Domain dm = null;
    try {
        dm = conn.domainLookupByName(vmName);
        final String xmlDesc = dm.getXMLDesc(0);
        parser.parseDomainXml(xmlDesc);
        return parser.getVncPort();
    } finally {
        try {
            if (dm != null) {
                dm.free();
            }
        } catch (final LibvirtException l) {
            logger.trace("Ignoring libvirt error.", l);
        }
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:19,代码来源:LibvirtComputingResource.java


示例12: destroyNetworkRulesForVm

import org.libvirt.Connect; //导入依赖的package包/类
public boolean destroyNetworkRulesForVm(final Connect conn, final String vmName) {
    if (!canBridgeFirewall) {
        return false;
    }
    String vif = null;
    final List<InterfaceDef> intfs = getInterfaces(conn, vmName);
    if (intfs.size() > 0) {
        final InterfaceDef intf = intfs.get(0);
        vif = intf.getDevName();
    }
    final Script cmd = new Script(securityGroupPath, getScriptsTimeout(), logger);
    cmd.add("destroy_network_rules_for_vm");
    cmd.add("--vmname", vmName);
    if (vif != null) {
        cmd.add("--vif", vif);
    }
    final String result = cmd.execute();
    if (result != null) {
        return false;
    }
    return true;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:23,代码来源:LibvirtComputingResource.java


示例13: configureNetworkRulesVmSecondaryIp

import org.libvirt.Connect; //导入依赖的package包/类
public boolean configureNetworkRulesVmSecondaryIp(final Connect conn, final String vmName, final String secIp,
                                                  final String action) {

    if (!canBridgeFirewall) {
        return false;
    }

    final Script cmd = new Script(securityGroupPath, getScriptsTimeout(), logger);
    cmd.add("network_rules_vmSecondaryIp");
    cmd.add("--vmname", vmName);
    cmd.add("--nicsecips", secIp);
    cmd.add("--action", action);

    final String result = cmd.execute();
    if (result != null) {
        return false;
    }
    return true;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:20,代码来源:LibvirtComputingResource.java


示例14: attachIso

import org.libvirt.Connect; //导入依赖的package包/类
@Override
public Answer attachIso(final AttachCommand cmd) {
    final DiskTO disk = cmd.getDisk();
    final TemplateObjectTO isoTo = (TemplateObjectTO) disk.getData();
    final DataStoreTO store = isoTo.getDataStore();
    if (!(store instanceof NfsTO)) {
        return new AttachAnswer("unsupported protocol");
    }
    final NfsTO nfsStore = (NfsTO) store;
    try {
        final Connect conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName());
        attachOrDetachIso(conn, cmd.getVmName(), nfsStore.getUrl() + File.separator + isoTo.getPath(), true);
    } catch (final LibvirtException | URISyntaxException | InternalErrorException e) {
        return new Answer(cmd, false, e.toString());
    }

    return new Answer(cmd);
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:19,代码来源:KvmStorageProcessor.java


示例15: getConnect

import org.libvirt.Connect; //导入依赖的package包/类
private Connect getConnect(org.jtestplatform.cloud.configuration.Connection connection) throws DomainException {
    synchronized (getLock(connection)) {
        ConnectData connectData = connections.get(connection);
        if (connectData == null) {
            try {
                Connect connect = new Connect(connection.getUri(), false);
                connectData = new ConnectData(connect);
            } catch (LibvirtException e) {
                throw new DomainException(e);
            }
            connections.put(connection, connectData);
        }
        connectData.incrementReferenceCounter();
        return connectData.getConnect();
    }
}
 
开发者ID:fduminy,项目名称:jtestplatform,代码行数:17,代码来源:ConnectManager.java


示例16: listAllDomains

import org.libvirt.Connect; //导入依赖的package包/类
private List<Domain> listAllDomains(Connect connect) throws LibvirtException {
    List<Domain> domains = new ArrayList<Domain>();

    // get defined but inactive domains
    for (String name : connect.listDefinedDomains()) {
        if (name != null) {
            domains.add(connect.domainLookupByName(name));
        }
    }

    // get active domains
    for (int id : connect.listDomains()) {
        domains.add(connect.domainLookupByID(id));
    }

    return domains;
}
 
开发者ID:fduminy,项目名称:jtestplatform,代码行数:18,代码来源:DomainCache.java


示例17: createNetwork

import org.libvirt.Connect; //导入依赖的package包/类
private NetworkConfig createNetwork(Connection connection) throws DomainException {
    final NetworkConfig config = new NetworkConfig(NETWORK_NAME, BASE_MAC_ADDRESS, BASE_IP_ADDRESS,
                                                   MIN_SUBNET_IP_ADDRESS, MAX_SUBNET_IP_ADDRESS);
    execute(connection, new Command<Object>() {
        @Override
        public Object execute(Connect connect) throws Exception {
            Network net = networkBuilder.build(connect, config);
            net.setAutostart(true);
            if (net.isActive() == 0) {
                net.create();
            }
            return null;
        }
    });
    return config;
}
 
开发者ID:fduminy,项目名称:jtestplatform,代码行数:17,代码来源:LibVirtDomainFactory.java


示例18: startDomain

import org.libvirt.Connect; //导入依赖的package包/类
private void startDomain(Connect connect) throws DomainException, LibvirtException {
    if (!isAlive()) {
        ipAddress = null;
        if (domain != null) {
            domain.getDomain().free();
        }
        domain = domainBuilder.defineDomain(connect, config, networkConfig);
        if (!isAlive()) {
            try {
                domain.getDomain().create();
            } catch (LibvirtException e) {
                throw new DomainException(e);
            }
        }

        ipAddress = domain.getIpAddress();
    }
}
 
开发者ID:fduminy,项目名称:jtestplatform,代码行数:19,代码来源:LibVirtDomain.java


示例19: getEntry

import org.libvirt.Connect; //导入依赖的package包/类
@Nonnull
private Entry getEntry(Connect connect, DomainConfig config) throws LibvirtException, DomainException {
    boolean undefinedDomainName = ConfigUtils.isBlank(config.getDomainName());
    Entry entry;
    synchronized (getLock(connect.getHostName())) {
        if (undefinedDomainName) {
            // automatically define the domain name
            // it must be unique for the connection
            entry = domainCache.findFreeEntry(connect);
            if (entry == null) {
                throw new DomainException("No free Entry found for a new domain");
            }
        } else {
            entry = domainCache.findEntry(connect, config.getDomainName());
            if (entry == null) {
                throw new DomainException(format("No Entry found for a domain named %s", config.getDomainName()));
            }
        }
    }
    return entry;
}
 
开发者ID:fduminy,项目名称:jtestplatform,代码行数:22,代码来源:DomainBuilder.java


示例20: mockConnect

import org.libvirt.Connect; //导入依赖的package包/类
private static Connect mockConnect(boolean cpu1, boolean wordSize32bits, int memoryInKB)
    throws IOException, LibvirtException {
    StringWriter capabilitiesXML = new StringWriter();
    Capabilities capabilities = new Capabilities();
    Guest guest = new Guest();
    Arch arch = new Arch();
    arch.setWordSize(getWordSize(wordSize32bits));
    arch.setName(getCpu(cpu1));
    guest.setArch(arch);
    capabilities.addGuest(guest);
    new CapabilitiesDom4jWriter().write(capabilitiesXML, capabilities);

    Connect connect = mock(Connect.class);
    when(connect.getCapabilities()).thenReturn(capabilitiesXML.toString());
    NodeInfo nodeInfo = new NodeInfo();
    nodeInfo.memory = memoryInKB;
    when(connect.nodeInfo()).thenReturn(nodeInfo);
    return connect;
}
 
开发者ID:fduminy,项目名称:jtestplatform,代码行数:20,代码来源:PlatformSupportManagerTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ELContext类代码示例发布时间:2022-05-23
下一篇:
Java AfterEffectB类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap