-1

with vmware web service SDK and Axis 1.4, ESXi 4.1 as server i am able to do set up the java environment. i have installed the esxi 4.1 on the workstation i compiled sample program that was given in the pdf

i downloaded the pdf from the site http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/sdk40programmingguide.pdf i successfully compiled and run the sample program SimpleClient.java through the command prompt,

i want to create the some tasks and show to my professor that these tasks can act like cloud service.

these tasks are also given in the gettingstartedguide.pdf that pdf says that tasks can be done.

the pdf is avaiable with googling with the words " vmware gettingstartedguide.pdf web service SDK"

these are the tasks that has to be performed on ESXi 4.1 1.create the virtual machine. 2. power on the virtual machine. 3. power off the virtual machine. 4. suspend the virtual machine 5 . Resume the virtual machine

once if i am able to do the above tasks then i can make those tasks as web environment.

i do not know much more about the vmware. i think to perform the above tasks we need to connect the server(and that program is also avialable in the gettingstartedGuide.pdf)

i am unable to proceed further with which task is linked( like the above 5 tasks can be performed once we are able to connect the server).

i am not understanding without creating the session with esxi how we can create the virtual machine.

i am also having little confusion on how the flow works to manage the above tasks.

Please Help me.

Any Suggestion is a fruitful step to me.

Thanking You

pratap m
  • 106
  • 2
  • 11
Pratap M
  • 1,059
  • 3
  • 21
  • 31

2 Answers2

1
/*================================================================================
Copyright (c) 2008 VMware, Inc. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation 
and/or other materials provided with the distribution.

 * Neither the name of VMware, Inc. nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior 
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
================================================================================*/

package com.vmware.vim25.mo.samples.vm;

import java.net.URL;

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;

/**
 * http://vijava.sf.net
 * @author Steve Jin
 */

public class VMpowerOps 
{
  public static void main(String[] args) throws Exception 
  {
    if(args.length!=5)
    {
      System.out.println("Usage: java VMpowerOps <url> " +
            "<username> <password> <vmname> <op>");
      System.out.println("op - reboot|poweron|poweroff" +
            "|reset|standby|suspend|shutdown");
      System.exit(0);
    }

    String vmname = args[3];
    String op = 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);

    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();
  }
}
Grv
  • 29
  • 4
1

I would suggest that you use the VMWare VI Java API for performing the above mentioned tasks. It is relatively simple and easy to use. I would also suggest that you browse through the blog doublecloud.org for further information.

Syed Ali
  • 1,817
  • 2
  • 23
  • 44
  • As you mentioned, i am thinking of this will work directly for esxi4.1 and we can put the tasks to tomcat web server for web application. we do not need any https for this..that means we do not need certificates to interact with esxi.....is it correct.. – Pratap M Feb 22 '12 at 14:45
  • yes you can work without setting SSL certificates but it is not recommended for the production environment. while fetching the ServiceInstance just set the last parameter (ignoreCertificates) to true. – Syed Ali Feb 22 '12 at 15:43
  • i have to put for web application..so that i can say that cloud service is avaialable as web application.i am not looking for any innovative thing but just as a web application it has to work.is it possible.. – Pratap M Feb 22 '12 at 15:50
  • i am developing some web task of authentication by third party through single sign on..for that i need some cloud service and i am using this esxi 4.1 and the mentioned tasks as cloud service..it is a simple dump cloud. – Pratap M Feb 22 '12 at 15:53
  • yes it should - give it a try using tomcat shipped with vmware vcenter – Syed Ali Feb 22 '12 at 15:54
  • i will do this part after my single sign on works...i am very very happy now..thank you – Pratap M Feb 22 '12 at 15:55
  • what do you mean by tomcat shipped with vmware center...do you mean we should have vmware vcenter – Pratap M Feb 22 '12 at 15:58
  • sorry about that. just mixed something else. it should work. see this for an introductory tutorial http://vijava.sourceforge.net/doc/getstarted/tutorial.htm – Syed Ali Feb 22 '12 at 16:14
  • Hi..i tried HelloVM.java and it is working fine.but i also tried the CreateVM.java. but it is saying that the message it is giving the result as vm could not be created. I have installed esxi on workstation. i do not understand where it is wrong.. – Pratap M Mar 03 '12 at 07:13
  • i got it..it is working. i have to give the name of the datastorage accordingly to my enviornment. just changining that gave me the result.haha....extremely happy..... – Pratap M Mar 03 '12 at 07:35
  • i have one small request..can we enable ignorecertificates to false and do neccessary things for enabling the ssl – Pratap M May 07 '12 at 17:51
  • 1
    @PratapMurukutla "Yes", but you will need to get a valid certificate installed on the ESXi or vCenter Server. OFC the certificate will have to have a certificate chain that your java app is aware of. – Tim May 17 '12 at 19:12
  • @Tim could you please help me how to do this...this is the only thing remaining for completing my project...atleast please some link where i can get some knowledge of implemention..thank you.. – Pratap M May 31 '12 at 13:58
  • @PratapMurukutla try these links http://www.grim.se/guide/jre-cert http://stackoverflow.com/questions/3612962/access-local-machine-certificate-store-in-java – Tim May 31 '12 at 14:21
  • i have done some work on https.Here my problem is that i am connecting esxi through the steve jin library files.we will execute the program and get success with the tutorial given by steve jin..from the program itself we will use https and ignorecertificate to be true or false...he has given option of true..but i do not know about false...i have to execute the hello program with java command..i do not use any browser to connect to the server. if it is with browser i do not have any problems..but it is with vmware...that is why i am asking the possibility...any way i will see whaticando.thanq – Pratap M May 31 '12 at 15:06
  • @Tim yes i implemented with the method you mentioned.But with slight adding of the code with the existed code..thank you.. – Pratap M Jun 04 '12 at 09:58