table of contents - vmwareusing pydev and the pyvmomi sdk.....7 inspecting the vcenter inventory...

63
Table of Contents Lab Overview - HOL-SDC-1622 - VMware Development Tools and SDKs ........................... 2 Lab Overview .......................................................................................................... 3 Module 1 - Datacenter automation for Python scripters (60 Minutes) .............................. 5 Overview ................................................................................................................. 6 Using PyDev and the pyvmomi SDK ........................................................................ 7 Inspecting the vCenter inventory from the Python interpreter ............................. 13 Python scripting with the vCloud Suite SDK for Python ......................................... 21 Conclusion............................................................................................................. 24 Module 2 - Python Scripting vRealize Orchestrator Workflows with the REST API (30 Minutes) .......................................................................................................................... 25 Overview ............................................................................................................... 26 Python scripting of vRealize Orchestrator Workflows ............................................ 27 Conclusion............................................................................................................. 37 Module 3 - Datacenter automation for Java programmers (60 Minutes) ......................... 38 Overview ............................................................................................................... 39 Using Workbench IS and the vSphere Management SDK ...................................... 40 Workbench IS and the vCloud Suite SDK for Java .................................................. 47 Conclusion............................................................................................................. 50 Module 4 - Workbench IS Tools (15 Minutes) ................................................................... 51 Overview ............................................................................................................... 52 Using the Remote System Explorer (RSE) ............................................................. 53 Conclusion............................................................................................................. 62 HOL-SDC-1622 Page 1 HOL-SDC-1622

Upload: others

Post on 15-Jul-2020

15 views

Category:

Documents


0 download

TRANSCRIPT

  • Table of ContentsLab Overview - HOL-SDC-1622 - VMware Development Tools and SDKs...........................2

    Lab Overview .......................................................................................................... 3Module 1 - Datacenter automation for Python scripters (60 Minutes) ..............................5

    Overview................................................................................................................. 6Using PyDev and the pyvmomi SDK........................................................................ 7Inspecting the vCenter inventory from the Python interpreter .............................13Python scripting with the vCloud Suite SDK for Python.........................................21Conclusion............................................................................................................. 24

    Module 2 - Python Scripting vRealize Orchestrator Workflows with the REST API (30Minutes) .......................................................................................................................... 25

    Overview............................................................................................................... 26Python scripting of vRealize Orchestrator Workflows ............................................27Conclusion............................................................................................................. 37

    Module 3 - Datacenter automation for Java programmers (60 Minutes) .........................38Overview............................................................................................................... 39Using Workbench IS and the vSphere Management SDK ......................................40Workbench IS and the vCloud Suite SDK for Java.................................................. 47Conclusion............................................................................................................. 50

    Module 4 - Workbench IS Tools (15 Minutes)................................................................... 51Overview............................................................................................................... 52Using the Remote System Explorer (RSE) ............................................................. 53Conclusion............................................................................................................. 62

    HOL-SDC-1622

    Page 1HOL-SDC-1622

  • Lab Overview - HOL-SDC-1622 - VMware

    Development Tools andSDKs

    HOL-SDC-1622

    Page 2HOL-SDC-1622

  • Lab OverviewThis introductory lab will get you started building and automating cloud infrastructuresolutions with VMware development tools and SDKs. These are scripter and developerfocused modules and some familiarity with programming in Python or Java is expected.But don't worry, no coding is required. Complete sample code has been provided.

    This lab is broken up into 4 individual modules with varying lengths. Use the "Modules"list to determine which use case(s) you want to complete. You may choose to completeany or all modules, keeping in mind that session time is limited.

    Modules do not depend on each other, so you can take them in any order. Use the "Tableof Contents" button in the menu bar for quick access to the module content.

    Module 1 - Datacenter automation for Python scripters (60 Minutes)

    You will learn how to write Python scripts to navigate and operate on a virtualdatacenter using pyvmomi (the Python SDK for vSphere API) and the vCloud Suite SDK.You will also learn how to use the Python interpreter and graphical debugger. There aremany samples for you to work with that cover a wide variety of datacenter automationuse cases, including the latest vSphere 6.0 features.

    Module 2 - Python Scripting vRealize Orchestrator Workflows with the RESTAPI (30 Minutes)

    You will learn how to write Python scripts to run vRealize Orchestrator Workflows via theREST API.

    Module 3 - Datacenter automation for Java programmers (60 Minutes)

    You will learn how to build Java applications to navigate and operate on a virtualdatacenter using Workbench IS, the vSphere Management SDK, and the vCloud SuiteSDK. You will also learn how to use the graphical debugger to step through code. Thereare many samples for you to work with that cover a wide variety of datacenterautomation use cases, including the latest vSphere 6.0 features.

    Module 4 - Workbench IS Tools (15 Minutes)

    This module is an introduction to tools included in Workbench IS including: RSE (RemoteSystem Explorer) - A tool to inspect and manage resources on a remote ESXi or vCentersystem.

    Lab Captain: Bob Fraser

    As you work through the modules, you may refer to the README.txt file on the Desktopfor help with International keyboards and for copying long strings of text.

    HOL-SDC-1622

    Page 3HOL-SDC-1622

  • This lab manual can be downloaded from the Hands-on Labs Document site found here:

    http://docs.hol.pub/catalog/

    HOL-SDC-1622

    Page 4HOL-SDC-1622

    http://docs.hol.pub/catalog/

  • Module 1 - Datacenterautomation for Pythonscripters (60 Minutes)

    HOL-SDC-1622

    Page 5HOL-SDC-1622

  • OverviewYou will learn how to write Python scripts to navigate and operate on a virtualdatacenter using pyvmomi (the Python SDK for vSphere API) and the vCloud Suite SDK.You will also learn how to use the Python interpreter and graphical debugger. There aremany samples for you to work with that cover a wide variety of datacenter automationuse cases, including the latest vSphere 6.0 features. This module is expected to take 60minutes.

    HOL-SDC-1622

    Page 6HOL-SDC-1622

  • Using PyDev and the pyvmomi SDKThis lesson shows you how to use Workbench IS and the PyDev plugin to run a samplescript and view the results. This also takes you through the code to understand how theSDK may be used to perform operations on the virtual infrastructure in a vSphere orvCenter environment.

    First you will run the sample script from the command line. Then you will debug thesample script using Workbench IS with the PyDev plugin and the Eclipse debugger.

    Run a pyvmomi sample

    The sample script can be run by double clicking run_getallvms.bat on the desktop.The image above shows an example run of the sample.

    Edit the sample

    1. Start Workbench IS by clicking on the Eclipse icon in the taskbar.2. Navigate to the PyDev perspective.3. Open the pyvmomi-community-samples project in the PyDev Package

    Explorer.4. Open getallvms.py by double clicking or the right click menu.

    HOL-SDC-1622

    Page 7HOL-SDC-1622

  • The image above shows the sample script. A more detailed explanation can be found inthe code comments.

    Debug the sample

    In this lesson you will learn how to debug a pyvmomi Python script.

    HOL-SDC-1622

    Page 8HOL-SDC-1622

  • Set a breakpoint

    In getallvms.py scroll down into the main function to line 96.

    At the line vm_folder = datacenter.vmFolder right click in the left margin to get thecontext menu as shown in the image above.

    Select Add Breakpoint

    Verify breakpoint

    You will know that the breakpoint is set when you see the green debug icon to the left ofthe line of code.

    Select Debug Configurations

    1. Press the triangle next to the debug icon2. select Debug Configurations ...

    HOL-SDC-1622

    Page 9HOL-SDC-1622

  • Debug

    Select Python Run >> getallvms.py

    The image above shows how the debug configuration is set up.

    Click on the Arguments tab and see the three program arguments:

    -s vcsa-01a.corp.local -u [email protected] -p VMware1!

    These arguments correspond to respectively.

    Click Debug to run the sample script in the Eclipse debugger.

    HOL-SDC-1622

    Page 10HOL-SDC-1622

  • Inspect the results

    The image above shows the Eclipse graphical debugger. Try:

    1. inspecting the datacenter variable by expanding the tree widget and clicking onelements.

    2. stepping through the code by clicking the Step Into or Step Over icons

    Explore other sample scripts

    The pyvmomi-community-samples project has many samples for a variety ofdatacenter automation use cases. Each file is an executable sample. To run, copy thegetallvms batch script, changing the python file and arguments or copy thegetallvms.py debug configuration and change the python file and arguments and run ordebug from Workbench IS.

    You may find the following samples interesting.

    vminfo_quick.py has an example of using property collectors for efficiently get all VMswith a common set of properties.

    HOL-SDC-1622

    Page 11HOL-SDC-1622

  • virtual_machine_power_cycle_and_question.py will select a VM by name, power itoff and power it back on. It optionally answers any VM questions on power on.

    HOL-SDC-1622

    Page 12HOL-SDC-1622

  • Inspecting the vCenter inventory fromthe Python interpreterOne of the benefits of the Python programming language is its interpretive nature andpowerful interactive shell. In this lesson you will learn how to use these tools to inspectthe vCenter hierarchy of objects (Datacenter, Host, VM, etc.).

    While you can always get to the Python interpreter by typing python in a terminalwindow, using a special purpose Python shell has advantages such as commandcompletion.

    The examples below will use the console shell that comes with PyDev.

    You may cut and paste helpful text from the README.txt file on the desktop.

    HOL-SDC-1622

    Page 13HOL-SDC-1622

  • Understanding the vCenter Inventory Hierarchy

    VMware vCenter allows you to manage physical and virtual infrastructure in adatacenter. The pyvmomi SDK provides Python bindings that allow you toprogrammatically manage the inventory of that same infrastructure.

    The inventory is managed as a collection of virtual datacenters. Each datacentercontains compute, data storage, and networking resources. Virtual machines and virtualapplications can be created in these datacenters that consume these resources. Folderscan be used to hierarchically group objects of the same type. The nested structureallows you to organize the objects in the datacenter into an easily manageablestructure. Possible reasons include aligning with various functions and/or organizationalstructure.

    The image above shows the hierarchy of objects in the vCenter inventory.

    For many pyvmomi applications, the flow of applications is similar. You connect to avCenter server, get a service instance, and starting with the root folder, navigate thehierarchy. You can then perform various operations on these managed objects.

    HOL-SDC-1622

    Page 14HOL-SDC-1622

  • Launching the PyDev console

    Navigate to the PyDev perspective and make sure a console is visible. If no console isvisible, you can launch one with menu Window >> Show View >> Console.

    In the console view:

    1. press the triangle next to the Open Console icon2. select PyDev Console

    HOL-SDC-1622

    Page 15HOL-SDC-1622

  • Configure the console

    1. Select Python console2. Press OK. If asked which interpreter to use, select pyvmomi.

    The Python interpreter shell will start. Double click the console tab to expand or restorethe console view.

    Initial setup and useful commands

    In the console type

    from pyVim import connect

    Nothing is returned but this loads parts of the pyvmomi library into the interpreter.

    Useful commands

    Use the up and down arrows to navigate the command history. Use or - for command completion.

    Try the import again as

    from pyVi import con

    help(connect)

    will print out module information.

    HOL-SDC-1622

    Page 16HOL-SDC-1622

  • Connect to vCenter

    Connect to vCenter and create a service instance:

    si = connect.SmartConnect(host='vcsa-01a.corp.local', user='[email protected]', pwd='VMware1!')

    If you see the warning:

    InsecureRequestWarning: Unverified HTTPS request is being made.

    You may safely ignore it.

    Two useful commands are type and dir.

    type(si)

    returns the type of the object. The output is:

    dir(si)

    will print the directory of the object, showing properties and methods.

    Navigate to a VM

    Type the following commands to get to a VM. Remember to use or - for command completion.

    Get the root folder:

    root = si.content.rootFolder

    Get the (first) datacenter:

    dc1 = root.childEntity[0]

    Make sure we really have a datacenter:

    type(dc1)

    returns:

    The type command is useful in the interpreter, but when writing scripts, there is aanother way to check types at runtime. First import the vim module:

    HOL-SDC-1622

    Page 17HOL-SDC-1622

  • from pyVmomi import vim

    This imports the vim and vmodl symbol tables and allows you to use shorter classnames.

    isinstance(dc1, vim.Datacenter) == True

    can now be used to ensure that we really have a datacenter object.

    Now get a list of VMs:

    vmList = dc1.vmFolder.childEntity

    Get the first VM

    vm = vmList[0]

    Verify the type.

    type(vm)

    type(vm) returns:

    Get the vm name:

    vm.name

    returns

    'linux-micro-02a'

    vm.summary

    will return a wealth of information about this VM, including runtime, configuration, andguest properties.

    Power on VM

    Now you will power on the VM.

    First check the power state of the VM:

    vm.runtime.powerState

    returns

    HOL-SDC-1622

    Page 18HOL-SDC-1622

  • 'poweredOff'

    Power on the VM with the following command:

    t = vm.PowerOn()

    Code completion can be used to quickly get you to relevant properties and functions.

    Type t = vm.p and wait for the pop up completion menu. If the menu doesn't appear,use -. Use the arrow key to select PowerOn().

    The image above shows how code completion works.

    Press twice to execute the power on command.

    A task is launched on the remote server.

    t.info

    returns status of the task.

    Specifically:

    t.info.state

    will return

    'success'

    when the PowerOn task has successfully completed on the server.

    Verify the state of the VM:

    vm.runtime.powerState

    returns

    'poweredOn'

    HOL-SDC-1622

    Page 19HOL-SDC-1622

  • HOL-SDC-1622

    Page 20HOL-SDC-1622

  • Python scripting with the vCloud SuiteSDK for PythonThis lesson illustrates Python scripting of new features introduced in vSphere 6.0(Content Catalog) and existing features which did not have a public API prior to thevSphere 6.0 release (Tagging).

    Run a vCloud Suite sample

    The sample can be run by double clicking run_tagging_workflow_python.bat on thedesktop. The sample demonstrations tagging CRUD operations. The image aboveshows an example run of the sample.

    Press any key to exit.

    What the script does

    1. Create a Tag category2. Create a Tag under the category3. Retrieve the managed object id of an existing cluster from its name4. Assign the tag to the cluster

    HOL-SDC-1622

    Page 21HOL-SDC-1622

  • 5. Detach the tag from the cluster6. Delete the tag7. Delete the tag category

    Edit the sample

    1. Start Workbench IS by clicking on the Eclipse icon in the taskbar.2. Navigate to the PyDev perspective.3. Open the vcloud-suite-python-client project in the PyDev Package Explorer by

    double clicking or the right click menu. Navigate to and open src >> com >>vmware >> vcloud >> suite >> sample >> workflow >>tagging_workflow.py.

    The image above shows the sample script. A more detailed explanation can be found inthe code comments.

    Explore other sample scripts

    The vcloud-suite-python-client project contains additional samples that use the vCloudSuite python client library (vapi_common_client-1.0.0) and vAPI runtime library(vapi_runtime-1.0.0). Additionally, some of the samples demonstrate the combined useof the vCloud Suite and vSphere APIs.

    HOL-SDC-1622

    Page 22HOL-SDC-1622

  • Open the Chrome browser and in the SDK Docs bookmarks folder you will find links tothe following documentation:

    1. VMware vCloud Suite Python SDK: client samples README - describing the SDKand samples

    2. VMware vCloud Suite Python SDK: Client API Reference

    The samples are organized into the following capabilities:

    • com.vmware.vcloud.suite.samples.vim.helpers - Samples and utilities foraccessing and manipulating VC objects using pyVmomi

    • com.vmware.vcloud.suite.samples.lookupservice - Service discoverysample using lookup service APIs

    • com.vmware.vcloud.suite.samples.workflow - Various vAPI work flowsamples

    • com.vmware.vcloud.suite.samples.inventory - Samples for inventory APIsfor retrieving information about vCenter datastore and network objects.

    HOL-SDC-1622

    Page 23HOL-SDC-1622

  • ConclusionYou now know how to write Python scripts to navigate and operate on a virtualdatacenter using pyvmomi (the Python SDK for vSphere API) and the vCloud Suite SDK,as well as how to use the Python interpreter and graphical debugger.

    You can find pyvmomi on github at:

    https://github.com/vmware/pyvmomi

    You can find sample code using pyvmomi for a variety of datacenter automation usecases at:

    http://vmware.github.io/pyvmomi-community-samples/

    Use the github issues feature to request a sample or to volunteer to contribute asample.

    You will find the vCloud Suite SDK for Python on Developer Center at:

    http://developercenter.vmware.com/sdks

    HOL-SDC-1622

    Page 24HOL-SDC-1622

    https://github.com/vmware/pyvmomihttp://vmware.github.io/pyvmomi-community-samples/http://developercenter.vmware.com/sdks

  • Module 2 - PythonScripting vRealize

    Orchestrator Workflowswith the REST API (30

    Minutes)

    HOL-SDC-1622

    Page 25HOL-SDC-1622

  • OverviewYou will learn how to write Python scripts to run vRealize Orchestrator Workflows via theREST API. This module is expected to take 30 minutes.

    HOL-SDC-1622

    Page 26HOL-SDC-1622

  • Python scripting of vRealizeOrchestrator WorkflowsThis lesson shows you how write a Python script to invoke vRealize Orchestratorworkflows and view the results.

    First you will run the sample script from the command line. Then you will edit and debugthe script using Workbench IS and PyDev.

    vRealize Orchestrator has a REST API that allows you to find and invoke OrchestratorWorkflows. While there is no formal Python client library, Python makes it easy to doREST programming with the Requests module. If you have Python, all you need to do isa 'pip install requests' and you have everything you need.

    Run a script to invoke a vRealize Orchestrator Workflow

    The sample script, that invokes a vRealize Orchestrator workflow, can be run by doubleclicking run_vro_workflow.bat on the desktop. The image above shows an examplerun of the sample. The workflow that runs is Define Namespace. It will add a newnamespace samplenamespace to the Dynamic Types hierarchy. Dynamic Types areuser defined types that can be used to model any object. The namespace is the root ofthe type hierarchy. You will not use the Dynamic Types, but this workflow provides aconvenient example.

    HOL-SDC-1622

    Page 27HOL-SDC-1622

  • Inspect the results with the vRealize Orchestrator Client

    Start the vRealize Orchestrator Client by clicking the logo in the taskbar.

    Login with the credentials: Host name: vro-01a.corp.local, User name:[email protected], Password: VMware1!

    1. Click the inventory tab2. Expand Dynamic Types3. You will see the new namespace samplenamespace4. You may close the Orchestrator client, if you wish, or click the Workflows tab

    and browse through the hundreds of workflows that come with vRealizeOrchestrator.

    Edit the script

    1. Start Workbench IS by clicking on the Eclipse icon in the taskbar.2. Navigate to the PyDev perspective.3. Open the pyvroworkflow project in the PyDev Package Explorer by double

    clicking or the right click menu.4. Open run_vro_workflow.py.

    HOL-SDC-1622

    Page 28HOL-SDC-1622

  • The image above shows the sample script. A more detailed explanation can be found inthe code comments.

    What the script does

    To invoke the workflow a URL is constructed:

    https://:8281/vco/api/workflows//executions

    workflowid identifies the workflow that will be run. You will see how to find that later inthe lesson. A HTTP POST request is made to the URL with the BODY content from thejson file that will be used as parameters to the workflow.

    If all goes well, you will receive a HTTP status of 202 (accepted). This means the requesthas been accepted and is processing asynchronously. The location header will containa URL that can be used to find out more about the workflow execution.

    More information about REST API for workflows and executions can be found in thedocumentation.

    HOL-SDC-1622

    Page 29HOL-SDC-1622

  • Documentation

    The documentation for the vRealize Orchestrator REST API can be found on the vRealizeOrchestrator appliance at the following URL:

    https://:8281/vco/api/docs/

    In the lab, there is a bookmark for this URL. Open the Chrome browser and in thebookmarks folder SDK Docs you will find the link to the vRealize Orchestrator APIdocumentation.

    Debug the script

    In this lesson you will learn how to debug the Python script.

    HOL-SDC-1622

    Page 30HOL-SDC-1622

  • Set a breakpoint

    In run_vro_workflow.py scroll down into the main function to line 99.

    At the line if r is None: right click in the left margin to get the context menu as shownin the image above.

    Select Add Breakpoint

    Verify breakpoint

    You will know that the breakpoint is set when you see the green debug icon to the left ofthe line of code.

    HOL-SDC-1622

    Page 31HOL-SDC-1622

  • Select Debug Configurations

    1. Press the triangle next to the debug icon2. Select Debug Configurations ...

    HOL-SDC-1622

    Page 32HOL-SDC-1622

  • Debug

    Select Python Run >> pyvroworkflow run_vro_workflow

    The image above shows how the debug configuration is set up.

    Click on the Arguments tab and see the three program arguments:

    -s vro-01a.corp.local -u [email protected] -p VMware1! -i5b8ff1c1-7f21-442a-956b-f28599ec422c -d define_namespace.json

    These arguments are used as command line arguments and are that same as those inrun_vro_workflow.bat

    Click Debug to run the sample script in the Eclipse debugger.

    HOL-SDC-1622

    Page 33HOL-SDC-1622

  • Inspect the results

    The image above shows the Eclipse graphical debugger. Try:

    1. inspecting r (the returned Response object) by expanding the tree widget andclicking on items.

    2. stepping through the code by clicking the Step Into or Step Over icons.

    Find a vRealize Orchestrator workflow by name

    In this lesson you will explore a Python script that finds a workflow by name via theREST API.

    HOL-SDC-1622

    Page 34HOL-SDC-1622

  • find_vro_workflow_by_name.py

    You can run the script by double clicking find_vro_workflow.bat on the desktop. Thescript will look for the workflow with the name define namespace and print out someinformation.

    In particular notice the id field. This is the workflow id and can be used in therun_vro_workflow.py script.

    What the script does

    To find the workflow a HTTP GET is done on the URL:

    https://:8281/vco/api/workflows/?conditions=name=

    The script then parses the return, constructing a Python dictionary, and loops throughthe keys printing out the values.

    Explore the script

    Now that you know how to use the PyDev editor and debugger you can:

    1. Look at the code2. Set a breakpoint and debug the code (a debug configuration

    find_vro_workflow_by_name has already been set up)

    HOL-SDC-1622

    Page 35HOL-SDC-1622

  • 3. Step through the code and inspect the results

    Inspecting the response, r , will help you understand the response object and what theJSON payload looks like.

    Write your own script (Optional)

    This is an optional lesson where you can try writing your own Python script. If youchoose not to include this lesson, you are done with this module.

    If you look at the output from find_vro_workflow_by_name you will see an attributeitemHref. In the vRealize Orchestrator REST API, itemHref is a direct URL to the objectyou are looking at. You can do a HTTP GET on this URL and find more information aboutthe workflow. You can also use this URL to invoke a workflow with an HTTP POST requestwith the parameters in JSON format in the BODY.

    Try the following:

    1. In the editor, make a copy of run_vro_workflow.py with the new namerun_vro_workflow_by_url.py

    2. Change the command line parsing to accept -l (for Location or urL) instead of -i(for id)

    3. In the function run_workflow construct the URL as follows: url = + 'extensions' This will end up producing the same URL as in run_vro_workflow

    4. Copy the .bat script or debug configuration from run_vro_workflow, substituting -l for -i

    5. Use the itemHref returned from find_vro_workflow_by_name

    You should now have a new script that can invoke a workflow by it's itemHref as well asthe original using workflowid.

    As you learn about and navigate the object hierarchy in the vRealize Orchestrator API,you will find it convenient to use Hrefs or URLs and using GET or POST to inspect oroperate on the objects. Many objects have attributes or arrays that are Hrefs.

    Combine the two scripts

    You now have everything you need to write run_vro_workflow_by_name

    Write a script to:

    1. Parse the arguments2. Do a HTTP GET as in find_vro_workflow_by_name to get the workflow3. If successful, get the item.Href and invoke the workflow with a HTTP POST as in

    run_vro_workflow_by_url

    If all goes well you should get a HTTP RESPONSE of Accepted (202).

    HOL-SDC-1622

    Page 36HOL-SDC-1622

  • ConclusionYou now know how to write Python scripts to run vRealize Orchestrator Workflows viathe REST API. You may download the VMware vRealize Orchestrator Appliance in thedownloads section on my.vmware.com:

    https://my.vmware.com/group/vmware/downloads#tab2 in the VMware vCloud Suite orVMware vSphere with Operations Management sections.

    You can get the sample code used in this lab on github at:

    https://github.com/burkeazbill/vroClientScripts

    You will find an active vRO community at:

    http://www.vcoteam.info/

    HOL-SDC-1622

    Page 37HOL-SDC-1622

    https://my.vmware.com/group/vmware/downloads#tab2https://github.com/burkeazbill/vroClientScriptshttp://www.vcoteam.info/

  • Module 3 - Datacenterautomation for Javaprogrammers (60

    Minutes)

    HOL-SDC-1622

    Page 38HOL-SDC-1622

  • OverviewYou will learn how to build Java applications to navigate and operate on a virtualdatacenter using Workbench IS, the vSphere Management SDK, and the vCloud SuiteSDK. You will also learn how to use the graphical debugger to step through code. Thereare many samples for you to work with that cover a wide variety of datacenterautomation use cases, including the latest vSphere 6.0 features. This module isexpected to take 60 minutes.

    HOL-SDC-1622

    Page 39HOL-SDC-1622

  • Using Workbench IS and the vSphereManagement SDKThis lesson shows you how to use Workbench IS to run a vSphere Management SDKsample and view the results. This also takes you through the code to understand howthe SDK may be used to perform operations on the virtual infrastructure. For moredetailed explanation refer to the SDK documentation athttp://developercenter.vmware.com>> SDKs >> vSphere Management SDK.

    First you will run a vSphere Management SDK sample application from the commandline via a batch script. Then you will debug the sample application using Workbench ISand the Eclipse debugger.

    Run a vSphere Management SDK sample

    The sample can be run by double clicking run_simple_client.bat on the desktop. Thesample will list the datacenter inventory of a vCenter Server. The first time the sample isrun, it may take up to 30 seconds to connect to the vCenter server. The image aboveshows an example run of the sample.

    Press any key to exit.

    HOL-SDC-1622

    Page 40HOL-SDC-1622

    http://developercenter.vmware.com>>

  • Edit the sample application

    1. Start Workbench IS by clicking on the Eclipse icon in the taskbar2. Navigate to the Java perspective.3. Open the vsphere-management-java-samples project in the Package Explorer.

    (Right click >> Open Project)4. Open src >> com.vmware.general >> SimpleClient.java.

    The image above shows the sample application. A more detailed explanation can befound in the code comments.

    Debug the sample application

    In this lesson you will learn how to use Workbench IS and the Eclipse debugger to debugthe sample application.

    HOL-SDC-1622

    Page 41HOL-SDC-1622

  • Set a breakpoint

    In SimpleClient.java scroll down into the getAndPrintInventoryContents functionto line 167.

    At the line ObjectContent oc = null; right click in the left margin to get the contextmenu as shown in the image above.

    Select Toggle Breakpoint

    Verify breakpoint

    You will know that the breakpoint is set when you see the green debug icon to the left ofthe line of code.

    HOL-SDC-1622

    Page 42HOL-SDC-1622

  • Select Debug Configurations

    Press the triangle next to the debug icon and select Debug Configurations ...

    HOL-SDC-1622

    Page 43HOL-SDC-1622

  • Debug

    Select Java Application >> SimpleClient.

    The image above shows how the debug configuration is set up. The Main class iscom.vmware.common.Main

    Click on the Arguments tab and see the classname of the sample that will run:

    com.vmware.general.SimpleClient

    To debug a different sample, duplicate this launch configuration and change theclassname in the Arguments tab.

    Click Debug to run the sample application in the Eclipse debugger.

    HOL-SDC-1622

    Page 44HOL-SDC-1622

  • Inspect the results

    The image above shows the Eclipse graphical debugger. Try:

    1. stepping through the code by clicking the Step Into or Step Over icons.2. inspecting the variables (e.g. oc), by expanding the tree widget and selecting

    items.

    Explore other sample applications

    The vsphere-management-java-samples project contains many samples coveringvarious aspects of the vSphere Management API.

    Open the chrome browser and in the SDK Docs bookmarks folder you will find links tothe following documentation:

    1. vSphere Management SDK Readme - describing the SDK and samples2. VMware vSphere API Reference

    You will find samples in the following categories:

    • general - Demonstrates basic capabilities of the vSphere API.• alarms - Demonstrates how to use alarms to monitor the vSphere environment.

    HOL-SDC-1622

    Page 45HOL-SDC-1622

  • • connection - How to establish a connection with a vCenter Server.• cim - Demonstrates how to use Common Information Model (CIM) in the vSphere

    environment.• events - How to use the event history collector.• guest - How to use the vSphere API to perform guest operations.• host - Host system and network configuration.• httpfileaccess - File operations using the HTTP protocol.• performance - How to retrieve performance data.• scheduling - How to schedule tasks.• scsilun - How to retrieve SCSI LUN identification data.• security - Username and password credential storage for automated application

    execution.• simpleagent - Support for automated login using local credential store.• storage - Storage DRS.• vapp - Using OVF Manager for import and export of virtual applications and

    virtual machine disk files.• vm - Virtual machine operations.

    HOL-SDC-1622

    Page 46HOL-SDC-1622

  • Workbench IS and the vCloud SuiteSDK for JavaThis lesson illustrates programmatic access to new features introduced in vSphere 6.0(Content Catalog) and existing features which did not have a public API prior to thevSphere 6.0 release (Tagging). This module also demonstrates how to interoperate withother vSphere APIs.

    Run a vCloud Suite sample

    The sample can be run by double clicking run_tagging_workflow_java.bat on thedesktop. The sample demonstrations tagging CRUD operations. The image aboveshows an example run of the sample.

    Press any key to exit.

    What the sample does

    1. Create a Tag category called “Asset”2. Create a Tag called “Server” under the category “Asset”3. Retrieve an existing Cluster using VIM APIs4. Translates the Cluster's MoRef into vAPI ID5. Assign “Server” tag to the Cluster using the ID

    HOL-SDC-1622

    Page 47HOL-SDC-1622

  • 6. Detach the tag from the Cluster7. Delete the tag “Server”8. Delete the tag category “Asset”

    Edit the sample

    1. Start Workbench IS by clicking on the Eclipse icon in the taskbar.2. Navigate to the Java perspective.3. Open the vcloud-suite-java-client project in the Package Explorer by double

    clicking or the right click menu.4. Open src >> com.vmware.vcloud.suite.samples.interop >>

    TaggingWorkflow.java.

    The image above shows the sample script. A more detailed explanation can be found inthe code comments.

    Explore other sample scripts

    The vcloud-suite-java-client project contains additional samples covering variousaspects of the vCloud Suite SDK and vSphere Management API.

    HOL-SDC-1622

    Page 48HOL-SDC-1622

  • Open the chrome browser and in the SDK Docs bookmarks folder you will find links tothe following documentation:

    1. VMware vCloud Suite SDK Java samples README - describing the SDK andsamples

    2. VMware vCloud Suite Java API Reference

    The samples are organized into the following capabilities:

    • com.vmware.vcloud.suite.samples.cis.tagging - Feature samples for cisTagging

    • com.vmware.vcloud.suite.samples.interop - Tagging/Content Library interopwith vSphere API's samples

    • com.vmware.vcloud.suite.samples.workflow - Various vAPI work flowsamples

    HOL-SDC-1622

    Page 49HOL-SDC-1622

  • ConclusionYou now know how to write Java applications to navigate and operate on a virtualdatacenter using vSphere Management SDK, and the vCloud Suite SDK, as well as howto use the graphical debugger.

    To find out more information or download Workbench IS, please visit VMware DeveloperCenter at:

    http://developercenter.vmware.com/tools>> Workbench IS.

    To find out more about the vSphere Management SDK, and the vCloud Suite SDK, pleasevisit:

    http://developercenter.vmware.com/sdks

    HOL-SDC-1622

    Page 50HOL-SDC-1622

    http://developercenter.vmware.com/toolshttp://developercenter.vmware.com/sdks

  • Module 4 - Workbench ISTools (15 Minutes)

    HOL-SDC-1622

    Page 51HOL-SDC-1622

  • OverviewThis module is an introduction to tools included in Workbench IS including: RSE (RemoteSystem Explorer) - A tool to inspect and manage resources on a remote ESXi or vCentersystem. This module is expected to take 15 minutes.

    HOL-SDC-1622

    Page 52HOL-SDC-1622

  • Using the Remote System Explorer(RSE)In this lesson you will use the Remote System Explorer to connect to an ESX host orvCenter server and explore the inventory of resources.

    Think of the Remote System Explorer as a mini vSphere Client (albeit with limitedfunctionality) embedded in the Eclipse IDE. This can be useful if you need to connect toan ESX host directly or prefer an experience, integrated with your developmentenvironment, for inspecting and manipulating the vCenter infrastructure. RSE is crossplatform and runs on Windows, Linux, and Mac OSX.

    Switch to the Remote System Explorer perspective

    Launch Eclipse by clicking the icon in the taskbar.

    Switch to the Remote System Explorer (RSE) perspective by clicking the icon on theupper right.

    HOL-SDC-1622

    Page 53HOL-SDC-1622

  • Connect to a vCenter server

    Right click in the Remote System panel and select New >> Connection …

    HOL-SDC-1622

    Page 54HOL-SDC-1622

  • Select the connection type

    Select Virtual Center for Linux and click Next

    HOL-SDC-1622

    Page 55HOL-SDC-1622

  • New Connection wizard

    In the New Connection wizard set the Host name to vcsa-01a.corp.local, the Username to [email protected], and the Password to VMware1! and click Finish.

    HOL-SDC-1622

    Page 56HOL-SDC-1622

  • Explore vCenter resources

    You will now see a new connection. Expand the hierarchy. You can see the inventory ofresources such as datacenters, clusters, and hosts, as well as a list of VMs.

    Click on a VM and, in the Properties panel, you will see a summary of properties for theVM such as memory, cpus, etc.

    HOL-SDC-1622

    Page 57HOL-SDC-1622

  • Connect to an ESX host

    Open the Remote System Explorer perspective.

    Right click in the Remote System panel and select New >> Connection …

    HOL-SDC-1622

    Page 58HOL-SDC-1622

  • Select the connection type

    Select ESX and click Next

    HOL-SDC-1622

    Page 59HOL-SDC-1622

  • New Connection wizard

    In the New Connection wizard set the Host name to esx-01a.corp.local, the User nameto root, and the Password to VMware1!

    Click Finish

    Explore ESX resources

    You will now see a new connection. Expand the hierarchy. You can see resources such asdatastores and network devices, as well as a list of VMs.

    Click on a VM and, in the Properties panel, you will see a summary of properties for theVM such as memory, cpus, etc.

    HOL-SDC-1622

    Page 60HOL-SDC-1622

  • You can directly act upon the remote file system in the File Explorer, copying or editingfile. You can launch ssh terminals from the Ssh Terminals section (use the right clickcontext menus).

    If you select and right click on objects in the invetory, such as a VM, you will see acontext menu of relevant operations (e.g. Power On VM).

    HOL-SDC-1622

    Page 61HOL-SDC-1622

  • ConclusionYou now know how to use Workbench IS and the Remote System Explorer (RSE) toinspect and manage resources on a remote ESXi or vCenter system.

    To find out more information or download Workbench IS, please visit VMware DeveloperCenter at:

    http://developercenter.vmware.com/tools>> Workbench IS.

    HOL-SDC-1622

    Page 62HOL-SDC-1622

    http://developercenter.vmware.com/tools

  • ConclusionThank you for participating in the VMware Hands-on Labs. Be sure to visithttp://hol.vmware.com/ to continue your lab experience online.

    Lab SKU: HOL-SDC-1622

    Version: 20151005-072644

    HOL-SDC-1622

    Page 63HOL-SDC-1622

    http://hol.vmware.com/

    Table of ContentsLab Overview - HOL-SDC-1622 - VMware Development Tools and SDKsLab Overview

    Module 1 - Datacenter automation for Python scripters (60 Minutes)OverviewUsing PyDev and the pyvmomi SDKRun a pyvmomi sampleEdit the sampleDebug the sampleSet a breakpointVerify breakpointSelect Debug ConfigurationsDebugInspect the resultsExplore other sample scripts

    Inspecting the vCenter inventory from the Python interpreterUnderstanding the vCenter Inventory HierarchyLaunching the PyDev consoleConfigure the consoleInitial setup and useful commandsConnect to vCenterNavigate to a VMPower on VM

    Python scripting with the vCloud Suite SDK for PythonRun a vCloud Suite sampleWhat the script doesEdit the sampleExplore other sample scripts

    Conclusion

    Module 2 - Python Scripting vRealize Orchestrator Workflows with the REST API (30 Minutes)OverviewPython scripting of vRealize Orchestrator WorkflowsRun a script to invoke a vRealize Orchestrator WorkflowInspect the results with the vRealize Orchestrator ClientEdit the scriptWhat the script doesDocumentationDebug the scriptSet a breakpointVerify breakpointSelect Debug ConfigurationsDebugInspect the resultsFind a vRealize Orchestrator workflow by namefind_vro_workflow_by_name.pyWhat the script doesExplore the scriptWrite your own script (Optional)Combine the two scripts

    Conclusion

    Module 3 - Datacenter automation for Java programmers (60 Minutes)OverviewUsing Workbench IS and the vSphere Management SDKRun a vSphere Management SDK sampleEdit the sample applicationDebug the sample applicationSet a breakpointVerify breakpointSelect Debug ConfigurationsDebugInspect the resultsExplore other sample applications

    Workbench IS and the vCloud Suite SDK for JavaRun a vCloud Suite sampleWhat the sample doesEdit the sampleExplore other sample scripts

    Conclusion

    Module 4 - Workbench IS Tools (15 Minutes)OverviewUsing the Remote System Explorer (RSE)Switch to the Remote System Explorer perspectiveConnect to a vCenter serverSelect the connection typeNew Connection wizardExplore vCenter resourcesConnect to an ESX hostSelect the connection typeNew Connection wizardExplore ESX resources

    ConclusionConclusion