Archive

Archive for the ‘Virtualization’ Category

Creating Your Own Task and Event in vSphere

September 9th, 2010 33 comments

vSphere has a powerful extension mechanism that allows you to add new features as integral part of the platform. Many vendors have already leveraged this by providing plug-ins so that users can manage their components seamlessly within same vSphere Client.

You can actually do more than that with the extension. The following sample shows how to create your own task and event with vSphere API. The code should be self explanatory therefore I don’t elaborate much here. Note that you must run the sample with a vCenter server as extensibility is implemented only in vCenter.

When running the code, you can see a new task created and progresses with 10% every second in the “Recent Tasks” pane of vSphere Client. When the task is done, you will also see a new event posted in the “Tasks & Events” tab of the host you associate the task with.

What can you do with this capability? Here are two typical use cases:

Really Easy Ways to Capture VM Screenshot

September 8th, 2010 7 comments

Since vSphere 2.5, there is a feature allowing you to capture screen shot of a running virtual machine. It’s not well publicized but you can find a short description with screenshotSupported (boolean) in the HostCapability data object. Thanks to Nikita for bringing this up in the comment of the vSphere Java API 2.1 GA post.

Indicates whether the screenshot retrival over https is supported for this host’s virtual machines. If true, a screenshot can be retrieved at the HTTPS relative path /screen?id=<managed object ID of virtual machine or snapshot>. If any of the optional parameters ‘top’, ‘left’, ‘bottom’, and ‘right’ is specified, the returned image will be cropped from the rectangle with upper left corner (left, top) and bottom right corner (right – 1, bottom – 1). These values default to the top, left, bottom and right edges of the image. The client must use an authenticated session with privilege VirtualMachine.Interact.ConsoleInteract on the requested virtual machine or, in the case of a snapshot, the virtual machine associated with that snapshot.

The managed object ID of virtual machine is the value of ManagedObjectReference, which can be easily found using MOB.

Once you have it, you can issue a URL as follows in any browser and get the screen shot in PNG format.

How to Get Metadata of VMware vSphere API?

September 7th, 2010 No comments

VMware vSphere API is defined by WSDL. As discussed in my previous blog REST or SOAP, Web Services is by nature procedural, and it does not support OO (object oriented). This contributes to the learning curve of vSphere Web Service API which is modeled with OO.

What if you want to find out what properties are supported by a particular managed object type in vSphere API? There was a specific question recently in blog comment: how to get valid/supported property paths like summary.hardware.numNics with HostSystem type.

Currently there is no systematically way to get this metadata which is not defined in WSDL. You have to manually read through vSphere API Reference.

Since vSphere Java API 1.0 (a.k.a. VI Java API by then), I have manually added a getter method for every property in the Java API. So the metadata is built in vSphere Java API from the beginning. Whenever there is a manual process, it could be error-prone. As much carefully as I liked, I made mistakes with properties ignored in vSphere Java API occasionally. These mistakes have been immediately patched up upon bug reports or self reviewing.

To get exactly what you want programmatically, you have to do something extra with Java reflection API. Let’s pick HostSystem as an example here.

vSphere Java API at VMworld 2010

September 6th, 2010 No comments

Last week was a super busy week for all the people involved in VMworld 2010 in San Francisco. Because I spent two hours driving to Moscone Center and back home, I didn’t write any blog after getting back totally exhausted. Now it’s time to get back to it.

I believe there are many blogs/news on VMworld in general. Let me get down to a much narrow part: VMware Sponsored open source vSphere Java API at VMworld 2010.

Thanks to the community, my presentation on vSphere API Best Practice went very well. It’s based on the top 10 best practices blog (part 1, part 2) I wrote early this year, with real world experiences shared with partner engagements. Two copies of my book were given away at the end of the presentation. Thanks to Pablo Roesch for getting the books!

After the presentation, I was invited to check out new products built on top of vSphere Java API. I cannot disclose all of them here because some are not yet on the poweredby page. Here are several companies I can publicly talk about:

Ruby to Manage and Automate VMware vSphere?

August 30th, 2010 No comments

As I mentioned in a previous blog, vSphere(VI) Java API can be used in any JVM languages/frameworks. We have samples in Jython, Groovy, Grail. This weekend I got a sample in JRuby shared by our community member Martin Jackson in the API forum. Thanks Martin!

I think it would be fun to share it with you. If you can write Ruby code, you can take advantage of VI Java API for managing and automating vSphere as well. If you have samples leveraging the API to share, I am happy to hear about it.

Now, let us take a look at Martin’s sample code ported from a VI Java API sample.

vSphere Java API 3.0 Kicks off, code name “Crescendo”

August 26th, 2010 11 comments

WIth 2.1 GAed yesterday, I am happy to announce the 3.0 project kicks off officially. For more fun, I picked up a code name for 3.0 release: Crescendo. For folks know music, crescendo means music gets louder and louder. That is where I want to bring the project to. It’s been a huge success for this VMware sponsored open source project. We’ve had 9,000+ downloads, plus 1000+ SVN code sync, after its first debut in 2008.

So where are we going next?

Before answering the question, let’s take a look at the themes of previous releases. The theme of 1.0 was ease of use with full object model and getter methods hiding property collector. The theme of 2.0 was Just Enough High Performance Web Service Engine resulted in not only performance boost, but also clean license with pure BSD, and much smaller footprint and zero memory leak.

Now it’s time to re-visit ease of use again, but from a different perspective. As I discussed early, the learning curve of vSphere API comes from two folds: lack of object model, and complexity of data objects. The 1.0 release solved the problem nicely. Now it’s time to tackle the second one.

Categories: vSphere API Tags:

Announcing vSphere Java API 2.1 GA Release

August 26th, 2010 10 comments

Right after vSphere 4.1 released, VI Java API 2.1 beta supporting vSphere 4.1 was released on July 15. After 40 days, I am pleased to announce GA of the 2.1 release. Many thanks to all vijava community memembers who helped to try 2.1 beta and give feedbacks.

The 2.1 beta is pretty good in terms of quality. I got several emails reporting greeen. I did get several bugs, some of which are carry-overs that should have been fixed in previous releases. Check the end of this blog for a list of bug fixes.

During the beta period, I started a poweredby page which now features 10 companies/products which use vijava API. If you would like your organizations/products included, please let me know.

Enough being said, are you ready to give 2.1 a try? Please feel to download it here. Even you are new to this API, 5 minutes is good enough to have your first HelloVSphere running with this tutorial.

Categories: vSphere API Tags: ,

Secret of vApp Template in vSphere

August 24th, 2010 1 comment

My colleagues and I had a discussion regarding the vApp template. After virtual machine template for virtual machine, you would expect vApp template for vApp and manage it in a similar way from the vSphere Client. But you cannot.

Most of us know that from vSphere Client, you have context menu item allowing you to convert a virtual machine to a template easily with a click. However you cannot find a similar menu item with a vApp. You can choose to convert a virtual machine inside a vApp, but then the converted template will jump out of the vApp container.

Can we have vApp template? The answer is we can, but in a different way.

Restriction with User Name in ESX 4.1

August 23rd, 2010 2 comments

According to a recent post by Duncan, there is an issue with password in ESX(i) 4.1. Only the first 8 characters of a password are taken and validated. A VMware KB article offered solutions to this issue.

Categories: vSphere API Tags: , ,

How to Get Event Type with vSphere API?

August 19th, 2010 12 comments

There is a recent question asking how to get the type of event from vSphere API in my previous blog. On one hand, you can clearly see the types of events on a vSphere Client, for instance “info”, “warning”, “error”, and “user.” On the other hand, you cannot find any information about the type from a given event itself using vSphere API.

Strictly speaking an event just indicates something has happened. That is it. You can categorize it differently depending on your goal. The Event type itself in vSphere API models an event as what it is, not about how you look at it. This is a right design philosophy, but turns out to be a little tricky for you to figure out the type of an event.

How does vSphere Client do the trick?

Categories: vSphere API Tags: , ,

Manage Lockdown Mode with New API in vSphere 4.1

August 17th, 2010 No comments

As a feature, lockdown mode has been added to vSphere 4.0 . Enabling it disables all remote root access to an ESXi machine. Any local changes to the host must be using:

  • DCUI (Direct Console User Interface).
  • vSphere Client or vCLI connecting to vCenter.
  • vSphere Client or vCLI connecting to ESXi with a local user account on the host.

My colleague Duncan Epping has summarized a table showing whether you can change ESXi with different access methods in two modes.

As a general practice for better security, it’s recommended to enable lockdown mode. However the lockdown mode could be breached by adding root user to local groups,

How to Get ESX Version from vCenter?

August 16th, 2010 4 comments

There is a recent question in vSphere(VI) Java API forum about this. On its face, it’s very easy because most people know how to get hold of the version as follows: 

String version = si.getAboutInfo().getVersion();

The si in the above code is the variable of ServiceInstance object. If you have never used the API yet, please try this Getting Started Tutorial which shows how to get your first program running from scratch in 5 minutes

If you are connecting to a vCenter server and try to get the version of a HostSystem the vCenter manages, it’s not so obvious. But it’s definitely doable. Here is the solution assuming you already get hold of the HostSystem object as host variable here: 

String version = host.getConfig().getProduct().getVersion();

Here you know why. First, the aboutInfo is now called product although they are of the same type. Second, it’s hidden within the config property. 

Before taking the code away, I would like to share with you an important tip for better performance. 

Categories: vSphere API Tags: ,

UUID vs. vSphere

August 12th, 2010 4 comments

UUID stands for universally unique identifier (UUID). It’s a 128-bit value. vSphere uses it as IDs for many different types of entities like HostSystem, VirtualMachine, Datastore, etc.

The UUID surfaces to the vSphere API as well. You can find many methods use UUID as parameter or return result. The most commonly used one is the SearchIndex.findByUuid() which find you a virtual machine or a host based on its UUID, either instance or BIOS UUID. The format used for UUID is as follows:

52dc2e26-dbc4-7d05-5fed-019d234379d9

Since 4.0, DistributedVirtualSwitchManager managed object is added and it has a method called queryDvsByUuid(). As reported by VI Java API community, the standard format doesn’t work. The accepted format is like this:

Why Hyperic Chose VI Java API for vSphere Integration?

August 11th, 2010 No comments

VMware SpringSource released Hyperic 4.4 last week. According to Charles Lee, co-founder of Hyperic, one key feature is “enhanced management of VMware virtualized environments through integration with VMware vCenter.” I am glad vSphere(VI) Java API (a.k.a. vijava) has contributed to the success of the product.

Here is part of Charles’s blog Hyperic Broadens vSphere Support through vCenter APIs in Version 4.4 explaining the rationale behind the choice:

How to Promote a Virtual Machine’s Disks?

August 10th, 2010 No comments

What does a promotion mean for a virtual machine’s disks? When you get a promotion, you may have more salary, a better title, bigger office space, etc. For sure a virtual disk cannot earn salary and doesn’t care about title, but it can occupy bigger space in datastore.

In my previous blog, I discussed how to create linked virtual machines using vSphere API. These linked virtual machines share a common disk as base, therefore the total disk consumption is significantly reduced. When a virtual disk is promoted, it gets its own “office” other than sharing it with others.

The vSphere API to promote virtual disks is promoteDisks_Task defined with VirtualMachine type. It has a tricky parameter called “unlink” (type: boolean) . According to the API reference:

1. If the unlink parameter is true, any disk backing which is shared shared by multiple virtual machines is copied so that this virtual machine has its own unshared version. Copied files always end up in the virtual machine’s home directory.

2. Any disk backing which is not shared between multiple virtual machines and is not associated with a snapshot is consolidated with its child backing.

Now when should you use true or false? “If the unlink parameter is true, the net effect of this operation is improved read performance, at the cost of disk space. If the unlink parameter is false the net effect is improved read performance at the cost of inhibiting future sharing.”

Here is the sample code that illustrates the usage of the API:

Vertically Complete Systems: Next Big Trend?

August 9th, 2010 2 comments

IBM recently announced its re-organization around its software and hardware business units. The previously separate business units were merged together as one – the Systems and Software Group led by the former software chief Steve Mills.

You may recall that IBM did not have a dedicated software group until Lou Gerstner created one 15 years ago to centralize all the software businesses into one business unit. This unit has been IBM’s most profitable business. Before that, IBM offered all the software as add-ons to the systems like 390 and AS/400.

Now can we expect IBM to offer hardware systems as add-ons to their software solutions?

Although companies constantly re-organize to streamline their business execution, this reorganization did indicate a big trend is happening in the IT industry. Computer vendors are striving to own vertically-complete stacks: from hardware all the way up to business applications.

Who Created That VM: Java Version of the Winning Script of VMware Contest

August 3rd, 2010 2 comments

As you recall from my previous blog on the Script-O-Mania contest, Alan Renouf won the first prize with his Who Created That VM script written in PowerCLI. The script leverages implicitly several vSphere APIs, so I think it would be cool to have a Java version. At least we can illustrate how to use these related vSphere APIs.

The following is a sample I rewote using VI Java API for the same purpose except that Alan’s script shows full display name of a user while this Java version shows user name (see the following diagram). Although longer, the Java version can run on any OS, not just Windows.

Categories: vSphere API Tags: ,

How to Create Linked Virtual Machines with vSphere API?

August 2nd, 2010 15 comments

More often than not, you may have several virtual machines based on same software stacks running on the same host. Although they are very much the same, they take as much space as multitude of what one virtual machine takes.

Since vSphere 4.0, things are different. You can significantly reduce the storage usage by a new feature called linked virtual machines. The idea is simple: sharing a common virtual disk among the similar virtual machines. The shared virtual disk serves as a base. On top of that, each virtual machine has its own delta disk. When a guest operating system writes to disk, the data persists to the delta disk. When it reads from disk, the delta disk is checked first before trying the base disk.

As a result, you only need to save one copy of the base disk no matter how many virtual machines you have (up to 8 virtual machines in a linked virtual machine group). One limitation is that you cannot use it with HA cluster.

How to create linked virtual machines? You have two approaches: clone a virtual machine either from a snapshot, or from its current running state.

What’s Deprecated in vSphere 4.1 API?

July 27th, 2010 No comments

In vSphere 4.1, several properties and types have been deprecated. The following table from vSphere Web Services SDK 4.1 release note lists each deprecated API element and its replacement.

Name of deprecated type, method, or property As of vSphere API 4.1, use instead…
Methods
PropertyCollector.CheckForUpdates PropertyCollector.WaitForUpdatesEx
PropertyCollector.RetrieveProperties PropertyCollector.RetrievePropertiesEx
PropertyCollector.WaitForUpdates PropertyCollector.WaitForUpdatesEx
VirtualMachine.AcquireMksTicket VirtualMachine.AcquireTicket
Data Objects
VirtualMachineMksTicket VirtualMachineTicket
Data Object Properties
Categories: vSphere API Tags: ,

Complete List of Managed Object Types in VMware vSphere API

July 19th, 2010 No comments

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