Using Nutanix Java SDK for Automation – Sample Code and Repo

DevOps is a response to the growing awareness that there is a disconnect between what is traditionally considered development activity and what is traditionally considered operations activity. For the business, DevOps contributes directly to enabling business agility and IT alignment.

Software vendors working with Nutanix to integrate their software stack into the Nutanix PRISM APIs allowing applications to drive infrastructure requirements such as security, availability, reliability and performance. These requirements go well beyond software defined storage configurations, but I leave this subject for another day.

That said, there is an increasing need for enterprise automation and it is Nutanix job to provide the means to make it happen. You should expect Nutanix to provide modules and integrate directly with configuration management, provisioning and orchestration tools such as Puppet, BMC, Chef, vCenter Orchestrator, SCOM, vCOPS and others; but you will also see Nutanix PRISM development kits for Java, Python, PowerShell and others languages be made available soon. As matter of fact Java and PowerShell are already available.


The Java SDK

As announced in one of my previous posts NOS 4.0 now ships with a Java SDK inside the nCLI package. In the PRISM UI there is a download nCLI option that will download a zip file containing the ncli.cmd and extra .jar files under the lib folder. There you will find the prism_sdk_rest.jar, the Nutanix Java SDK that uses PRISM REST APIs.


The first release of the Java SDK does not include binary dependencies, so you would need to map dependencies one-by-one and download them from multiple sources. Fortunately, we have done the work for you and you won’t have to track dependencies. The sample Java code that I have uploaded to the Nutanix Repository contains all the required binaries, exemplifies how to connect to PRISM API and execute few queries.

Click here to go to repository.


In the Java code being provided you will find all the required binaries and couple initial sample functions, including: getVMsgetDisksgetHostsgetContainersgetManagementServers and getProtectionDomains. For my next article I will include functions to change virtual machine availability, create new containers or protection domains etc.

In the  code the ServerConnectionManager class is responsible for API connectivity and should be first instantiated ‘connMgr‘. Once the connection to PRISM is successful other objects may be instantiated.

		// Stablish connection with PRISM API
		final ServerConnectionsManager connMgr = ServerConnectionsManager

		// Retrieve list of virtual machines and properties
		System.out.println("Virtual Machines");
		final VMAdministration ref4 = connMgr.getVMAdministration();
		final List vms = ref4.getVMs(null, null, null).getEntities();
		final Iterator iteratorVms = vms.iterator();
		while (iteratorVms.hasNext()) {



Nutanix does not have yet documentation for the Java SDK, but it is safe to say that the entire PRISM API feature-set has been made available via the SDK. The classes I find myself using the most are related to hosts, VMs, health check and protection domains, but there are also classes specific to hypervisor configuration, multi clusters, virtual disk administration, licensing and others. If you want to see the entire list of classes, click here.


Self-Signed Certificate

One of the challenges I faced in my Nutanix lab environment was a self-signed certificate, so I implemented a class that ignores the original self-signed certificate – While this is bad security practice I am not planning to implement a valid certificate in my lab environment. I suggest that you implement a valid signed certificate from a trusted root CA authority in your production Nutanix environment.


Sample Code Results

The sample code will list VMs, Containers, Hosts, Disks, Protection Domains and Management Servers. The results are iterated thought and printed to the console. Here is the results after running the code.

(Click to Enlarge)

Screen Shot 2014-08-10 at 4.44.35 PM


REST API Explorer

Some of the Java objects in the SDK will require knowledge about their entities and fields. Since there is no documentation at this point you can simply go to the REST API Explorer and PRISM and identify what should be provided in each of the fields or objects.

(Click to Enlarge)

Screen Shot 2014-08-10 at 5.31.50 PM


If you happen to build any interesting function please share it with me and I will add to the Sample Code in GitHub.

I would like to thank Nutanix engineer Vamsi Krishna for compiling the first version of the sample code.


This article was first published by Andre Leibovici (@andreleibovici) at

Leave a Reply

Your email address will not be published.