Just following on from my previous article (HERE) on using Python Pyvmomi SDK wrapper for the vSphere Web Services API this time I show you how to iterate through the Web Services API tree. In numerous posts and VMUG sessions, I have given dating back to 2007 I have discussed that the objects in vSphere Web API are laid out in a hierarchical tree. Probably using the same relationship that objects have inside the vCenter Database. Here is the current diagram form the Vmware documentation. At the root of the tree, there is a folder; it contains the datacenter object. Underneath the Datacenter object is several other folders containing related objects. One for hosts, one for VMs, one for Networks and one for Storage.
The objective of this posts Python script is to move down the left-hand side of the tree list each object and finally getting to a list of VMs. The script below assumes you have to use the setup for authenticating to vSphere as in the previous script (HERE) and only contains the difference of what we are trying to achieve this time.
content = si.RetrieveContent() # now loop through any object that is tagged as "rooFolder" for child in content.rootFolder.childEntity: if hasattr(child, 'hostFolder'): datacenter = child # first object will be a datacentre hostFolder = datacenter.hostFolder # now assign the datacenter to a hostfolder variable cluster = hostFolder.childEntity # childs of hosts folders are clusters print("Datacenter name: " + child.name) # now loop through the clusters object for clusterList in cluster: print(clusterList.name) if hasattr(clusterList, 'host'): #if a child is tagged is host loop through the child for host in clusterList.host: print(host.name) for vm in host.vm: # host.vm holds a list of vm associated to that host print(" VM name: " + vm.name)
You can see from this code that we first find the folder tagged as rootfolder. This contains the datacenter object. Which in turn contains a hostfolder object which in turn contains a computer resource folder (the cluster). Which in turn contains the Host objects. This is where we stop. But hold on arent’t we suppose to list the VMs too? Well the VM objects are actually in a different folder. We observed that last time. However each host as a parameter called host.vm which is a list just of the name of each VM that is associated with that particular host.
Next time we will see how we can build to lists of objects and compare them so we cannot only list up the the VMs but list there properties too.
Security is a major concern for IT admins and if you’re responsible for important workloads hosted in Azure, you need to know your security is as tight as possible. In this free webinar, presented by Thomas Maurer, Senior Cloud Advocate on the Microsoft Azure Engineering Team, and Microsoft MVP Andy Syrewicze, you will learn how to use Azure Security Center to ensure your cloud environment is fully protected.
The webinar covers:
- Azure Security Center introductions
- Deployment and first steps
- Best practices
- Integration with other tools
- And more!
Being an Altaro-hosted webinar, expect this webinar to be packed full of actionable information presented via live demos so you can see the theory put into practice before your eyes. Also, Altaro put a heavy emphasis on interactivity, encouraging questions from attendees and using engaging polls to get instant feedback on the session. To ensure as many people as possible have this opportunity, Altaro present the webinar live twice so pick the best time for you and don’t be afraid to ask as many questions as you like!
There are certain topics in the IT administration world which are optional but security is not one of them. Ensuring your security knowledge if ahead of the curve is an absolute necessity and becoming increasingly important as we are all becoming exposed to more and more online threats every day. If you are responsible for important workloads hosted in Azure, this webinar is a must.
Webinar: Azure Security Center: How to Protect Your Datacenter with Next Generation Security
Date: Tuesday, 30th July
Time: Webinar presented live twice on the day. Choose your preferred time:
- 2pm CEST / 5am PDT / 8am EDT
- 7pm CEST / 10am PDT / 1pm EDT
Save your seat click >HERE<
Turbonomics is running a webinar for anyone interested in finding out about K8S (Kubernetes) . The Webinar is titled: Introduction to Kubernetes for Multicloud Scale. What to except from the session:
– What is Kubernetes
– Why Leading Organizations are Adopting it
– Key Problems Solved with Kubernetes
– Enterprise-ready Kubernetes-as-a-Service Offerings
Hey billy bonus if you register >HERE< you could win a $100 Amazon Voucher..