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


Java Domain.getXMLDesc方法代码示例

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


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

示例1: getVncPort

import org.libvirt.Domain; //导入方法依赖的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

示例2: getMacAddress

import org.libvirt.Domain; //导入方法依赖的package包/类
private static String getMacAddress(Domain domain) throws LibvirtException {
    String macAddress = null;

    String xml = domain.getXMLDesc(0);

    //TODO it's bad, we should use an xml parser. create and add it in the libvirt-model project.
    String begin = "<mac address='";
    int idx = xml.indexOf(begin);
    if (idx >= 0) {
        idx += begin.length();
        int idx2 = xml.indexOf('\'', idx);
        if (idx2 >= 0) {
            macAddress = xml.substring(idx, idx2);
        }
    }

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

示例3: getVncPort

import org.libvirt.Domain; //导入方法依赖的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) {
            s_logger.trace("Ignoring libvirt error.", l);
        }
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:19,代码来源:LibvirtComputingResource.java

示例4: volumeExists

import org.libvirt.Domain; //导入方法依赖的package包/类
public boolean volumeExists(String instanceId, String devicePath) {
    LOG.debug(String.format("volumeExists(%s, %s)", instanceId, devicePath));
    try {
        Domain domain = this.connection.domainLookupByName(instanceId);
        if (null == domain)
            throw new LibvirtManagerException(UNABLE_TO_GET_DOMAIN + instanceId);
        String domainXml = domain.getXMLDesc(FLAG_NOT_USED);
        if (domainXml.contains(devicePath)) {
            LOG.warn(String.format("Device %s still attached to Instance %s. Domain Xml: %s", devicePath, instanceId, domainXml));
            return true;
        }
    } catch (LibvirtException e) {
        processLibvirtException(e, UNABLE_TO_GET_DOMAIN + instanceId);
    }

    return false;
}
 
开发者ID:barnyard,项目名称:pi,代码行数:18,代码来源:LibvirtManager.java

示例5: detachDevice

import org.libvirt.Domain; //导入方法依赖的package包/类
@Override
public void detachDevice(String domainName, String deviceXml) throws LibvirtException {
    addCommand(String.format("detachDevice(%s, %s)", domainName, deviceXml));
    Domain domain = domainLookupByName(domainName);
    if (null != domain) {
        String xml = domain.getXMLDesc(1);
        System.err.println("##### " + xml);
        int start = xml.lastIndexOf("<disk");
        int end = xml.lastIndexOf("</disk>") + "</disk>".length();
        if (start > -1 && end > -1) {
            String newXml = xml.substring(0, start) + xml.substring(end);
            System.err.println("###### " + newXml);
            when(domain.getXMLDesc(anyInt())).thenReturn(newXml);
        }
    } else
        throw new DomainNotFoundException();
}
 
开发者ID:barnyard,项目名称:pi,代码行数:18,代码来源:StubLibvirtConnection.java

示例6: assertThatTheRightLibvirtApiIsInvokedForRunInstance

import org.libvirt.Domain; //导入方法依赖的package包/类
protected void assertThatTheRightLibvirtApiIsInvokedForRunInstance() throws Exception {
    int[] domains = stubLibvirtConnection.listDomains();
    assertEquals(1, domains.length);

    Domain domain = stubLibvirtConnection.domainLookupByID(domains[0]);
    assertEquals(domain.getName(), instanceId);

    String domainXml = domain.getXMLDesc(0);
    assertThatDomainXmlContainsNecessaryFields(domainXml);
}
 
开发者ID:barnyard,项目名称:pi,代码行数:11,代码来源:InstanceManagerApplicationIntegrationTestBase.java

示例7: getDomainXml

import org.libvirt.Domain; //导入方法依赖的package包/类
@Override
public String getDomainXml(String domainName) throws LibvirtException {
    LOG.debug(String.format("getDomainXml(%s)", domainName));
    Domain domain = this.domainLookupByName(domainName);
    if (null == domain) {
        throw new DomainNotFoundException();
    }
    return domain.getXMLDesc(0);
}
 
开发者ID:barnyard,项目名称:pi,代码行数:10,代码来源:LibvirtConnection.java

示例8: attachDevice

import org.libvirt.Domain; //导入方法依赖的package包/类
@Override
public void attachDevice(String domainName, String deviceXml) throws LibvirtException {
    addCommand(String.format("attachDevice(%s, %s)", domainName, deviceXml));
    Domain domain = domainLookupByName(domainName);
    if (null != domain) {
        String xml = domain.getXMLDesc(1);
        System.err.println("##### " + xml);
        String newXml = xml + deviceXml;
        System.err.println("###### " + newXml);
        when(domain.getXMLDesc(anyInt())).thenReturn(newXml);
    }
}
 
开发者ID:barnyard,项目名称:pi,代码行数:13,代码来源:StubLibvirtConnection.java

示例9: execute

import org.libvirt.Domain; //导入方法依赖的package包/类
@Override
public Answer execute(final MigrateWithStorageAcrossClustersCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final VirtualMachineTO vm = command.getVirtualMachine();

    try {
        final LibvirtUtilitiesHelper utilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
        final Connect sourceConnection = utilitiesHelper.getConnectionByVmName(vm.getName());
        final Connect destinationConnection = utilitiesHelper.retrieveQemuConnection("qemu+tcp://" + command.getDestinationIpAddress() + "/system");

        final Domain domain = sourceConnection.domainLookupByName(vm.getName());

        // VIR_DOMAIN_XML_MIGRATABLE = 8
        String domainXml = domain.getXMLDesc(8);

        final XPath xPath = XPathFactory.newInstance().newXPath();
        final XPathExpression expression = xPath.compile("/pool/target/path");

        final List<VolumeObjectTO> volumes = new ArrayList<>();
        for (final Pair<VolumeTO, StorageFilerTO> entry : command.getVolumeMapping()) {
            final VolumeTO volumeTO = entry.first();
            final StorageFilerTO storageFilerTO = entry.second();

            final StoragePool sourcePool = sourceConnection.storagePoolLookupByName(volumeTO.getPoolUuid());
            final String sourcePoolXml = sourcePool.getXMLDesc(0);

            final StoragePool destinationPool = destinationConnection.storagePoolLookupByName(storageFilerTO.getUuid());
            final String destinationPoolXml = destinationPool.getXMLDesc(0);

            final String sourcePath = expression.evaluate(new InputSource(new StringReader(sourcePoolXml)));
            final String sourceLocation = sourcePath + "/" + volumeTO.getPath();

            final String destinationPath = expression.evaluate(new InputSource(new StringReader(destinationPoolXml)));
            final String destinationLocation = destinationPath + "/" + volumeTO.getPath();

            domainXml = domainXml.replace(sourceLocation, destinationLocation);

            final VolumeObjectTO volumeObjectTO = new VolumeObjectTO();
            volumeObjectTO.setId(volumeTO.getId());
            volumeObjectTO.setPath(volumeTO.getPath());
            volumes.add(volumeObjectTO);
        }

        // VIR_MIGRATE_LIVE = 1
        // VIR_MIGRATE_UNDEFINE_SOURCE = 16
        // VIR_MIGRATE_NON_SHARED_DISK = 64
        domain.migrate(destinationConnection, 1 | 16 | 64, domainXml, vm.getName(), null, 0);

        return new MigrateWithStorageAcrossClustersAnswer(command, volumes);
    } catch (final Exception e) {
        s_logger.error("Migration of vm " + vm.getName() + " with storage failed due to " + e.toString(), e);
        return new MigrateWithStorageAcrossClustersAnswer(command, e);
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:54,代码来源:LibvirtMigrateWithStorageAcrossClustersCommandWrapper.java

示例10: getDomainXml

import org.libvirt.Domain; //导入方法依赖的package包/类
@Override
public String getDomainXml(String domainName) throws LibvirtException {
    System.err.println(String.format("%s getDomainXml(%s)", new Date(), domainName));
    Domain domain = this.domainLookupByName(domainName);
    return domain.getXMLDesc(0);
}
 
开发者ID:barnyard,项目名称:pi,代码行数:7,代码来源:StubLibvirtConnection.java


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