In vSphere Java API 2.0, I wrote a lightweight caching framework. It’s still experimental but has a great potential to greatly simplify your development work. Commercial companies already use it in their products.
The motivation behind this framework is simple – instead of keep polling the changes from the server side, you keep a local cache that is made as fresh as possible. The View in the vSphere Perl toolkit is one way to do. It caches all properties of a managed object despite the fact that you don’t need that many at all.
The caching framework in vSphere Java API takes another approach. You tells it what managed objects and what properties you want to be cached. After that, the caching framework does its best to read the properties and keep them as fresh as possible.
Architecturally the caching framework is totally separated from the core of the API. You can take it away without any impact on the rest of the API. This is quite different from other toolkit.
Have enough introduction? Let’s take a look at sample code: Read more... (489 words, estimated 1:57 mins reading time)
As a by-product, the vSphere Java API makes Jython programming a lot easier. The following is a very simple sample written in Jython to print out the name of the first virtual machine in inventory.
from java.net import *
from com.vmware.vim25.mo import *
si= ServiceInstance(URL(“https://sjin-dev1/sdk”),\
“root”, “password”, True)
rootFolder = si.getRootFolder()
vms = InventoryNavigator(rootFolder) \
.searchManagedEntities(“VirtualMachine”)
print “Hello ” + vms[0].getName()
si.getServerConnection().logout()
As you can see, it really brings in the benefit of VI Java API into Python community at almost no extra cost. Read more... (118 words, estimated 28 secs reading time)
In my previous blogs, I have introduced the vSphere API object model, vSphere Java API architecture. I assume you’ve run through the 5 minute Getting Started Tutorials with HelloWorld sample.
Now, let’s take a look on how to use the API in general.
1. Always starts with a ServiceInstance with URL/username/password, or URL/sessionID. For example,
ServiceInstance si = new ServiceInstance(new URL(urlStr), username, password, true);
2. From the ServiceInstance object, you can: Read more... (371 words, estimated 1:29 mins reading time)
In my previous blog, I talked about the object model of the vSphere API. Many people like the UML diagram that illustrates how the managed objects are inherited from each other.
Following that blog, I will introduce the object model of the open source Java API that is built on top of the Web Services, as well as some key design decisions I made while designing the API.
The following UML diagram is extracted from the overall model but adds much more details with properties and methods. If you can understand this diagram, you can then easily understand all other managed object types. Read more... (568 words, 2 images, estimated 2:16 mins reading time)
I mentioned the vSphere API self paced lab at PEX in my previous blog. Not all the people who are interested in learning the API made it to PEX last month. A reader asked me when it can be online in his comment.
Here is the VI Java API part in the tutorial. We had the environment set up all together for you in the PEX lab including the Eclipse and all the related jar files. So it’s very easy to get started there. Without going to PEX, you need to do something extra by yourself. But that is not too hard at all. I promise it won’t take you much time at all. To get the basic one done, you probably need 5 to 30 minutes depending on your familiarity with Java.
Ready to learn? Read more... (1261 words, 1 image, estimated 5:03 mins reading time)
If you have trouble to understand vSphere API when you first use it, you are definitely not alone. I had the same trouble when I first used it a while back.
Some of the troubles come from the disconnect between conventional programming model and that of vSphere API. In this blog, I summarize the top 5 myths about vSphere API based on my experience and the questions I see in the VMware community forum and vSphere Java API forum:
- Non-existing Managed Objects
- Pervasive PropertyCollector
- Short-Lived Task Object
- “Weak” HostSystem
- “Un-documented” View
Let’s examine each of them one by one. Read more... (734 words, 1 image, estimated 2:56 mins reading time)
When I start to use a new API/SDK, I always look for the object model diagram before digging into the API Reference. With that, I can have a good overview of the API, from the concepts to the structure. This can save a lot of time.
Unfortunately, we don’t find such a object model diagram in any official document. The following is the UML diagram from my book VMware VI and vSphere SDK. Read more... (340 words, 2 images, estimated 1:22 mins reading time)
Last summer, Reflex VP engineering Aaron Bawcom visited VMware campus. He is one of the authors of Virtualization For Security: Including Sandboxing, Disaster Recovery, High Availability, Forensic Analysis, And Honeypotting.
During our talk, Aaron told me a secret project called VQL. Because it’s a secret, I didn’t talk about it to anyone. Just before the PEX 2010, we exchanged emails about the VQL. Aaron told me it’s already shipped. So it’s time to broadcast it.
VQL is a DSL that looks like SQL, easy to understand and easy to use. Unlike SQL on data, it’s on virtual resources in vSphere environment. The following is a quick sample. It gets back the VMs installed with SQL servers with verions newer than 9.2 and they are running 10 minutes ago.
SQL Server and VersionMajor >= 9 and VersionMinor >= 2 project vm at 10 minutes ago Read more... (339 words, 1 image, estimated 1:21 mins reading time)
Several folks asked me about how to use vSphere(VI) Java API to connect to a VM running on vSphere. The quick answer is vSphere Java API is not designed for this. You will need VMware Remote Console, browser plug-in, remote desktop/VNC, SSH client etc. However, it can help you to get the information required by the console or plug-in. Tal Altman from CISCO suggested that it be a topic for doublecloud.org. Here it is.
There are 3 ways to connect to the VM from your client side outside the vSphere and Web Access which have built-in support for console access.
- Using VMware Remote Console which is a standalone application
- Using browser plug-in to either IE or Firefox (Note: this is NOT supported by VMware. Please don’t call the company tech support for this.)
- Using Remote Desktop, VNC or SSH
The first two connect to the ESX host, and work even there is no guest OS installed on the VM. The last one assumes you have guest OS installed, and have IP network and server components in place already.
Note that these 3 ways work for the VMs in the public cloud as well if the related ports are open in your firewall. It is, however, not the case for most enterprises, therefore I particularly say it’s for VMs in private cloud. If you don’t have firewall issue, feel free to give it a try with public cloud as well.
Let’s go over one by one in details and see how vSphere Java API helps. Read more... (1112 words, 2 images, estimated 4:27 mins reading time)
While browsing the project home of VI Java API, I found a link to a great tool contributed by pitchcat. It is a standalone Java application that shows managed objects and data objects in a tree hierarchy, and all the methods attached to a managed object.
I highly recommend it to all the VI Java API developers. Why? Although you can get similar information from MOB, vijava browser gives you an overview of all the managed objects and clear paths to any managed objects or data objects. Read more... (129 words, 2 images, estimated 31 secs reading time)
Recent Comments