• Stars
    star
    202
  • Rank 187,096 (Top 4 %)
  • Language
    Java
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Java samples, language bindings, and API reference documentation for vSphere, VMC, and NSX-T using the VMware REST API

VMware vSphere Automation SDK for Java

Table of Contents

Abstract

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+

Supported OnPrem vCenter Releases:

vCenter 7.0, 7.0U1, 7.0U2, 7.0U3, 8.0, 8.0U1 and 8.0U2

Please refer to the notes in each sample for detailed compatibility information.

Supported NSX-T Releases

NSX-T 2.2, 2.3, 3.0, 4.0.0.0, 4.0.1

Latest VMware Cloud on AWS Release:

VMC M24 (1.24) (Release Notes)

Quick Start Guide

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:

  1. Setting up maven
  2. Setting up a vSphere test environment

Setting up maven

The SDK requires maven to build the samples.

  1. Download the latest maven from https://maven.apache.org/download.cgi and extract it to your machine.
  2. Install JDK 8 and set JAVA_HOME to the directory where JDK is installed.
    export JAVA_HOME=<jdk-install-dir>
  3. Update PATH environment variable to include the maven and jdk "bin" directories.
    export PATH=<maven-bin-dir>:$JAVA_HOME/bin:$PATH

Setting up a vSphere Test Environment

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.

Building the Samples

In the root directory of your folder after cloning the repository, run the below maven commands -

mvn initialize

mvn clean install

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

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-8.0.2.1.jar vmware.samples.vcenter.vm.list.ListVMs

java -cp target/vsphere-samples-8.0.2.1.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-8.0.2.1.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-8.0.2.1.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-8.0.2.1.jar vmware.samples.vcenter.vm.list.ListVMs --config-file sample.properties --server servername

Connect to VMware Cloud on AWS

using csp api_token (also called refresh_token)

import com.vmware.vmc.Orgs;
import com.vmware.vmc.model.Organization;
import com.vmware.vapi.vmc.client.VmcClients;

ApiClient apiClient = VmcClients.createDefault("<refresh_token>");
Orgs orgsStub = apiClient.createStub(Orgs.class);
Organization orgDetails = orgsStub.get("<org_id>");
System.out.println(orgDetails);

Output in console:

Organization (com.vmware.vmc.model.organization) => {
    updated = 8/18/22 20:41:34 +0000,
    userId = xxxx-xxxx-xxxx,
    updatedByUserId = xxxx-xxxx-xxxx,
    created = 10/3/17 22:19:31 +0000,
    version = 4,
    updatedByUserName = xxxx-xxxx-xxxx,
    userName = xxxx-xxxx-xxxx,
    id = xxxx-xxxx-xxxx,
    orgType = INTERNAL_NON_CORE,
    displayName = xxxx/xxxx/xxxx,
    name = xxxx,
    projectState = CREATED,
    properties = OrgProperties (com.vmware.vmc.model.org_properties) => {
        values = {...}
    }
    [dynamic fields]: {
        org_seller_info = <unset>
    }
}

using client_credentials (Server to Server OAuth app's id and secret)

import com.vmware.vmc.Orgs;
import com.vmware.vmc.model.Organization;
import com.vmware.vapi.vmc.client.VmcClients;

ApiClient apiClient = VmcClients.createDefault("<client_id>", "<client_secret>", "<org_id>");
orgsStub = apiClient.createStub(Orgs.class);
Organization orgDetails = orgsStub.get("<org_id>");
System.out.println(orgDetails);

Output in console:

Organization (com.vmware.vmc.model.organization) => {
    updated = 8/18/22 20:41:34 +0000,
    userId = xxxx-xxxx-xxxx,
    updatedByUserId = xxxx-xxxx-xxxx,
    created = 10/3/17 22:19:31 +0000,
    version = 4,
    updatedByUserName = xxxx-xxxx-xxxx,
    userName = xxxx-xxxx-xxxx,
    id = xxxx-xxxx-xxxx,
    orgType = INTERNAL_NON_CORE,
    displayName = xxxx/xxxx/xxxx,
    name = xxxx,
    projectState = CREATED,
    properties = OrgProperties (com.vmware.vmc.model.org_properties) => {
        values = {...}
    }
    [dynamic fields]: {
        org_seller_info = <unset>
    }
}

Importing the samples to eclipse

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:

  1. Go to File -> Import.
  2. Select Existing Projects into Workspace.
  3. Select the root directory as the directory where the samples are located.
  4. Click Finish

Adding a new sample

Once the eclipse project is imported, follow below steps to add a new sample using the sample template:

  1. Right click on the project and select New -> Package. Specify a package name in the wizard and click Finish.
  2. 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.
  3. 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.

API Documentation

vSphere API Documentation

VMware Cloud on AWS API Documentation

NSX API Documentation

Support

For official support, users with Active - Premium SDK Support, Standard SDK Support, Premier/Success 360, and VMware Select Support can reach out to VMware Global Support for any issues in line with our SDK and API Support policy. For community support, please open a Github issue or start a Discussion.

Submitting samples

Developer Certificate of Origin

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.

Required Information

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

Versioning

vSphere Automation Java SDK - X.Y.Z.U.P

vCenter-related: X.Y - (Major release), Z - (Update release), U - (Patch)

vSphere Automation Java SDK - related: P - (vSphere Automation Java SDK Maintenance patches)

Suggested Information

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

Contribution Process

  • 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

Code Style

Please conform to oracle java coding standards. http://www.oracle.com/technetwork/articles/javase/codeconvtoc-136057.html

Resource Maintenance

Maintenance Ownership

Ownership of any and all submitted samples are maintained by the submitter.

Filing Issues

Any bugs or other issues should be filed within GitHub by way of the repository’s Issue Tracker.

Resolving Issues

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.

VMware Sample Exchange

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.

Repository Administrator Resources

Board Members

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:

  • Ankit Agrawal (VMware)
  • Martin Cvetanov (VMware)
  • Shweta Purohit (VMware)
  • Jobin George (VMware)
  • Kunal Singh (VMware)

Approval of Additions

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.

VMware Resources

More Repositories

1

photon

Minimal Linux container host
Python
2,879
star
2

govmomi

Go library for the VMware vSphere API
Go
2,177
star
3

pyvmomi

VMware vSphere API Python Bindings
Python
2,168
star
4

open-vm-tools

Official repository of VMware open-vm-tools project
C
2,048
star
5

differential-datalog

DDlog is a programming language for incremental computation. It is well suited for writing programs that continuously update their output in response to input changes. A DDlog programmer does not write incremental algorithms; instead they specify the desired input-output mapping in a declarative manner.
Java
1,328
star
6

pyvmomi-community-samples

A place for community contributed samples for the pyVmomi library.
Python
989
star
7

PowerCLI-Example-Scripts

PowerShell
734
star
8

vsphere-automation-sdk-python

Python samples, language bindings, and API reference documentation for vSphere, VMC, and NSX-T using the VMware REST API
Python
721
star
9

splinterdb

High Performance Embedded Key-Value Store
C
663
star
10

vic

vSphere Integrated Containers Engine is a container runtime for vSphere.
Go
641
star
11

burp-rest-api

REST/JSON API to the Burp Suite security tool.
Java
546
star
12

versatile-data-kit

One framework to develop, deploy and operate data workflows with Python and SQL.
Python
406
star
13

concord-bft

Concord byzantine fault tolerant state machine replication library
C++
374
star
14

chap

chap analyzes un-instrumented core files for leaks, memory growth, and corruption
C++
345
star
15

kube-fluentd-operator

Auto-configuration of Fluentd daemon-set based on Kubernetes metadata
Go
318
star
16

goipmi

Go IPMI library
Go
181
star
17

vic-product

vSphere Integrated Containers enables VMware customers to deliver a production-ready container solution to their developers and DevOps teams.
RobotFramework
174
star
18

pyvcloud

Python SDK for VMware vCloud Director
Python
170
star
19

ansible-for-nsxt

Ansible delivers simple IT automation that ends repetitive tasks and frees up DevOps teams for more strategic work. This project is to enable this automation for NSX-T installation.
Python
164
star
20

vcd-cli

Command Line Interface for VMware vCloud Director
Python
161
star
21

mangle

Git Repository for the Mangle tool
Java
159
star
22

weathervane

Virtual-Infrastructure and Cloud Performance Benchmark
Java
154
star
23

vmware-go-kcl

KCL Implementation in Go lang by VMware
Go
149
star
24

dscr-for-vmware

The Repository contains Microsoft PowerShell Desired State Configuration (DSC) Resources for managing VC and ESXi settings.
PowerShell
139
star
25

terraform-provider-vcd

Terraform VMware Cloud Director provider
Go
138
star
26

dod-compliance-and-automation

Security hardening content for VMware solutions to US Department of Defense standards
Ruby
135
star
27

ansible-module-vcloud-director

ansible-module-vcloud-director
Python
108
star
28

tdnf

Tiny Dandified Yum
C
106
star
29

terraform-provider-nsxt

Terraform VMware NSX-T provider
Go
103
star
30

declarative-cluster-management

Declarative cluster management using constraint programming, where constraints are described using SQL.
Java
99
star
31

powerclicore

PowerCLI Core Dockerfile
Dockerfile
96
star
32

terraform-provider-vra

Terraform VMware vRealize Automation provider
Go
96
star
33

clarity-city

Clarity City
CSS
91
star
34

load-balancer-and-ingress-services-for-kubernetes

Load Balancer and Ingress services for Kubernetes
Go
87
star
35

hamlet

Multi-Vendor Service Mesh Interoperation
86
star
36

open-vmdk

Python
85
star
37

container-service-extension

Container Service for VMware vCloud Director
Python
78
star
38

go-vcloud-director

Golang SDK for VMware Cloud Director
Go
76
star
39

vrealize-developer-tools

Extension for Visual Studio Code that provides code intelligence features and enables a more developer-friendly experience when creating vRealize content
TypeScript
73
star
40

nsx-t-datacenter-ci-pipelines

CI pipelines for VMware NSX-T Datacenter
Python
72
star
41

flowgate

Project FlowGate is an open-source vendor-neutral project that helps enterprises integrate facility systems data and IT data to form a single holistic view of their operations. By combining these two disparate data sets into one view, data center operators/IT admins are better equipped to optimize operations which were previously impossible.
Java
71
star
42

nsx-powerops

NSX-v Operationalization project. Automate Networking Documentation and HealthCheck.
Python
68
star
43

singleton

A service that provides support for Software Internationalization and Localization
Java
68
star
44

alb-sdk

Avi SDK and Utilities
Java
65
star
45

esx-boot

The ESXi bootloader
C
65
star
46

node-replication

An operation-log based approach for data replication.
Rust
57
star
47

ansible-security-hardening

ansible playbooks for linux distro security hardening
56
star
48

go-vmware-nsxt

golang library for NSX-T REST API
Go
55
star
49

data-annotator-for-machine-learning

Data annotator for machine learning allows you to centrally create, manage and administer annotation projects for machine learning
TypeScript
54
star
50

te-ns

Traffic Emulator for Network Services
C
53
star
51

idm

51
star
52

replay-app-for-tvos

tvOS application that converts an Apple TV into to a digital signage / kiosk
Swift
49
star
53

bitfusion-with-kubernetes-integration

Bitfusion with Kubernetes Integration Support
Go
48
star
54

photon-docker-image

Shell
44
star
55

vmw-guestinfo

Go
41
star
56

terraform-provider-tanzu-mission-control

Terraform provider to manage resources of Tanzu Mission Control
Go
40
star
57

terraform-provider-vra7

Terraform VMware vRealize Automation 7 provider
Go
40
star
58

c-rest-engine

C
39
star
59

power-validated-solutions-for-cloud-foundation

PowerShell Module for VMware Validated Solutions
PowerShell
39
star
60

nsx-alb-datascript-samples-library

DataScript Examples Library
Lua
38
star
61

build-tools-for-vmware-aria

Build Tools for VMware Aria provides development and release management tools for implementing automation solutions based on the VMware Aria Suite and VMware Cloud Director. The solution enables Virtual Infrastructure Administrators and Automation Developers to use standard DevOps practices for managing and deploying content.
Java
38
star
62

harbor-boshrelease

CFF BOSH Release for Project Harbor
Shell
37
star
63

ansible-vsphere-gos-validation

Guest OS validation test set for vSphere using Ansible
Python
37
star
64

cluster-api-provider-cloud-director

Cluster API Provider for VMware Cloud Director. The project is an open source implementation of K8s ClusterAPI project and allows customers to provision resources directly from VMware Cloud Director. It enables Cloud Director powered Clouds to be treated as yet-another-cloud in the multi-cloud journey for VMware Cloud Providers.
Go
36
star
65

script-runtime-service-for-vsphere

The Repository contains Script Runtime Service for vSphere. A service for managing server-side PowerCLI instances to run commands and scripts against VCenter servers.
Smalltalk
35
star
66

vrops-export

vRealize Operations Export Tool
Java
34
star
67

powershell-module-for-vmware-cloud-foundation

PowerShell Module for VMware Cloud Foundation
PowerShell
34
star
68

photon-packer-templates

VMware Photon Packer Templates
HCL
32
star
69

vsphere-automation-sdk-go

Go programming language SDK (Beta) for VMC. NSX-T and vSphere services will be added soon.
Go
32
star
70

likewise-open

Likewise OSS project
C
32
star
71

terraform-provider-avi

Terraform AVI Networks provider
Go
31
star
72

go-ipfix

An ipfix library in Go
Go
30
star
73

network-config-manager

Network configuration manager is utility for easily configuring networking on a linux system
C
30
star
74

nsx-container-plugin-operator

Kubernetes Operator for the NSX Container Plugin (NCP)
Go
30
star
75

nerpa

Network Programming with Relational and Procedural Abstractions (NERPA)
Rust
30
star
76

json-template-engine

This project provides implementations for the JSON template specification.
C++
30
star
77

vidm-saml-toolkit

VMware Identity Manager SAML Toolkit for Developers
Java
28
star
78

vic-ui

vSphere Integrated Containers Plug-In for vSphere Client provides information about your VIC setup and allows you to deploy VCHs directly from the vSphere Client.
TypeScript
27
star
79

cloud-director-named-disk-csi-driver

Container Storage Interface (CSI) driver for VMware Cloud Director
Go
27
star
80

vmware-cloud-director-ui-components

VMware Cloud Director UI Common Components
TypeScript
26
star
81

terraform-provider-vmc

Terraform provider for VMware Cloud on AWS
Go
25
star
82

vsphere-guest-run

Python library for guest operations
Python
24
star
83

python-client-for-vmware-cloud-on-aws

Python Client for VMware Cloud on AWS is an open-source Python-based tool. Written in Python, the tool enables VMware Cloud on AWS users to automate the consumption of their VMware Cloud on AWS SDDC.
Python
24
star
84

vmware-openapi-generator

VMware-openapi-generator tool generates open-api documents from vapi metamodel format.
Python
23
star
85

nsx-advanced-load-balancer-tools

Repository to build Docker container with all Avi tools.
Dockerfile
22
star
86

vSphere-machine-learning-extension

vSphere Machine Learning Extension
Shell
21
star
87

vmware-go-kcl-v2

vmware-go-kcl is a vmware originated open-source project for AWS Kinesis Client Library in Go. It has been widely used by many external companies and internally by Carbon Black. vmware-go-kcl-v2 is its companion project by utilizing AWS Go SDK V2 which introduces lots of breaking changes. To keep the repo clean, it is better to have a separated repo vmware-go-kcl-v2 with better golang project structure improvement.
Go
21
star
88

workflowTools

Developer workflow tooling for jenkins, jira, reviewboard and git
Java
20
star
89

global-load-balancing-services-for-kubernetes

Global Load Balancing Services for Kubernetes
Go
20
star
90

network-event-broker

manages network configuration
Go
20
star
91

crest

Crest machine learning based automated accessibility tests
Python
20
star
92

django-yamlconf

Django settings values via external YAML formatted files simplifying the c onfiguration of Django applications
Python
19
star
93

ansible-collection-alb

VMware Advanced Load Balancer (formerly Avi) Ansible Collection
Python
18
star
94

kernel-event-collector-module

This is the Linux kernel module event collector for the Carbon Black Cloud.
C
18
star
95

vra-sdk-go

VMware vRealize Automation SDK for Go
Python
18
star
96

cloud-provider-for-cloud-director

Kubernetes External Cloud Provider for VMware Cloud Director
Go
18
star
97

vhpc-toolkit

Virtualized High Performance Computing Toolkit - A toolkit to help configure and manage virtual high performance computing (HPC) clusters by leveraging vSphere APIs
Python
17
star
98

upgrade-framework

A product-agnostic framework for defining and sequencing upgrades
Java
17
star
99

powershell-module-for-vmware-cloud-foundation-reporting

PowerShell Module for VMware Cloud Foundation Reporting
PowerShell
17
star
100

nsx-integration-for-openshift

NSX-T deployment playbooks for Openshift integration
Python
16
star