The Content Library is a core component that is part of the vCenter Server.
It is a new addition to the vSphere 6.0 release.
The API samples published here are accompanied by the blogs published by the Content Library Team, which explain the use of Content Library APIs and various concepts introduced by the Content Library Service.
This document will go through the steps required:
- to quickly run a Content Library API sample
- to setup a development environment to facilitate development and exploration using the Content Library APIs
Following instructions are for the Mac OS X, but are applicable to other platforms as well (with minimal platform specific changes).
- VMware vCenter Server 6.0 installed.
- VMware vCloud Suite SDK 6.0 for Java downloaded and extracted to a local directory.
These samples are based on the following version of the SDK.VMware-vCloud-Suite-SDK-Java-6.0.0-2561089.zip File size:55 MB File type:zip Release Date:2015-03-12 Build Number:2561089
- a JDK (>=1.7).
- The environment variable
JAVA_HOMEmust be defined.$ export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_76.jdk/Contents/Home"
git- good to have, but even otherwise you can download the source-code directly.
- You can get the sample code by cloning this repository, or by downloading the sources directly.
$ mkdir ~/my-projects $ cd ~/my-projects $ git clone https://github.com/vmware/content-library-api-samples.git $ cd content-library-api-samples
- We need the libraries from the SDK to build the source code. Let's assume that the SDK is downloaded in
~/Downloadsdirectory. The extracted contents will be placed inVMware-vCloud-Suite-SDK-Javadirectory by default.$ cd ~/Downloads $ unzip VMware-vCloud-Suite-SDK-Java-6.0.0-2561089.zip
- Let's copy the libraries from the directory where we have extracted the SDK.
$ cp -r ~/Downloads/VMware-vCloud-Suite-SDK-Java/client/lib ~/my-projects/content-library-api-samples
- Let's build the samples and run the executor script generated by
gradle.
The code samples usegradlefor its build system.
You don't needgradleto be installed sincegradlewdoes it for you.$ cd ~/my-projects/content-library-api-samples $ ./gradlew installApp
- Let's run the generated executor script which is configured to run the sample from
LibraryCount.java.
This sample connects to the provided vCenter Server instance, and lists the number of content libraries available in that instance.$ cd ~/my-projects/content-library-api-samples $ ./build/install/content-library-api-samples/bin/content-library-api-samples Enter the hostname/IP for the vCenter SSO Server: vcenter.example.com Enter SSO username: administrator@vsphere.local Enter SSO password: The number of libraries in this system is: 0 $
-
Congratulations! You just ran a very basic Content Library API sample successfully!
Head over to the Development Setup section if you want to get your hands dirty. -
To run other samples, use of an IDE is recommended. However, following is an option to run those directly from the command line
$ cd ~/my-projects/content-library-api-samples $ java -cp "./build/libs/content-library-api-samples-1.0.jar:lib/*" com.vmware.content.samples.LibraryCount Enter the hostname/IP for the vCenter SSO Server: vcenter.example.com Enter SSO username: administrator@vsphere.local Enter SSO password: The number of libraries in this system is: 0
To run any sample, you could use the above pattern.
$ cd ~/my-projects/content-library-api-samples $ java -cp "./build/libs/content-library-api-samples-1.0.jar:lib/\*" com.vmware.content.samples.<SAMPLE\_CLASS\_NAME>
In addition to the requirements from the previous section, we will need:
- a decent IDE (Eclipse, IntelliJ IDEA, etc.).
This documentation is based on Eclipse, but the steps shouldn't be very different for other IDEs.
gradlecomes with a task to generate an Eclipse project and classpath files, so we will use that to speed up the import.$ cd ~/my-projects/content-library-api-samples $ ./gradlew eclipse
-
Launch your Eclipse and import the
content-library-api-samplesdirectory as an Eclipse project.
- To run the sample of your choice, select and right click on the API sample in the Project Explorer view, and choose
Run As > Java Applicationfrom the context menu.
- This setup is what you need to make use of the Content Library APIs for your requirements.
- Feel free to explore Content Library APIs on your own.
- And follow the blogs published by the Content Library Team which explain the concepts and APIs exposed by the Content Library Service.
- To be able to run the samples with ease, we have included sample
ISOandOVFfiles to be used for uploads. - However, these are not real
ISOorOVFfiles. These are plain-text files and contain fake data. These are included for convenience only. - It is recommended to use real
ISOandOVFfiles to run the workflows and realize all the benefits exposed by the Content Library Service and VMware Virtual Infrastructure.
- HTTP URL to be used when importing
OVFto a library:
http://vmware.github.io/content-library-api-samples/input/sample-ovf/descriptor.ovf (891 bytes) - To upload
OVFfrom a local storage to a library, please downloadOVFand its referencedVMDKfiles from following URLs in the same directory on the local storage- Download
OVFfrom here (891 bytes) - Download
VMDKfor the aboveOVFfrom here (68 bytes)
- Download
- HTTP URL to be used when importing
ISOto a library:
http://vmware.github.io/content-library-api-samples/input/sample-iso/only-for-demo.iso - To upload
ISOfrom a local storage to a library, please download theISOfile from the above URL.
