Posts tagged: vCenter

Complete List of Managed Object Types in VMware vSphere API

By Steve Jin, July 19, 2010

The following tables list all the managed object types in VI 3.5, vSphere 4 and 4.1. A short description is provided for each type explaining its major responsibilities.

Note that the managed object types are added in an incremental way. The types in older versions are still supported in newer versions. The complete types in a verion include ones in the correpsonding table plus all the ones in all older version tables.

Hope this post gives you a high level overview of functionalities of the vSphere APIs. Check out other blogs such as best practices (1-5, 6-10) on how to use them in general. And don’t forget my book which introduces them extensively with many read to use samples.

Table 1 Managed Object Types in VI 3.5 Read more »

Author: Steve Jin is the author of VMware VI and vSphere SDK (Prentice Hall), creator of VMware vSphere Java API. For future articles, please subscribe to Email or RSS, and follow on Twitter.

Invalid property? A Trick With vSphere PropertyCollector

By Steve Jin, April 14, 2010

As I discussed extensively in my book, the PropertyCollector is very powerful yet not easy to use. There was a question posted at vSphere Java API forum related to the property collector which I think worths sharing here. Although it’s found using vSphere Java API, but it really goes beyond the API to the vSphere API itself.

The problem was not able to retrieve the info.vmfs property of a Datastore managed object using vSphere Java API, but OK with others like info.freeSpace, info.maxFileSize, info.name, etc. If MOB is used, the info.vmfs can be retrieved without any problem.

vSphere Java API wraps up the PropertyCollector using getter methods for all the direct properties in very managed object. Mostly you don’t need to touch the PropertyCollector at all.

In some cases, you do want to get hold of the sub properties directly to save CPU cycle and bandwidth. That is why I decided to open up the getPropertyByPath() method with which you can provide the property path and get the value in one call.

Now, what is the cause of the problem?

It’s related the typing of the property. The info property is typed as DatastoreInfo. It does NOT have a sub property called vmfs. But DatastoreInfo is an abstract type which is extended to VmfsDatastoreInfo which does have vmfs sub property. There are other possibilities, for example, DatastoreInfo to NasDatastoreInfo which does NOT have vmfs sub property at all. So before being certain about the real type, we cannot request for info.vmfs.

How to solve this issue?

It’s pretty easy. You want to get the info with getInfo() method, and check the instance type before casting it to VmfsDatastoreInfo. Once it’s casted, you can use the vmfs as easy as one getVmfs() call.

For future tricks and tips, feel free to subscribe to this feed, and follow me at Twitter.

Author: Steve Jin is the author of VMware VI and vSphere SDK (Prentice Hall), creator of VMware vSphere Java API. For future articles, please subscribe to Email or RSS, and follow on Twitter.

I18N vs. vSphere

By Steve Jin, April 8, 2010

With today’s global market, a software vendor has to consider the internationalization (I18N) issue to better serve users in different areas and maximize the return on the product investment. This article introduces the I18N basics of vSphere. Much of the content is based on my book VMware VI and vSphere SDK by Prentice Hall.

There are two basic meanings. First, you have to design your software so that it is localizable. In other words, you have to use the right APIs that can handle double byte characters. Sometimes people call this globalization (G11N).

Second, you should provide localized versions of your software so that users can read and use their native languages. Sometimes people call this localization.

In most cases, you externalize all the text strings that are visible to end users from the code to the resource files and translate them into different languages. Then localizing the software is as easy as combining the code and localized resource files. This is the way VirtualCenter server is localized. Depending on the programming language and platform, the resource files can be organized differently and might have another format. For example, Java uses properties files, yet C++ on Windows uses resource dlls.

That said, I18N is a broad topic that does much more than what is briefly covered here. Further discussion is beyond the scope of this book, but you can find more detailed information online.

As discussed, the VI SDK is essentially a set of Web Services interfaces. The WS-I18N summarizes four internationalization patterns that can be applied with Web Services when deployed. Read more »

Author: Steve Jin is the author of VMware VI and vSphere SDK (Prentice Hall), creator of VMware vSphere Java API. For future articles, please subscribe to Email or RSS, and follow on Twitter.

Introducing A Tiny Yet Powerful API to Manage and Automate vSphere

By Steve Jin, February 3, 2010

In yesterday’s blog, I talked about a little known secret of vSphere MOB – the invisible embedded XML in the HTML pages. To take advantage of the secret, I created a client side REST API which was shipped in VI Java API 2.0.

Note that I call it a Client side REST, because it is different from conventional REST API whose boundary is on the wire. With the Client side REST, the boundary is on the client side over the Java API. It implies that you cannot use a Web browser to “GET” information as would you with most conventional REST API. Anyway, the difference is not big enough for you to think twice because even if you use conventional REST API, most likely you will use a wrapper layer instead of tweaking XML data directly.

The API is very powerful and easy to use, and can do almost everything the SOAP APIs can do. There are a few developers tried it and fell in love with it, but most people don’t know much about it.

When Would You Want to Use It?

As said, the Client REST API provides similar functionality as SOAP based API. The key advantages of the API are

  • Super fast loading time compared with VI SDK. Already impressed by the VI Java API SOAP implementation, this API is about 20 times faster than that in loading time.
  • Super simple and light-weighted. Only 4 Java classes involved and zero dependency on any third party library other than J2SE.
  • XML centric so that you can easily apply XPATH, XSLT, XQuery on the data returned from the API.
  • Version Neutral. It works with 2.0, 2.5, and 4.0 without any change in your code.
  • Can be easily ported to other languages. I actually did a Python version and then handled it over to my colleagues. Consider the amount of code involved, it’s not a big project.

Once you are clear with these benefits, you can decide how it fits your projects. Before you make the final decision, please read on to the discussion part.

Architecture Overview

As you can see from the following figure, there are two layers: REST API layer and the managed object wrapper/cache layer. The later is built on top of the former. You can build your applications on either or both of these two layers.

The REST API layer talks to the vCenter/ESX(i) as a MOB client. It takes REST-like URL from the callers and makes HTTP calls to the server. When the responses come back, it converts them back to XML and returns to the caller.

The managed object wrapper/cache layer provides a bit higher level services, so you can speak in terms like managed object, properties, data object, etc. The caching is a little interesting here. It basically provides a caching around a wrapper. The cache holds the whole property XML so that you can retrieve multiple properties without going to the server twice.

The following diagram shows the object models. RestClient is the REST API layer. The RestManagedObject and CachedManagedObject are Managed Object wrapper/cache layer.

The ResultConverter is a helper class that you don’t even need to know, but it does the heavy lifting in the back. The challenge for the ResultConvert is that the responses of method calls do NOT have any XML embedded, therefore the code has to parse the HTML tables to XML. It can be tricky when you have tables embedded in tables for several layers.

 
 

As a long time software professional, I know how important the samples are to learn a new APIs. Let’s move onto the HelloWorld like sample.

A Sample Using Both API Layers

This is a sample included with the VI Java API that shows how you can use the API. It has two methods that demo the usage of the REST level API and managed object level API. I believe it is clear enough for me not to add any additional explanation. Click here to check out the full code from the code repository.

public class RestAppDemo
{
  public static void main(String[] args) throws Exception
  {
    RestClient rc = new RestClient("https://8.8.8.8", "root", "pass");
    runRestLevel(rc);
    runMOLevel(rc);
  }

  public static void runMOLevel(RestClient rc) throws Exception
  {

    RestManagedObject si = new RestManagedObject(rc, "ServiceInstance");

    System.out.println("name:" + si.getPropertyAsString("content.about.fullName"));
    System.out.println(si.invoke("currentTime"));
    System.out.println(si.invoke("retrieveContent"));

    String allXml = si.getAllProperties();
    System.out.println(allXml);
    CachedManagedObject csi = new CachedManagedObject(allXml);
    System.out.println("name:" + csi.getProperty("content.about.fullName"));
    System.out.println("root:" + csi.getProperty("content.rootFolder"));
    System.out.println("cap:" + si.getPropertyAsString("capability.multiHostSupported"));

    String em_id = si.getPropertyAsString("content.eventManager");
    RestManagedObject eventMgr = new RestManagedObject(rc, em_id);
    System.out.println("latest evt:" + eventMgr.getPropertyAsString("latest.fullFormattedMessage"));

    RestManagedObject vm = new RestManagedObject(rc, "48");
    System.out.println("reload:" + vm.invoke("reload"));
    CachedManagedObject cvm = new CachedManagedObject(vm.getAllProperties());
    System.out.println("Roles:" + cvm.getProperty("effectiveRole"));
  }

  public static void runRestLevel(RestClient rc) throws Exception
  {
    String contentXml = rc.get("moid=ServiceInstance&doPath=content");
    System.out.println(contentXml);

    XPath xpath = XPathFactory.newInstance().newXPath();
    String emMOR = xpath.evaluate("//eventManager/text()", new InputSource(new StringReader(contentXml)));
    System.out.println("view:" + emMOR);
    String lastEventXml = rc.get("moid=" + emMOR + "&doPath=latestEvent");
    xpath.reset();
    String eMessage = xpath.evaluate("//fullFormattedMessage/text()", new InputSource(new StringReader(lastEventXml)));
    System.out.println("Latest Event: " + eMessage);

    System.out.println(rc.get(null));
    System.out.println(rc.get("?moid=ServiceInstance&doPath=content%2eabout"));
    long start = System.currentTimeMillis();
    System.out.println(rc.get("?moid=48"));
    long end = System.currentTimeMillis();
    System.out.println("time taken:" + (end-start));
    Map para = new Hashtable();
    para.put("newName", "Melody_SuSe");
    System.out.println(rc.post("moid=48&method=rename", para));
    Map para1 = new Hashtable();
    System.out.println(rc.post("http://10.20.143.205/mob/?moid=48&method=acquireMksTicket", para1));
  }
}

Discussion

Although the Client REST API works perfectly fine, it’s not supported by VMware but the open source community. The underlying MOB may change over the time. Without the secret XML, the whole stuff just doesn’t work unless much more efforts there to convert the property HTML to XML.

Having said that, it’s still a good choice for you to write small applications, especially small utilities, automation scripts, XML centric applications, etc.

Are you ready to give it a try? Visit the VI Java API project home. Everything is there.

Author: Steve Jin is the author of VMware VI and vSphere SDK (Prentice Hall), creator of VMware vSphere Java API. For future articles, please subscribe to Email or RSS, and follow on Twitter.

Page 1 of 11

OfficeFolders theme by Themocracy