VMware vSphere Automation SDK Java: samples README

VMware logo

This document describes the vSphere Automation SDK for Java samples that use the vSphere Automation Java client library (vsphereautomation-client-sdk-6.5.0.jar) and vAPI runtime library (vapi-runtime-2.5.0.jar). Additionally, some of the samples demonstrate the combined use of the vSphere Automation SDK APIs and the vSphere Web Services API. To support this combined use, the vSphere Automation SDK for Java includes the vSphere Management SDK jar (vim25.jar). The examples have been developed to work with JDK 1.8.

The following sections provide information about using the samples..

Sample Packaging

The sample sub-directories show the organization of the samples Java packages. The samples are organized into the following capabilities:

PackageDescription
vmware.samples.taggingFeature samples for Tagging
vmware.samples.commonCommon classes used in the samples; This package does NOT contain any samples
vmware.samples.common.vim.helpersHelper and util classes for vSphere Web Services APIs. This package does NOT contain any samples
vmware.samples.contentlibraryFeature samples for content library
vmware.samples.vcenterFeature samples for virtual machine configuration and operations
vmware.samples.ssoSamples for sso authentication

Running the samples

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
To display the usage information for a sample, run the sample without specifying any parameters.

The SDK provides the command line scripts run.sh (Linux) and run.bat (Windows) for running the samples. These files are located in the VMware-vSphere-Automation-SDK-Java/client/bin directory. Note that you must set the JAVA_HOME environment variable to the base directory for JDK 1.8 before running the samples.

Examples of running a sample and providing parameters on the command line


Use a command like the following to display usage information for a sample:
$./run.sh vmware.samples.tagging.workflow.TaggingWorkflow
usage:
./run.sh | run.bat packagename.SampleClassName [--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
    --cluster <CLUSTER>                                        The name of the cluster to be tagged
    --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:
$./run.sh vmware.samples.tagging.taggingworkflow.TaggingWorkflow --server servername --username administrator@vsphere.local --password password --cluster vAPISDKCluster --cleardata true --skip-server-verification

Examples of running a sample and providing parameters in a configuration file


Use a command like the following to run a sample using only a configuration file:
$./run.sh vmware.samples.tagging.workflow.TaggingWorkflow --config-file sample.properties

Use the following command to run the sample using a combination of configuration file and command line parameters:
$./run.sh vmware.samples.tagging.workflow.TaggingWorkflow --config-file sample.properties --cluster Cluster1

Importing the samples project in Eclipse

The samples directory contains .project and .classpath Eclipse project files. You can use these for code browsing or for development. To import the samples into Eclipse, use VMware-vSphere-Automation-SDK-Java/client/samples as the root directory for an existing project.


Copyright © 2015,2016 VMware, Inc. All rights not expressly granted herein are reserved.

Last updated: September 21, 2016 |  VMware vSphere Automation SDK Java