Results 1 to 2 of 2

Thread: VMpowerOp

  1. #1
    pavel is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default VMpowerOp

    Hi, everyone.
    I try this source code with eclipse sdk 3.6.1 :

    import java.net.URL;
    import com.vmware.vim25.CustomFieldDef;
    import com.vmware.vim25.Permission;
    import com.vmware.vim25.mo.Folder;
    import com.vmware.vim25.mo.InventoryNavigator;
    import com.vmware.vim25.mo.ServiceInstance;
    import com.vmware.vim25.mo.Task;
    import com.vmware.vim25.mo.VirtualMachine;

    /**
    * VMware Infrastructure (vSphere) Java API
    * @author Steve Jin / Modified by Michael Hopf
    */

    public class VMpowerOps {

    public static void main(String[] args) throws Exception {

    String vmname = "Test_VM";
    /* other ops: reboot|poweron|poweroff|reset|standby|suspend|shut down */
    String op = "standby";

    ServiceInstance si = new ServiceInstance(new URL("https://server1.fireline.de/sdk"), "root", "password", 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");
    }
    }
    else
    {
    System.out.println("Invalid operation. Exiting...");
    }
    si.getServerConnection().logout();
    }
    }


    from: Access VMware ESXi server with vijava API (your own developed Java software)

    I got that I should change "waitForMe()" with "waitForTask()" ..
    But it still not working. Is there mistake in this sourse code? I don't have so much experience with programing. Is there some mistake? In this web site is written everything, but it is still making mistake.

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:

    at com.vmware.vim25.mo.samples.vm.VMpowerOps.main(VMp owerOps.java:17)

  2. #2
    pavel is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Talking

    Hallo,
    This problem can't be repair.
    In VmWare ESXi 4, VMWare Inc has apparently restricted Remote Command Line Interface (RCLI) administration of the free version of ESXi. The write permission are not possible since we need to upgrade it to full licensed one. This simple tuto is to enable the snmp via rcli

    I will search other way.
    Thank you for the attention:D

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •