• Stars
    star
    721
  • Rank 60,673 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created about 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

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

VMware vSphere Automation SDK for Python

Build Status

Table of Contents

Abstract

This document describes the vSphere Automation Python SDK samples that use the vSphere Automation python client library. Additionally, some of the samples demonstrate the combined use of the vSphere Automation and vSphere APIs. To support this combined use, the vSphere Automation Python SDK samples require the vSphere Management SDK packages (pyVmomi) to be installed on the client. The samples have been developed to work with python 3.8+

Supported OnPrem vCenter Releases

vCenter 7.0, 7.0U1, 7.0U2, 7.0U3 , 8.0 and 8.0U1 Please refer to the notes in each sample for detailed compatibility information.

Supported NSX-T Releases

NSX-T 2.2 - 4.1.0 and VMC 1.7 - 1.22

Latest VMware Cloud on AWS Release:

VMC M22 (1.22) (Release Notes)

Quick Start Guide

Prepare a Python Development Environment

We recommend you to install latest Python and pip on your system.

A Python virtual environment is also highly recommended.

Installing Required Python Packages

SDK package installation commands may differ depending on the environment where it is being installed. The three installation options provided below are for different environments. pip and setuptools are common requirements for these installation types, upgrade to the latest pip and setuptools.

NOTE: The SDK also requires OpenSSL 1.0.1+ in order to support TLS1.1 & 1.2

1. Typical Installation

This is the recommended way to install the SDK. The installation is done from PyPI and Automation SDK Python Github repositories.

Install/Update latest pip from PyPI.

pip install --upgrade pip

Install/Update setuptools

pip install --upgrade setuptools

Install SDK packages from Github.

pip install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git
2. Local installation

Local installation can be used in an environment which either do not have Github access or users do not want to install from Github repository.

Install all the wheel files from SDK's lib directory.

pip install -U lib/*/*.whl

Install dependencies like lxml and pyvmomi from PyPI as other requirements were installed from SDK's lib directory.

pip install -U <SDK_DIRECTORY_PATH>

Where <SDK_DIRECTORY_PATH> is either install directory of the SDK or location of SDK's zip e.g.

pip install -U /root/vsphere-automation-sdk-python
Or
pip install -U vsphere-automation-sdk-python-8.0.0.0.zip
3. Installation in an air gap environment

For this type of environment an additional step is required to ensure SDK's dependencies are available. Following dependencies have to be downloaded from PyPI and transferred to the air gap environment.

NOTE: This step has to be done in an environment which has PyPI access.

pip download  -r requirements_pypi.txt -d lib
zip -r lib.zip lib/

Follow these steps in the air gap environment. Unzip the lib.zip under automation SDK home directory.

unzip lib.zip

Install all the dependencies and packages.

pip install -U lib/**/*.whl

This is to install the "vSphere-Automation-SDK" which provides an SDK version. It also ensures that all the SDK requirements are installed. If not, the installation will fail.

pip install -U `pwd`

Connect to a vCenter Server

import requests
import urllib3
from vmware.vapi.vsphere.client import create_vsphere_client
session = requests.session()

# Disable cert verification for demo purpose. 
# This is not recommended in a production environment.
session.verify = False

# Disable the secure connection warning for demo purpose.
# This is not recommended in a production environment.
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

# Connect to a vCenter Server using username and password
vsphere_client = create_vsphere_client(server='<vc_ip>', username='<vc_username>', password='<vc_password>', session=session)

# List all VMs inside the vCenter Server
vsphere_client.vcenter.VM.list()

Output in a Python Interpreter:

(venv) het-m03:vsphere-automation-sdk-python het$ python
Python 3.9.8 (main, Nov 10 2021, 06:03:50)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> import urllib3
>>> from vmware.vapi.vsphere.client import create_vsphere_client
>>> session = requests.session()
>>> session.verify = False
>>> urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) 
>>> vsphere_client = create_vsphere_client(server='<vc_ip>', username='<vc_username>', password='<vc_password>', session=session)
>>> vsphere_client.vcenter.VM.list()
[Summary(vm='vm-58', name='standalone-20e4bd3af-esx.0-vm.0', power_state=State(string='POWERED_OFF'), cpu_count=1, memory_size_mib=256), 
...]

NOTE: If you are using Bash, be sure to use single quote for username and password to preserve the values. If you use double quote, you will have to escape special characters, such as "$". See Bash manual

Connect to VMware Cloud on AWS

from vmware.vapi.vmc.client import create_vmc_client

# Connect to VMware Cloud on AWS using refresh token
vmc_client = create_vmc_client('<refresh_token>')

# Get organizations associated with calling user.
vmc_client.Orgs.list()

Output in a Python Interpreter:

(venv) het-m03:vsphere-automation-sdk-python het$ python
Python 3.9.8 (main, Nov 10 2021, 06:03:50)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from vmware.vapi.vmc.client import create_vmc_client
>>> vmc_client = create_vmc_client('<refresh_token>')
>>> vmc_client.Orgs.list()
[Organization(updated=datetime.datetime(2018, 3, 2, 16, 57, 46), user_id='77aa6e6f-3257-3637-9cd9-14fae3a25b9d', updated_by_user_id='2021b5ae-890b-3472-ba9a-bc8cff776ca7', created=datetime.datetime(2017, 4, 4, 11, 57, 48, 861), version=15, updated_by_user_name='[email protected]', user_name='[email protected]', id='2a8ac0ba-c93d-4748-879f-7dc9918beaa5', display_name='VMC-SET', name='j13hqg73', sla='VMC_INTERNAL', project_state='CREATED', properties=OrgProperties(values={'defaultAwsRegions': 'US_WEST_2,US_EAST_1', 'sddcLimit': '5', 'planVersion': '3.0', 'defaultHostsPerSddc': '4', 'invitationCode': '/csp/gateway/slc/api/service-invitations/aa7203c3617bbe755597b8b0ad652', 'enableAWSCloudProvider': 'true', 'enableZeroCloudCloudProvider': 'true', 'accountLinkingOptional': 'false', 'defaultPDXDatacenter': 'pdx2', 'skipSubscriptionCheck': 'true', 'minHostsPerSddc': '4', 'maxHostsPerSddc': '8', 'hostLimit': '16', 'maxHostsPerSddcOnCreate': '4', 'isAllAccess': 'true', 'enabledAvailabilityZones': '{"us-east-1":["iad6","iad7","iad12"],"us-west-2":["pdx1", "pdx4", "pdx2"]}'}), cloud_configurations={'AWS': AwsOrgConfiguration(provider='AWS')})
...]

Run SDK Samples

In this section we will walk you through the steps to run the sample code for vSphere and VMware Cloud on AWS APIs.

First, set PYTHONPATH to use SDK helper methods

  • Linux/Mac:

    export PYTHONPATH=${PWD}:$PYTHONPATH

  • Windows:

    set PYTHONPATH=%cd%;%PYTHONPATH%

Run VMware Cloud on AWS Samples

$ python samples/vmc/orgs/organization_operations.py -r <refresh_token>

Run vSphere Samples

A vSphere test environment is required with the following configuration:

  • 1 vCenter Server
  • 2 ESX hosts
  • 1 NFS Datastore with at least 3GB of free capacity

Note Please have the details of these available but do not have any configuration pre-created on vCenter server or ESXi Hosts, for example there should be no existing datacenters, clusters or attached hosts on the vCenter server.

Running the SDK Sample Setup Script

Before executing the samples we'll need to setup the vSphere test environment using one of the sample scripts (samples/vsphere/vcenter/setup/main.py). The script will perform the following:

  • Create 2 test Datacenters
  • Create a test Cluster
  • Create Test Folders for VM Storage
  • Attach the hosts
  • Create a Distributed Switch
  • Create a Distributed Portgroup
  • Attach the NFS datastore (if Selected) to the hosts
  • Copy the Photon OS ISO image downloaded from VMware's bintray server to the datastore
  • Create directories to add sample ports

First, edit settings in samples/vsphere/vcenter/setup/testbed.py and replace everything in < > brackets with your environment information. Leave the rest of the settings in this file at their default values.

config["SERVER"]    = "<vcenter_hostname_or_ip>"
config["USERNAME"]  = "<vsphere_username>"
config["PASSWORD"]  = "<vsphere_password>"

config["ESX_HOST1"] = "<ESX_host1_ipaddress>"
config["ESX_HOST2"] = "<ESX_host2_ipaddress>"
config["ESX_USER"]  = "<esx_username>"
config["ESX_PASS"]  = "<esx_password>"

config["USE_NFS"]   = True
config["NFS_HOST"]  = "<nfs_ipaddress>"
config["NFS_REMOTE_PATH"] = "/store1"

At this point, we're ready to run the setup script:

$ python samples/vsphere/vcenter/setup/main.py -sv

After completion you will see from the output and also the vSphere Client that the environment has now been fully setup and is ready to easily run further samples.

To view other available command-line options:

$ python samples/vsphere/vcenter/setup/main.py -h

Run the vAPI vCenter sample suite:

$ python samples/vsphere/vcenter/setup/main.py -riv

Run a specific sample in a standalone mode:

$ python samples/vsphere/vcenter/vm/list_vms.py -v

API Documentation

vSphere API Documentation

VMware Cloud on AWS API Documentation

NSX API Documentation

Troubleshooting

Common issues you may run into while installing the sdk and running samples are listed here

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)
  • Jobin George (VMware)
  • Martin Tsvetanov (VMware)
  • Shweta Purohit (VMware)
  • Kunal Singh (VMware)

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,339
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

splinterdb

High Performance Embedded Key-Value Store
C
664
star
9

vic

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

burp-rest-api

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

versatile-data-kit

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

concord-bft

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

chap

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

kube-fluentd-operator

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

vsphere-automation-sdk-java

Java samples, language bindings, and API reference documentation for vSphere, VMC, and NSX-T using the VMware REST API
Java
202
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

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
19

mangle

Git Repository for the Mangle tool
Java
159
star
20

weathervane

Virtual-Infrastructure and Cloud Performance Benchmark
Java
154
star
21

vmware-go-kcl

KCL Implementation in Go lang by VMware
Go
149
star
22

dscr-for-vmware

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

terraform-provider-vcd

Terraform VMware Cloud Director provider
Go
138
star
24

dod-compliance-and-automation

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

ansible-module-vcloud-director

ansible-module-vcloud-director
Python
108
star
26

tdnf

Tiny Dandified Yum
C
106
star
27

terraform-provider-nsxt

Terraform VMware NSX-T provider
Go
105
star
28

declarative-cluster-management

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

powerclicore

PowerCLI Core Dockerfile
Dockerfile
96
star
30

terraform-provider-vra

Terraform VMware vRealize Automation provider
Go
96
star
31

clarity-city

Clarity City
CSS
91
star
32

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

Load Balancer and Ingress services for Kubernetes
Go
87
star
33

hamlet

Multi-Vendor Service Mesh Interoperation
86
star
34

open-vmdk

Python
85
star
35

container-service-extension

Container Service for VMware vCloud Director
Python
78
star
36

go-vcloud-director

Golang SDK for VMware Cloud Director
Go
76
star
37

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
38

nsx-t-datacenter-ci-pipelines

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

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
40

nsx-powerops

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

singleton

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

alb-sdk

Avi SDK and Utilities
Java
65
star
43

esx-boot

The ESXi bootloader
C
65
star
44

node-replication

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

ansible-security-hardening

ansible playbooks for linux distro security hardening
56
star
46

go-vmware-nsxt

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

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
48

te-ns

Traffic Emulator for Network Services
C
53
star
49

idm

51
star
50

replay-app-for-tvos

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

bitfusion-with-kubernetes-integration

Bitfusion with Kubernetes Integration Support
Go
48
star
52

photon-docker-image

Shell
44
star
53

vmw-guestinfo

Go
41
star
54

terraform-provider-tanzu-mission-control

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

terraform-provider-vra7

Terraform VMware vRealize Automation 7 provider
Go
40
star
56

c-rest-engine

C
39
star
57

power-validated-solutions-for-cloud-foundation

PowerShell Module for VMware Validated Solutions
PowerShell
39
star
58

nsx-alb-datascript-samples-library

DataScript Examples Library
Lua
38
star
59

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
60

harbor-boshrelease

CFF BOSH Release for Project Harbor
Shell
37
star
61

ansible-vsphere-gos-validation

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

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
63

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
64

vrops-export

vRealize Operations Export Tool
Java
34
star
65

powershell-module-for-vmware-cloud-foundation

PowerShell Module for VMware Cloud Foundation
PowerShell
34
star
66

photon-packer-templates

VMware Photon Packer Templates
HCL
32
star
67

vsphere-automation-sdk-go

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

likewise-open

Likewise OSS project
C
32
star
69

terraform-provider-avi

Terraform AVI Networks provider
Go
31
star
70

go-ipfix

An ipfix library in Go
Go
30
star
71

network-config-manager

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

nsx-container-plugin-operator

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

nerpa

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

json-template-engine

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

vidm-saml-toolkit

VMware Identity Manager SAML Toolkit for Developers
Java
28
star
76

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
77

cloud-director-named-disk-csi-driver

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

vmware-cloud-director-ui-components

VMware Cloud Director UI Common Components
TypeScript
26
star
79

terraform-provider-vmc

Terraform provider for VMware Cloud on AWS
Go
25
star
80

vsphere-guest-run

Python library for guest operations
Python
24
star
81

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
82

vmware-openapi-generator

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

nsx-advanced-load-balancer-tools

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

vSphere-machine-learning-extension

vSphere Machine Learning Extension
Shell
21
star
85

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
86

workflowTools

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

global-load-balancing-services-for-kubernetes

Global Load Balancing Services for Kubernetes
Go
20
star
88

network-event-broker

manages network configuration
Go
20
star
89

crest

Crest machine learning based automated accessibility tests
Python
20
star
90

django-yamlconf

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

ansible-collection-alb

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

kernel-event-collector-module

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

vra-sdk-go

VMware vRealize Automation SDK for Go
Python
18
star
94

cloud-provider-for-cloud-director

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

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
96

upgrade-framework

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

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

PowerShell Module for VMware Cloud Foundation Reporting
PowerShell
17
star
98

nsx-integration-for-openshift

NSX-T deployment playbooks for Openshift integration
Python
16
star
99

trace-cruncher

Trace-Cruncher provides an interface between the existing instrumentation for collection and visualization of Linux kernel tracing data and the ecosystem of instruments for data analysis available in Python.
C
16
star
100

cloud-director-extension-standard-library

Standard Library for VMware Cloud Director solutions add-ons and add-on elements.
TypeScript
16
star