Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to vSphere APIs Using pyVmomi

17,837 views

Published on

Introduction to vSphere APIs Using pyVmomi

Slides to go along with the talk I gave at the SATX VMUG on 3-26-2015

Published in: Software
  • DOWNLOAD FULL BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Awesome
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Introduction to vSphere APIs Using pyVmomi

  1. 1. Introduction to vSphere APIs Using pyVmomi pyVmomi Michael Rice @VirtDevNinja http://errr-online.com/ https://github.com/michaelrice
  2. 2. About Michael Rice ❖ Software Developer @ Rackspace ❖ Trust me, I have a Linux beard. ❖ http://linuxbeard.com/image/114385301362 ❖ RPM Package Maintainer for pyVmomi ❖ Leading community contributor to pyVmomi & community- samples ❖ Creator of YAVIJAVA the VIJAVA fork ❖ StackOverflow pyVmomi & VIJAVA
  3. 3. About pyVmomi ❖ Open Source python SDK for vSphere ❖ Released Dec 2013 ❖ License: Apache 2.0 ❖ Python VMWare Managed Object Management Interface ❖ Other Vmomi projects include GoVmomi & rbVmomi ❖ Wraps vSphere WebServices SOAP API very tightly ❖ Its been around a long time!! Look on your 4.0 HostSystems! ❖ Multiple versions. Whats on HostSystems != whats on GitHub
  4. 4. Why Use Python & pyVmomi ❖ Python is easy for beginners to learn ❖ vSphere 6.0 VMWare released VMWare vCloud Suite SDK for Python ❖ http://developercenter.vmware.com/web/sdk/60/vcloudsuite-python ❖ Python is in the top 10 languages you should be learning RIGHT NOW! ❖ If you work in a mixed environment of admins running Windows, Mac and Linux then the same Python code works for everyone! (mostly) ❖ Integrate with ConfigManagement like Ansible & SaltStack ❖ pySphere and pSphere are much slower because they use SUDS ❖ pyVmomi is FAST! 360 milliseconds to inventory 576 VMs ❖ Do tasks you can normally only do from the UI — Reset Alarms from Red to Green
  5. 5. Setting Up a Development Environment ❖ Setup a Development vCenter using Simulator ❖ Install Python and VirtualEnv on our desktop ❖ Install Python IDE — pyCharm/IntelliJ, pyDev, etc.. ❖ No Intelli-Sense due to dynamic nature of library ❖ Install pyVmomi
  6. 6. Installing vCenter SA ❖ Download vCenter Server Appliance 5.5 ova ❖ 6.0 has a bug and Simulator DOES NOT WORK! ❖ Deploy the OVA to Fusion or Workstation ❖ Use simple shell script to configure VCSA Simulator ❖ https://gist.github.com/michaelrice/
  7. 7. #!/bin/bash # See the original work from William Lam at http://www.virtuallyghetto.com/ echo "Accepting EULA ..." /usr/sbin/vpxd_servicecfg eula accept echo "Setting default ports ..." /usr/sbin/vpxd_servicecfg 'ports' 'defaults' echo "Configuring Embedded DB ..." /usr/sbin/vpxd_servicecfg 'db' 'write' 'embedded' echo "Configuring SSO..." /usr/sbin/vpxd_servicecfg 'sso' 'write' 'embedded' 'password' echo "Starting VCSIM ..." /usr/bin/vmware-vcsim-start default echo "Starting VCSA ..." /usr/sbin/vpxd_servicecfg service start
  8. 8. Install Python & VirtualEnv ❖ Please See one of the 1000’s of guides online ❖ I use 2.7 but pyVmomi supports the following versions of Python: 2.6, 2.7, 3.3, 3.4 ❖ On Mac consider brew install of python
  9. 9. Install an IDE ❖ pyCharm/IntelliJ ❖ pyDev ❖ Other
  10. 10. Install pyVmomi ❖ Universal/Recommended ❖ pip install -U pyvmomi ❖ RHEL/Fedora/CentOS ❖ yum install pyvmomi ❖ FreeBSD ❖ pkg install pyvmomi
  11. 11. Not So Fast!!
  12. 12. vSphere Object Model ❖ Managed Objects ❖ HostSystem, VirtualMachine, Folder, Network, etc.. ❖ Managed Object Reference ❖ Used in MO to point to other associated managed objects ❖ Data Objects ❖ Information about a Managed Object. Properties of the MO
  13. 13. Object Diagram
  14. 14. Basic Usage with Actual Code!! >>> from pyVim.connect import SmartConnect >>> si = SmartConnect(host="vcsa", user="admin", pwd="password") >>> host = si.content.searchIndex.FindByDnsName(None, “DC0_C0_H0”, False) >>> print host.name DC0_C0_H0 >>> print host.summary.hardware.model ProLiant DL380 G5 3 Lines of Code to get a HostSystem!
  15. 15. List All HostSystems in vCenter service_instance = SmartConnect(User, Password, HostName) Hosts = GetAllHosts(service_instance) for host in Hosts: PrintHostInfo(host) def PrintHostInfo(host): # print various property info for a given host def GetAllHosts(service_instance): # do work needed to get host related info here…
  16. 16. Solving Business Problems ❖ SAN Team has a “Non Impacting No Downtime Maintenance” to do on the SAN Switches ❖ All customers have redundant connections ❖ Maint will require them to bring down A chan restore it then bring down B chan and restore it ❖ Such a low risk VirtSupport not informed only customer is notified. ❖ vCenter Alarms monitor the SAN connections ❖ They see redundancy lost & trigger SNMP trap. ❖ Ticket is generated for each device!! ❖ 30 mins later its 3am & 100’s of tickets have hit the queue fire drill begins!
  17. 17. Solving Business Problems ❖ Already had SOP in place for how to manually work the Redundancy lost tickets ❖ Use python to connect to various APIs in company to gather data from ticket to automate the SOP ❖ Use pyVmomi to connect vCenter to check for actual problem. ❖ Rescan HBA etc.. ❖ Use pyVmomi to ack alarm & reset from red to green ❖ Use python to hit ticket API to close ticket if fixed or flag as real issue for VirtSupport to go look at ❖ While this code was in production it worked 1000’s of tickets saving Rackers 100’s of hours in NVA work.
  18. 18. Valuable Tools ❖ Onyx ❖ https://labs.vmware.com/flings/onyx ❖ Latest Version: 2.2.5 ❖ Capture all traffic happening between client and server ❖ DoubleCloud Proxy ❖ Created by: Steve Jin ❖ http://www.doublecloud.org/doublecloud-proxy/ ❖ Capture all traffic happening between client and server
  19. 19. Onyx & DoubleCloud Proxy ❖ Start the app and point them at your target vSphere server ❖ Point your script or VIClient etc.. at proxy ❖ Profit
  20. 20. Things Ive Learned ❖ There are several “hidden” folders ❖ These can all be seen using the MOB ❖ HostSystems do not always have a unique UUID ❖ On Dell if Service Tag not set in BIOS it uses a generic default UUID ❖ When searching for them use the DNS Name or InventoryPath + name ❖ InventoryPath can be tricky. Use MOB for help ❖ Using the UUID will return the first one it finds ❖ http://kb.vmware.com/kb/1006250
  21. 21. Things Ive Learned ❖ VirtualMachine BIOS UUID is shared by VMS in a vApp ❖ The only thing unique for use in searching for a VM is the instance UUID so use it or the InventoryPath + name ❖ Property Collectors are complicated but worth the extra work ❖ You CAN NOT SCALE with out them!!
  22. 22. Must Have Links ❖ pyVmomi docs: https://github.com/vmware/pyvmomi/tree/master/docs ❖ community-samples: https://github.com/vmware/pyvmomi-community-samples/ ❖ ~30 samples and growing!! Contribute today!! ❖ Help us: https://github.com/vmware/pyvmomi-community- samples/labels/help%20wanted ❖ My Blog: http://www.errr-online.com/ ❖ VMWare developer resources: http://developercenter.vmware.com/sdks ❖ Shawn Hartsock: http://hartsock.blogspot.com/ ❖ VMWare employee currently maintaing pyVmomi ❖ youtube: https://www.youtube.com/playlist?list=PLO7- YtwexdVIttJejhsBjo0TZPq0BSFfw
  23. 23. Getting Help ❖ pyVmomi: https://github.com/vmware/pyvmomi ❖ IRC: Freenode —> #pyvmomi ❖ Mailing List: http://pyvmomi.2338814.n4.nabble.com/ ❖ StackOver Flow: tag post with pyvmomi

×