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


Java ServiceInstance.queryVMotionCompatibility方法代码示例

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


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

示例1: migrateVM

import com.vmware.vim25.mo.ServiceInstance; //导入方法依赖的package包/类
private static boolean migrateVM(ServiceInstance si, Folder rootFolder,
    HostSystem newHost, String targetVMName, String newHostName)
    throws Exception {

  log("Selected host [vm] for vMotion: " + newHostName + " [" + targetVMName
      + "]");
  VirtualMachine vm = (VirtualMachine)new InventoryNavigator(rootFolder)
      .searchManagedEntity("VirtualMachine", targetVMName);
  if (vm == null) {
    log(WARNING, "Could not resolve VM " + targetVMName + ", vMotion of this VM cannot be performed.");
    return false;
  }

  ComputeResource cr = (ComputeResource)newHost.getParent();

  String[] checks = new String[] { "cpu", "software" };
  HostVMotionCompatibility[] vmcs = si.queryVMotionCompatibility(vm,
      new HostSystem[] { newHost }, checks);

  String[] comps = vmcs[0].getCompatibility();
  if (checks.length != comps.length) {
    log(WARNING, "CPU/software NOT compatible, vMotion failed.");
    return false;
  }

  long start = System.currentTimeMillis();
  Task task = vm.migrateVM_Task(cr.getResourcePool(), newHost,
      VirtualMachineMovePriority.highPriority,
      VirtualMachinePowerState.poweredOn);
  if (task.waitForMe() == Task.SUCCESS) {
    long end = System.currentTimeMillis();
    log("vMotion of " + targetVMName + " to " + newHostName
        + " completed in " + (end - start) + "ms. Task result: "
        + task.getTaskInfo().getResult());
    return true;
  } else {
    TaskInfo info = task.getTaskInfo();
    log(WARNING, "vMotion of " + targetVMName + " to " + newHostName
        + " failed. Error details: " + info.getError().getFault());
    return false;
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:43,代码来源:VMotionTrigger.java

示例2: main

import com.vmware.vim25.mo.ServiceInstance; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
  if(args.length!=5)
  {
    System.out.println("Usage: java MigrateVM <url> " +
    "<username> <password> <vmname> <newhost>");
    System.exit(0);
  }

  String vmname = args[3];
  String newHostName = args[4];

  ServiceInstance si = new ServiceInstance(
      new URL(args[0]), args[1], args[2], true);

  Folder rootFolder = si.getRootFolder();
  VirtualMachine vm = (VirtualMachine) new InventoryNavigator(
      rootFolder).searchManagedEntity(
          "VirtualMachine", vmname);
  HostSystem newHost = (HostSystem) new InventoryNavigator(
      rootFolder).searchManagedEntity(
          "HostSystem", newHostName);
  ComputeResource cr = (ComputeResource) newHost.getParent();
  
  String[] checks = new String[] {"cpu", "software"};
  HostVMotionCompatibility[] vmcs =
    si.queryVMotionCompatibility(vm, new HostSystem[] 
       {newHost},checks );
  
  String[] comps = vmcs[0].getCompatibility();
  if(checks.length != comps.length)
  {
    System.out.println("CPU/software NOT compatible. Exit.");
    si.getServerConnection().logout();
    return;
  }
  
  Task task = vm.migrateVM_Task(cr.getResourcePool(), newHost,
      VirtualMachineMovePriority.highPriority, 
      VirtualMachinePowerState.poweredOn);

  if(task.waitForMe()==Task.SUCCESS)
  {
    System.out.println("VMotioned!");
  }
  else
  {
    System.out.println("VMotion failed!");
    TaskInfo info = task.getTaskInfo();
    System.out.println(info.getError().getFault());
  }
  si.getServerConnection().logout();
}
 
开发者ID:Juniper,项目名称:vijava,代码行数:54,代码来源:MigrateVM.java


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