本文整理汇总了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;
}
}
示例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();
}