VMware {code} Community
Viveeel
Contributor
Contributor
Jump to solution

unable to Use Apputil.initialize()

Hi All,

I am very new to Vsphere API, As I need to Start and Stop VM using Vsphere API, Kindly guide me with the same,

I am currently able to use Connect to VCenter using vmporttype and fetch details but still unable to use Apputil to control VM which was provided by Create.class in examples provided by VSphere API to create VM.

I am using vSphere WebService with Java.

I tried exploring their examples but some how when ever I tried to use Apputil.initilize I will get the following message

Common Java Options :

   --portnumber < type String, default 443>

      Port to connect to server

   --help < type String >

      Display usage information for the application or script

   --protocol < type String >

      Protocol for the server connection (HTTP, HTTPS)

   --username < type String >

      Required. User account with privileges to connect to the host

   --servicepath < type String >

      Service path used to connect to server

   --sessionfile < type String >

      File containing previously saved session cookie

   --ignorecert < type String >

      Ignore the server certificate validation

   --config < type String >

      Location of the VI Perl Toolkit configuration file

   --server < type String >

      Server to connect to

   --password < type String >

      Required. Password for the user account

   --url < type String >

      Required. Complete URL for the VI API Web service to connect to

Command specific options:

Caught Exception :  Name : com.vmware.apputils.ArgumentHandlingException Message : Exception running : com.vmware.apputils.ArgumentHandlingException: usage Trace

0 Kudos
1 Solution

Accepted Solutions
Steve_Jin
Expert
Expert
Jump to solution

Hi Vivek,

You are on the right track. Just remove the jars from Apache AXIS, and you will be good. All jars you need is the vijava*.jar and dom4j*.jar.

Good luck!

Steve (http://www.doublecloud.org)

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org

View solution in original post

0 Kudos
8 Replies
Viveeel
Contributor
Contributor
Jump to solution

public void vLogin(String[] n) throws Exception
    {
        System.out.println("Initialize AppUtil");
        try {
             cb = AppUtil.initialize("VExplore",n);
             cb.connect();
             System.out.println("Connection Succesful.");
             cb.disConnect();
          }
          catch(Exception e) {
             System.out.println("Connection UnSuccesful.");
             throw e;
          }
    }
    public static void main(String[] args) throws Exception
    {
        VExplore vExplore = new VExplore();
        //vExplore.test();
        //System.out.println("Session still open");
        String[] n = {url, userName, password};
        vExplore.vLogin(n);

        }

0 Kudos
Steve_Jin
Expert
Expert
Jump to solution

Check out the samples here:

http://vijava.svn.sourceforge.net/viewvc/vijava/trunk/src/com/vmware/vim25/mo/samples/vm/

There is a sample callded VmPowerOps.java among other samples.

To get started, you want to read this first in 5 minutes:

Get Started Tutorial (5 Minutes)

Other resources at http://vijava.sf.net, and http://www.doublecloud.org

Steve, author of VMware VI and vSphere SDK (Prentice Hall), creator of open source vijava API

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Viveeel
Contributor
Contributor
Jump to solution

Thanks Steve,

But I am still facing this error

https://10.201.214.78/sdk/vimService
admin
secret
Exception in thread "main" java.lang.InstantiationError: com.vmware.vim25.VimPortType
    at com.vmware.vim25.mo.ServiceInstance.<init>(ServiceInstance.java:82)
    at com.vmware.vim25.mo.ServiceInstance.<init>(ServiceInstance.java:69)
    at com.wipro.dummy.CreateVM.main(CreateVM.java:97)

Thanks

Vivek Sheel

0 Kudos
Steve_Jin
Expert
Expert
Jump to solution

Hi Vivek,

You are on the right track. Just remove the jars from Apache AXIS, and you will be good. All jars you need is the vijava*.jar and dom4j*.jar.

Good luck!

Steve (http://www.doublecloud.org)

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
0 Kudos
Viveeel
Contributor
Contributor
Jump to solution

Hey Steve,

Its been great help and I am able to use the respective API as well,

removed all the API provided by Vsphere and was able to use.

Can you guide me with how can I obtain the status of VM in Host to see if it is running or Not

The getGuest().getGuestState() doesnt return the correct values.

Thanks,

Vivek Sheel

0 Kudos
Steve_Jin
Expert
Expert
Jump to solution

Hey Vivek,

Glad to know it's helpful.Smiley Happy

For the guest related status, you need VMware Tools installed in the VM. Have you done so? It's ALWAYS recommended to have VMware Tools installed. As a good practice, have VMware Tools installed in every VM template.

Good luck!

Steve (http://www.doublecloud.org)

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Viveeel
Contributor
Contributor
Jump to solution

Hi Steve,

It resolved the most of issues I am having. I was trying in wrong way to get status  when I used with runtimeinfo it gave me what i was looking for.

Currently working with If I can provide the iso file to CdDrive. Its been good exp learning this and its much more easier than Vsphere SDK.

Thanks,

Vivek Sheel

0 Kudos
Viveeel
Contributor
Contributor
Jump to solution

Hi Steve,

Can you provide me guide for your code.

I need to create a port group for my Virtual Distributed Switch.

I am able to create the Distributed Switch but unable to create a port group for the same.

0 Kudos