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);
if(vm==null)
{
System.out.println("No VM " + vmname + " found");
si.getServerConnection().logout();
return;
}
if("reboot".equalsIgnoreCase(op))
{
vm.rebootGuest();
System.out.println(vmname + " guest OS rebooted");
}
else if("poweron".equalsIgnoreCase(op))
{
Task task = vm.powerOnVM_Task(null);
if(task.waitForMe()==Task.SUCCESS)
{
System.out.println(vmname + " powered on");
}
}
else if("poweroff".equalsIgnoreCase(op))
{
Task task = vm.powerOffVM_Task();
if(task.waitForMe()==Task.SUCCESS)
{
System.out.println(vmname + " powered off");
}
}
else if("reset".equalsIgnoreCase(op))
{
Task task = vm.resetVM_Task();
if(task.waitForMe()==Task.SUCCESS)
{
System.out.println(vmname + " reset");
}
}
else if("standby".equalsIgnoreCase(op))
{
vm.standbyGuest();
System.out.println(vmname + " guest OS stoodby");
}
else if("suspend".equalsIgnoreCase(op))
{
Task task = vm.suspendVM_Task();
if(task.waitForMe()==Task.SUCCESS)
{
System.out.println(vmname + " suspended");
}
}
else if("shutdown".equalsIgnoreCase(op))
{
Task task = vm.suspendVM_Task();
if(task.waitForMe()==Task.SUCCESS)
{
System.out.println(vmname + " suspended");
}
}