- Abstract
- Supported vCenter Releases
- Table of Contents
- Quick Start Guide
- API Documentation
- Submitting samples
- Resource Maintenance
- Repository Administrator Resources
- VMware Resources
This document describes the vSphere Automation Java SDK samples that use the vSphere Automation java client library. Additionally, some of the samples demonstrate the combined use of the vSphere Automation and vSphere Web Service APIs. The samples have been developed to work with JDK 1.8.
vCenter 6.0, 6.5, 6.7, 6.7U1, 6.7U2
Please refer to the notes in each sample for detailed compatibility information.
The VMware Cloud on AWS API and samples are currently available as a preview and are subject to change in the future.
This document will walk you through getting up and running with the Java SDK Samples. Prior to running the samples you will need to setup a vCenter test environment and install maven, the following steps will take you through this process. Before you can run the SDK samples we'll need to walk you through the following steps:
- Setting up maven
- Setting up a vSphere test environment
The SDK requires maven to build the samples.
- Download the latest maven from https://maven.apache.org/download.cgi and extract it to your machine.
- Install JDK8 and set JAVA_HOME to the directory where JDK is installed.
export JAVA_HOME=<jdk-install-dir>
- Update PATH environment variable to include the maven and jdk "bin" directories.
export PATH=<maven-bin-dir>:$JAVA_HOME/bin:$PATH
NOTE: The samples are intended to be run against a freshly installed non-Production vSphere setup as the scripts may make changes to the test environment and in some cases can destroy items when needed.
To run the samples a vSphere test environment is required with the following minimum configuration
- 1 vCenter Server
- 2 ESX hosts
- 1 NFS Datastore with at least 3GB of free capacity
Apart from the above, each individual sample may require additional setup. Please refer to the sample parameters for more information on that.
In the root directory of your folder after cloning the repository, run the below maven commands -
mvn initialize
mvn clean install
When running the samples, parameters can be provided either on the command line, in a configuration file (using the --config-file parameter), or a combination of both. The parameter values specified on the command line will override those specified in the configuration file. When using a configuration file, each required parameter for the sample must be specified either in the configuration file or as a command line parameter. Each parameter specified in the configuration file should be in the "key=value" format. For example:
vmname=TestVM
cluster=Cluster1
Note: Please specify the fully qualified “hostname” of the server for running the samples to avoid hostname verification errors.
Use a command like the following to display usage information for a particular sample.
$java -ea -cp target/vsphere-samples-6.8.7.jar vmware.samples.vcenter.vm.list.ListVMs
java -cp target/vsphere-samples-6.8.7.jar vmware.samples.vcenter.vm.list.ListVMs [--config-file <CONFIGURATION FILE>]
--server <SERVER> --username <USERNAME> --password <PASSWORD> --cluster <CLUSTER> [--truststorepath <ABSOLUTE PATH OF JAVA TRUSTSTORE FILE>]
[--truststorepassword <JAVA TRUSTSTORE PASSWORD>] [--cleardata] [--skip-server-verification]
Sample Options:
--config-file <CONFIGURATION FILE> OPTIONAL: Absolute path to the configuration file containing the sample options.
NOTE: Parameters can be specified either in the configuration file or on the command
line. Command line parameters will override values specified in the configuration file.
--server <SERVER> hostname of vCenter Server
--username <USERNAME> username to login to the vCenter Server
--password <PASSWORD> password to login to the vCenter Server
--truststorepath <ABSOLUTE PATH OF JAVA TRUSTSTORE FILE> Specify the absolute path to the file containing the trusted server certificates. This
option can be skipped if the parameter skip-server-verification is specified.
--truststorepassword <JAVA TRUSTSTORE PASSWORD> Specify the password for the java truststore. This option can be skipped if the
parameter skip-server-verification is specified.
--cleardata OPTIONAL: Specify this option to undo all persistent results of running the sample.
--skip-server-verification OPTIONAL: Specify this option if you do not want to perform SSL certificate
verification.
NOTE: Circumventing SSL trust in this manner is unsafe and should not be used with
production code. This is ONLY FOR THE PURPOSE OF DEVELOPMENT ENVIRONMENT.
Use a command like the following to run a sample using only command line parameters:
$java -ea -cp target/vsphere-samples-6.8.7.jar vmware.samples.vcenter.vm.list.ListVMs --server servername --username [email protected] --password password --skip-server-verification
Use a command like the following to run a sample using only a configuration file:
$java -ea -cp target/vsphere-samples-6.8.7.jar vmware.samples.vcenter.vm.list.ListVMs --config-file sample.properties
Use the following command to run the sample using a combination of configuration file and command line parameters:
$java -ea -cp target/vsphere-samples-6.8.7.jar vmware.samples.vcenter.vm.list.ListVMs --config-file sample.properties --server servername
To generate the eclipse project files for the samples run the below command
mvn eclipse:clean eclipse:eclipse
Once generated, follow below steps to import the project to eclipse:
- Go to File -> Import.
- Select Existing Projects into Workspace.
- Select the root directory as the directory where the samples are located.
- Click Finish
Once the eclipse project is imported, follow below steps to add a new sample using the sample template:
- Right click on the project and select New -> Package. Specify a package name in the wizard and click Finish.
- Right click on the newly created package and click Import -> General -> File System. In the dialog box, click "Browse" and select the "sample-template" folder in the root directory.
- Select the "SampleClass" in the dialog box and click finish.
This will import a basic sample class to your package, which you can then customize according to your needs.
-
Previous releases: 6.5
Before you start working with this project, please read our Developer Certificate of Origin. All contributions to this repository must be signed as described on that page. Your signature certifies that you wrote the patch or have the right to pass it on as an open-source patch.
The following information must be included in the README.md for the sample.
- Author Name
- This can include full name, email address or other identifiable piece of information that would allow interested parties to contact author with questions.
- Date
- Date the sample was originally written
- Minimal/High Level Description
- What does the sample do ?
- Any KNOWN limitations or dependencies
The following information should be included when possible. Inclusion of information provides valuable information to consumers of the resource.
- vSphere version against which the sample was developed/tested
- SDK version against which the sample was developed/tested
- Java version against which the sample was developed/tested
- Follow the GitHub process
- Please use one branch per sample or change-set
- Please use one commit and pull request per sample
- Please post the sample output along with the pull request
- If you include a license with your sample, use the project license
Please conform to oracle java coding standards. http://www.oracle.com/technetwork/articles/javase/codeconvtoc-136057.html
Ownership of any and all submitted samples are maintained by the submitter.
Any bugs or other issues should be filed within GitHub by way of the repository’s Issue Tracker.
Any community member can resolve issues within the repository, however only the board member can approve the update. Once approved, assuming the resolution involves a pull request, only a board member will be able to merge and close the request.
It is highly recommended to add any and all submitted samples to the VMware Sample Exchange: https://code.vmware.com/samples
Sample Exchange can be allowed to access your GitHub resources, by way of a linking process, where they can be indexed and searched by the community. There are VMware social media accounts which will advertise resources posted to the site and there's no additional accounts needed, as the VMware Sample Exchange uses MyVMware credentials.
Board members are volunteers from the SDK community and VMware staff members, board members are not held responsible for any issues which may occur from running of samples from this repository.
Members:
- Kunal Singh (VMware)
- Jobin Jeorge (VMware)
Items added to the repository, including items from the Board members, require 2 votes from the board members before being added to the repository. The approving members will have ideally downloaded and tested the item. When two “Approved for Merge” comments are added from board members, the pull can then be committed to the repository.