VMware vSphere Automation Python SDK: client README 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 examples have been developed to work with python 2.7, 3.3, 3.4 and 3.5. The following sections provide information about using the samples..
Python SDK and 3rd party DependenciesPlease see the instructions for installing the SDK and 3rd party libraries. Feature Samples The vSphere Automation Python SDK samples are located in the client sample
directory:
samples
vAPI Samples for Managing vSphere Infrastructure and Virtual MachinesThe directory vsphere.samples.vcenter contains samples for the vSphere infrastructure and virtual machine APIs. You have two options to run samples inside this package:
Sample Program Structure for the Content Library and Tagging SamplesThe Content Library and Tagging samples use a framework to facilitate different aspects of using the samples. Some of the framework capabilities are:
samples_base .
This class uses service_manager_factory to create and manage the
vAPI service endpoint and vSphere service port. Every sample implements the
following methods from the class samples_base :
Samples configurationYou can specify server, username and password in the configuration file (sample.cfg). If you use a configuration file, you can run samples without specifying these options on the command line. When you run a sample, you can override the configuration file values by specifying command line options.[connection] server=vCenter server IP username=username password=passwordThe sample.cfg file can be found under VMware-vSphere-Automation-SDK-Python-<version>/client/samples/src
Connection Workflow Samples:
To work with the VMWare-supported deployment configurations of
Platform Services Controllers (Single Sign-On) and vCenter Servers,
applications need to dynamically discover service URLs to make service requests.
Before making service requests, applications need to authenticate.
They can authenticate using a username and password or with a token obtained
from the Single Sign-On service.
Running the Connection Workflow Samples:The following parameters are needed for running the samples:
Working with lookup service WSDLThe vSphere Automation SDK for Python samples use the vSphere Automation Lookup Service to obtain the URLs for other vSphere Automation services (SSO, vAPI, VIM, SPBM, etc.). The SDK contains the Lookup Service WSDL files. The samples use the python SUDS client for accessing the lookup service.The Lookup Service WSDL files are located in the following SDK directory: VMware-vSphere-Automation-SDK-Python-<version>/client/wsdl .
You must specify the WSDL file location in the client/samples/src/sample.cfg file and in the lookupservice.wsdl file (located in the WSDL directory).
Running the samples from the command line
You can run the samples from command line using the scripts supplied in
Examples: $cd /path/to/VMware-vSphere-Automation-SDK-Python-<version>/client/bin $run_sample.sh ../samples/src/vsphere/samples/workflow/connection_workflow.py \ -vapiurl https://203.0.113.0/api \ -stsurl https://203.0.113.0:443/sts/STSService/vsphere.local \ -username administrator@vsphere.local \ -password AdminPasswordUse the -h option to print information about a sample. The following example shows the help for the vAPI connection workflow sample. $ ./run_sample.sh ../samples/src/vsphere/samples/workflow/vapi_connection_workflow.py -h usage: vapi_connection_workflow.py [-h] [-w LSWSDLURL] [-s LSSOAPURL] [-m MGMTINSTANCENAME] [-u USERNAME] [-p PASSWORD] [-v] Demonstrates vAPI connection and service initialization call flow using the username and password. Step 1: Retrieve the vAPI service endpoint URL from lookup service. Step 2: Connect to the vAPI service endpoint. Step 3: Use the username/password to login to the vAPI service endpoint. Step 4: Create a vAPI session. Step 5: Validate some of the vAPI services. Step 6: Delete the vAPI session. optional arguments: -h, --help show this help message and exit -w LSWSDLURL, --lswsdlurl LSWSDLURL Lookup service WSDL URL -s LSSOAPURL, --lssoapurl LSSOAPURL Lookup service SOAP URL -m MGMTINSTANCENAME, --mgmtinstancename MGMTINSTANCENAME Instance name of the vCenter Server management node. When only one node is registered, it is selected by default; otherwise, omit the parameter to get a list of available nodes. -u USERNAME, --username USERNAME SSO user name -p PASSWORD, --password PASSWORD SSO user password -v, --skipverification Do not verify server certificate Note: In the above example mgmtinstancename is optional and can be omitted if there's a single vCenter Server management node in the deployment. When there is more than one management node, the user MUST specify the management node instance name against which the sample needs to run, else the sample throws MultipleManagementNodeException. Example of a multiple management node exception: raise MultipleManagementNodeException(MultipleManagementNodeException.format(result)) vsphere.samples.common.lookup_service_helper.MultipleManagementNodeException: Multiple Management Node Found on server Node name: vcenter-1.example.com uuid: de2afd86-790e-11e4-9c20-0200087f55c6 Node name: vcenter-2.example.com uuid: 545da868-7910-11e4-81e1-020008e89d83Example exception when an invalid management instance name is specified by the user: ValueError: abc is not a valid management node instance name Available management nodes: Node name: vcenter-2.example.com uuid: 545da868-7910-11e4-81e1-020008e89d83 Node name: vcenter-1.example.com uuid: de2afd86-790e-11e4-9c20-0200087f55c6
|