The vSphere SDK is a set of libraries that support vSphere API, as well as tools and samples that assist your development efforts. The vSphere SDK is also known as VI SDK, vCenter SDK, ESX SDK, etc.
Both system administrators and software developers would be interested in vSphere automation and integration. VMware customers can use it to automate vSphere; partners can use it to integrate with vSphere platform.
Where Should I Get Started?
Before getting started with vSphere API, you should learn the vSphere product first. It should give you basic concepts regarding virtual machine, host, networking, storage, etc. The vSphere API is just a “view” into the vSphere product. Also very helpful is the Managed Object Browser(MOB) which allows you to explore the inventory and see the managed object internals. Optionally, you can use VIJava Browser.
Once you have a good understanding of vSphere, you should check out the object model of vSphere API. The UML diagram gives you a high level overview on managed objects available in the API. For a complete listing of all the object types, you can check out here and also the API reference.
After that, you have several choices on the language bindings. If you use Java, you want to read this tutorial which helps you to run your first HelloWorld like application in 5 minutes. For others, check out the language binding section.
Where can I download vSphere SDK?
Check out the Web Service SDK at developer community download center.
Note: if you are using the open source VI Java API, go to the http://vijava.sf.net.
Where can I find documentations?
All the official documentation of vSphere SDK is here. You can also buy VMware VI and vSphere SDKfrom Amazon.
Where can I get help?
You can post your questions to the VMware management API forum. For VI Java API related questions, post them to the VI Java API forum.
What language should I use for vSphere API?
The vSphere API is based on SOAP Web Services. As a result, you can use any programming language that supports SOAP. For out of box support, see next question.
What language bindings are available for vSphere API?
Java: http://vijava.sf.net
.Net: http://sourceforge.net/projects/vitfordotnet/
Ruby: https://github.com/rlane/rbvmomi
Perl: http://www.vmware.com/support/developer/viperltoolkit/
PowerShell: http://www.vmware.com/support/developer/PowerCLI/
You can use VI Java API with JVM based languages like JRuby (Ruby), Jython (Python), Scala, etc. Check out the vSphere Java API section.Currently there is no PHP support for vSphere API.
vSPHERE JAVA API
What is VI Java API?
Virtual Infrastructure API is an open source project created by Steve Jin from VMware R&D. It aims to simplify the use of VI SDK and improve the performance. This API is also known as vSphere Java API because of the name change of VI to vSphere.
How is this API different from VI SDK?
This API is built on top of the web services interfaces defined in WSDL included in VI SDK. To use this API 1.0, you have to get VI SDK installed and configured first. For more information on how to install VI SDK, please refer Developer’s Setup Guide.
Since version 2.0, you don’t need any installation and configuration of VI SDK. All you need is two jar files of this API and dom4j, which are all included in the binary download.
What does this API mean to me?
If you are using Java to develop applications talking to VMware Infrastructure (vSphere), this API is for you. Using this API instead of the VI SDK web services interfaces results in significantly less line of code, much faster, and much more readable code.
Here are two samples with the same functionality written with VI SDK (part of 100 lines) and with VI Java API (all 28 lines). You can tell the difference by yourself.
Also, take a look at the testimonials from the community.
What is released?
The binary, source code, and over 50 samples showing how to use the API. There are two different bundles: one with binary only for runtime; the other with all source and samples.
Where should I get started?
First, please check out the Get Started Tutorial. Optionally, read these two short documents: Get started with VI Java API (2 pages), and Object model of VI Java API (3 pages) listed at VI Java API documentation Links to PDF files are included in the documents.
Secondly, go to the download page and download the latest release. Once the downloaded jar file is included in your existing VI SDK project’s classpath, you can start to program your first HelloVM program. Note: With 2.0 and beyond, you don’t need any jar files from VI SDK.
Where can I find Javadoc of the API?
There is unfortunately no Javadoc coming with API. One reason for this is that the API has faithfully followed the object model of vSphere API, and as a result the vSphere API reference can be used. The key differences are: for the every property of managed object, VI Java API has an equivalent getter method; for the every method in vSphere API reference, forget about the first _this parameter and use real types instead of ManagedObjectReference.
Where can I find the sample code and API source code?
Click here for Sample code. Note: before you run the samples, make sure you change the URL/username/password, and possible other parameters in the samples.
For API source code, check here.
How can I get an managed object if I have its ID, for example task-id?
Read this article.
How to find a folder for virtual machine or hosts?
The folder itself is a type which can hold datacenters, virtual machines, hosts, etc. It’s determined by its property “childType.” Check this post for in-depth discussion
How to set up proxy with the VI Java API?
It’s no different for other Java applications. Check out details here.
Can I set up connection timeout in VI Java?
Yes, check here.
How can I ignore the SSL certificate? Should I?
It really depends. If you want to ignore the certificate, you can simple provide a “true” value to the ServiceInstance constractor as follows:
ServiceInstance si = new ServiceInstance(new URL(urlStr), username, password, true);
Even you ignore the certificate, the traffics between are still encrypted. But the client won’t authenticate if the server is what it claims to be. I recommend you to ignore the certificate in development time, just for convenience.
If you put false, you have to import the server SSL key into Java keystore and provide the path to the keystore when you run the application.
VI JAVA Browser
You can optionally use the VI Java Browser.
Can I export and import OVF with vSphere API?
Yes. More are here and here.
How can I delete a virtual machine?
Check out here.
Can I create my own Task and Event using vSphere API?
Yes. Check here.
How to get Event type?
Check here.
Why isn’t there event type for network port group?
Not everything happened with vSphere has a corresponding event. This post discusses this is in great details.
Is there an easy to keep update with property changes?
Yes. Check out the caching framework in VI Java API.
Troubleshooting
Why can’t I use the API with ESXi via API?
It’s possible that you are using free version of ESXi which doesn’t fully support the API. Check this post, and upgrade your license.
What are the common faults?
Check out here.
What Should I do if I got an exception?
First of all, you need to isolate the exception to see if it’s from vSphere API or a normal programming exception. One simple way is check the full name of the exception. The vSphere API exception normally have package name like com.vmware.vim25.
When it’s a vSphere API exception, check the API reference to see what’s the nature of the exception and what could possibly cause it. With that in mind, check your API parameters and the managed object conditions like power status of a virtual machine. See other FAQs below. You also use server logs and Onyx to help.
Why return com.vmware.vim25.NotSupported when calling cloneVM?
Some method for example cloneVM_Task() is only supported on vCenter. When you call ESX or ESXi, you may get this NotSupported exception. So, switch to vCenter server instead. It’s also possible that you got this with vCenter in some rare cases. The solution is to switch to ESX or ESXi.
Why did I get javax.net.ssl.SSLHandshakeException?
It’s possible that you haven’t correctly set up the certificate with your Java keystore. If you are in development phase, you can temporarily bypass this by ignore the certificate as described in a previous FAQ.
What can I do if I got com.vmware.vim25.InvalidRequest exception?
The InvalidRequest means your parameter to vSphere API is not expected by the server: either missing some required parameters, or giving inappropriate values. It’s mostly hard to find out which parameters. You want to check out the sample code and compare them with yours. If there is no clue, you want to use Oynx to record vSphere Client and compare that of your application.
Why did I get com.vmware.vim25.InvalidProperty exception?
It’s most likely you’ve specified a wrong property name or a wrong property path while using the PropertyCollector managed object. The VI Java API has provider getter methods for all direct properties of all managed objects. You will much less like to get this InvalidProperty exception using VI Java API. Even so it’s still possible to get this exception. Check out this article for in-depth discussion.
Why did I get com.vmware.vim25.TaskInProgress?
The TaskInProgress exception is caused by multiple calls at the same time. If you can limit one call on one VM at a time, the issue may go away. Check the chapter 18 of my book (http://amzn.to/97ZyAg) on multithreading issues in details.
Why I got java.lang.InstantiationError while running VI Java API?
Most likely you use VI Java 2.0 and newer, but still have jar files of Apache AXIS in your classpath. Remove all of them, and you should be able to run.
Why does it fail with some username/password?
You need to escape the special characters like <, >, ‘, “, & in a string passed into the API because VI Java does not escape them for you in 2.0 and 2.1 and thus fails the XML parser on the server side. We may change this in the future.
How to turn on logs of vCenter and ESX?
For ESX, check this article. For vCenter, check out LucD’s blog.
My server application works fine in lab but doesn’t scale in production. Any thought?
It’s possible with session management. Check out this article for tips.
What tools to troubleshoot an application built on vSphere API?
First of all, your application can be debugged as any other applications. You should get familiar with the debuggers of your language and IDE.
Besides the debuggers, you want to look at Onyx. This is essentially a proxy which can intercept the traffics between your application and vCenter/ESX. You can analyze the XML messages and compare them with those recorded between vSphere Client and vCenter/ESX.
If you want to monitor every possible IP packet, you can take a look at WireShark. It may take a little effort to set up the SSL certificate for decrypting the messages, and set up the filters for interested packets.
You can also switch HTTPS to HTTP and use tools like TcpMon to log the HTTP traffic. Because HTTP is not enabled by default, I wouldn’t recommend it when Oynx can serve your need.
Reference :
http://www.doublecloud.org/vmware-vsphere-api-and-sdk-faq/
Thanks To ALL !!!!
No comments:
Post a Comment