本文整理汇总了Java中org.libvirt.Domain类的典型用法代码示例。如果您正苦于以下问题:Java Domain类的具体用法?Java Domain怎么用?Java Domain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Domain类属于org.libvirt包,在下文中一共展示了Domain类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getFreeMemory
import org.libvirt.Domain; //导入依赖的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
示例2: vifHotPlug
import org.libvirt.Domain; //导入依赖的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
示例3: getVmState
import org.libvirt.Domain; //导入依赖的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
示例4: restoreVMSnapshotMetadata
import org.libvirt.Domain; //导入依赖的package包/类
public void restoreVMSnapshotMetadata(final Domain dm, final String vmName, final List<Ternary<String, Boolean, String>> vmsnapshots) {
logger.debug("Restoring the metadata of vm snapshots of vm " + vmName);
for (final Ternary<String, Boolean, String> vmsnapshot : vmsnapshots) {
final String snapshotName = vmsnapshot.first();
final Boolean isCurrent = vmsnapshot.second();
final String snapshotXML = vmsnapshot.third();
logger.debug("Restoring vm snapshot " + snapshotName + " on " + vmName + " with XML:\n " + snapshotXML);
try {
int flags = 1; // VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE = 1
if (isCurrent) {
flags += 2; // VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT = 2
}
dm.snapshotCreateXML(snapshotXML, flags);
} catch (final LibvirtException e) {
logger.debug("Failed to restore vm snapshot " + snapshotName + ", continue");
}
}
}
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:19,代码来源:LibvirtComputingResource.java
示例5: 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
示例6: listAllDomains
import org.libvirt.Domain; //导入依赖的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
示例7: findFreeDomainId
import org.libvirt.Domain; //导入依赖的package包/类
@Nullable
private Integer findFreeDomainId(List<Domain> domains) throws LibvirtException {
Set<Integer> domainIds = new HashSet<Integer>(domains.size());
for (Domain domain : domains) {
if (domain.getName().startsWith(DOMAIN_NAME_PREFIX)) {
domainIds.add(Integer.parseInt(domain.getName().substring(DOMAIN_NAME_PREFIX.length())));
}
}
Integer domainId = null;
for (int id = networkConfig.getMinSubNetIpAddress(); id <= networkConfig.getMaxSubNetIpAddress(); id++) {
if (!domainIds.contains(id)) {
domainId = id;
break;
}
}
return domainId;
}
开发者ID:fduminy,项目名称:jtestplatform,代码行数:19,代码来源:DomainCache.java
示例8: 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
示例9: call
import org.libvirt.Domain; //导入依赖的package包/类
@Override
public Domain call() throws LibvirtException {
long flags = 1 << 0;
// set compression flag for migration, if libvirt version supports it
if (dconn.getLibVirVersion() >= 1000003) {
flags |= 1 << 11;
}
if (migrateStorage) {
flags |= 1 << 6;
}
if (autoConvergence && dconn.getLibVirVersion() >= 1002003) {
flags |= 1 << 13;
}
return dm.migrate(dconn, flags, dxml, vmName, "tcp:" + destIp, libvirtComputingResource.getMigrateSpeed());
}
开发者ID:apache,项目名称:cloudstack,代码行数:20,代码来源:MigrateKVMAsync.java
示例10: getFreeMemory
import org.libvirt.Domain; //导入依赖的package包/类
private Long getFreeMemory(final Connect conn, final LibvirtComputingResource libvirtComputingResource){
try {
long allocatedMem = 0;
int[] ids = conn.listDomains();
for(int id :ids) {
Domain dm = conn.domainLookupByID(id);
allocatedMem += dm.getMaxMemory() * 1024L;
s_logger.debug("vm: " + dm.getName() + " mem: " + dm.getMaxMemory() * 1024L);
}
Long remainingMem = libvirtComputingResource.getTotalMemory() - allocatedMem;
s_logger.debug("remaining mem" + remainingMem);
return remainingMem;
} catch (Exception e) {
s_logger.debug("failed to get free memory", e);
return null;
}
}
开发者ID:apache,项目名称:cloudstack,代码行数:18,代码来源:LibvirtStartCommandWrapper.java
示例11: vifHotUnPlug
import org.libvirt.Domain; //导入依赖的package包/类
private void vifHotUnPlug (final Connect conn, final String vmName, final String macAddr) throws InternalErrorException, LibvirtException {
Domain vm = null;
vm = getDomain(conn, vmName);
final List<InterfaceDef> pluggedNics = getInterfaces(conn, vmName);
for (final InterfaceDef pluggedNic : pluggedNics) {
if (pluggedNic.getMacAddress().equalsIgnoreCase(macAddr)) {
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 : getAllVifDrivers()) {
vifDriver.unplug(pluggedNic);
}
}
}
}
开发者ID:apache,项目名称:cloudstack,代码行数:17,代码来源:LibvirtComputingResource.java
示例12: getVmState
import org.libvirt.Domain; //导入依赖的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) {
s_logger.warn("Can't get vm state " + vmName + e.getMessage() + "retry:" + retry);
} finally {
try {
if (vms != null) {
vms.free();
}
} catch (final LibvirtException l) {
s_logger.trace("Ignoring libvirt error.", l);
}
}
}
return PowerState.PowerOff;
}
开发者ID:apache,项目名称:cloudstack,代码行数:23,代码来源:LibvirtComputingResource.java
示例13: 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
示例14: getVmNetworkStat
import org.libvirt.Domain; //导入依赖的package包/类
public List<VmNetworkStatsEntry> getVmNetworkStat(Connect conn, String vmName) throws LibvirtException {
Domain dm = null;
try {
dm = getDomain(conn, vmName);
List<VmNetworkStatsEntry> stats = new ArrayList<VmNetworkStatsEntry>();
List<InterfaceDef> nics = getInterfaces(conn, vmName);
for (InterfaceDef nic : nics) {
DomainInterfaceStats nicStats = dm.interfaceStats(nic.getDevName());
String macAddress = nic.getMacAddress();
VmNetworkStatsEntry stat = new VmNetworkStatsEntry(vmName, macAddress, nicStats.tx_bytes, nicStats.rx_bytes);
stats.add(stat);
}
return stats;
} finally {
if (dm != null) {
dm.free();
}
}
}
开发者ID:apache,项目名称:cloudstack,代码行数:24,代码来源:LibvirtComputingResource.java
示例15: restoreVMSnapshotMetadata
import org.libvirt.Domain; //导入依赖的package包/类
public void restoreVMSnapshotMetadata(Domain dm, String vmName, List<Ternary<String, Boolean, String>> vmsnapshots) {
s_logger.debug("Restoring the metadata of vm snapshots of vm " + vmName);
for (Ternary<String, Boolean, String> vmsnapshot: vmsnapshots) {
String snapshotName = vmsnapshot.first();
Boolean isCurrent = vmsnapshot.second();
String snapshotXML = vmsnapshot.third();
s_logger.debug("Restoring vm snapshot " + snapshotName + " on " + vmName + " with XML:\n " + snapshotXML);
try {
int flags = 1; // VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE = 1
if (isCurrent) {
flags += 2; // VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT = 2
}
dm.snapshotCreateXML(snapshotXML, flags);
} catch (LibvirtException e) {
s_logger.debug("Failed to restore vm snapshot " + snapshotName + ", continue");
continue;
}
}
}
开发者ID:apache,项目名称:cloudstack,代码行数:20,代码来源:LibvirtComputingResource.java
示例16: testRebootInstance
import org.libvirt.Domain; //导入依赖的package包/类
@Test
public void testRebootInstance() throws Exception {
setupImmutableResourceManagerToMimicExistingNetworkForVlanId(instanceId, instance);
setupDeviceUtilsToMimicNetworkForRunningInstance();
Domain mockDomain = stubLibvirtConnection.startDomain("<name>" + instanceId + "</name>");
ReceivedMessageContext rebootMessageContext = setupMessageContextForInstanceReboot();
// act
instanceManagerApplication.deliver(instancePastryId, rebootMessageContext);
Thread.sleep(3000);
// assert
verify(mockDomain).reboot(eq(0));
}
开发者ID:barnyard,项目名称:pi,代码行数:17,代码来源:RingInstanceManagerIntegrationTest.java
示例17: 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
示例18: calculateFreeMemory
import org.libvirt.Domain; //导入依赖的package包/类
private long calculateFreeMemory() throws IOException {
NodeInfo nodeInfo = libvirtManager.getNodeInfo();
long nodeMemoryInMB = nodeInfo.memory / ONE_THOUSAND_TWENTY_FOUR;
xenConfigurationParser.init(this.xenConfigPath);
long xenMinMemoryInMB = xenConfigurationParser.getLongValue("dom0-min-mem");
LOG.debug(String.format("Available Node memory (from libvirt): %dMB, Memory reserved for dom0 in xen config: %dMB, Memory reserved for Xen in p2p-app-config: %dMB", nodeMemoryInMB, configReservedMem, xenMinMemoryInMB));
long usedMemory = 0;
Collection<Domain> allRunInstances = libvirtManager.getAllInstances();
for (Domain domain : allRunInstances) {
try {
if (StringUtils.isBlank(domain.getName()) || !domain.getName().toLowerCase(Locale.UK).contains("domain"))
usedMemory += domain.getMaxMemory() / ONE_THOUSAND_TWENTY_FOUR;
} catch (LibvirtException e) {
LOG.warn(String.format(UNABLE_TO_GET_NODE_INFORMATION_FOR_INSTANCE_IN_XEN_WITH_ID_S, domain), e);
}
}
// deduct 64M as an extra buffer for xen
long freeMemoryInMB = nodeMemoryInMB - usedMemory - xenMinMemoryInMB - configReservedMem - SIXTY_FOUR;
LOG.debug(String.format("Free memory available in xen: %d", freeMemoryInMB));
return freeMemoryInMB;
}
开发者ID:barnyard,项目名称:pi,代码行数:27,代码来源:SystemResourceState.java
示例19: shouldReturnListOfCrashedInstances
import org.libvirt.Domain; //导入依赖的package包/类
@Test
public void shouldReturnListOfCrashedInstances() throws Exception {
// setup
final Domain[] domains = new Domain[] { createMockDomain(1, DomainState.VIR_DOMAIN_RUNNING), createMockDomain(2, DomainState.VIR_DOMAIN_NOSTATE), createMockDomain(3, DomainState.VIR_DOMAIN_PAUSED),
createMockDomain(4, DomainState.VIR_DOMAIN_BLOCKED), createMockDomain(5, DomainState.VIR_DOMAIN_CRASHED), createMockDomain(6, DomainState.VIR_DOMAIN_SHUTDOWN), createMockDomain(7, DomainState.VIR_DOMAIN_SHUTOFF),
createMockDomain(8, DomainState.VIR_DOMAIN_CRASHED) };
when(mockConnection.listDomains()).thenReturn(new int[] { 1, 2, 3, 4, 5, 6, 7, 8 });
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
int i = (Integer) invocation.getArguments()[0];
return domains[i - 1];
}
}).when(mockConnection).domainLookupByID(isA(Integer.class));
// act
Collection<String> result = this.libvirtManager.getAllCrashedInstances();
// assert
assertEquals(2, result.size());
assertTrue(result.contains("i-5"));
assertTrue(result.contains("i-8"));
}
开发者ID:barnyard,项目名称:pi,代码行数:26,代码来源:LibvirtManagerTest.java
示例20: newLibVirtDomain
import org.libvirt.Domain; //导入依赖的package包/类
LibVirtDomain newLibVirtDomain(Domain domain)
{
return new LibVirtDomain(this, domain)
{
private int cleanUpId;
@Override
protected void addDomainToCleanUp()
{
this.cleanUpId = LibVirtAdapter.this.addObjectToCleanUp(this.domain, this.cleanup);
}
@Override
protected void removeDomainFromCleanUp()
{
LibVirtAdapter.this.removeObjectFromCleanUp(this.cleanUpId);
}
};
}
开发者ID:intrbiz,项目名称:virt,代码行数:21,代码来源:LibVirtAdapter.java
注:本文中的org.libvirt.Domain类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论