Last week I introduced you to vSphere Supervisor cluster APIs and also had a post on how to use DCLI for managing vSphere Supervisor cluster. In this post, I am going to show you how to enable/configure vSphere Supervisor cluster and also create namespace on the top of vSphere Supervisor cluster.
These key APIs are demonstrated using couple of python scripts. This time I thought let me try little different style of writing. I am sure you will enjoy learning.
1. Enable/configure vSphere Supervisor cluster :
What/Where/How | Link/Info |
Where to refer REST API documentation? | Official API documentation or H5C –> Developer Center –> API Explorer |
How do I land from VCF 4.0 on to vSphere for configuring this key workflow? | Refer this cool short video VCF 4.0 SDDC manager by Cormac |
How do I create base setup for labs, learning purpose? | Refer this cool deployment script by William |
My python script to configure Supervisor cluster on base setup | configure_supervisor_cluster.py script. Used python library “requests” to call APIs. We can use other “vSphere Automation SDKs” as well or Automating supervisor cluster workflows using Java SDK |
Enable vSphere Supervisor cluster API | POST https://{server}/api/vcenter/namespace-management/clusters/{cluster} ?action=enable |
Complete API Spec/payload for above POST call | API Spec |
Enable API Spec/Payload I passed in my script | Github link for spec you can use the same for postman call |
How did I fetched inputs needed to be passed into POST Call? | Refer line 139 through 178 in script |
Sample run | Shown below |
How it looks in UI before & after ? | Shown below |
How to run script :
C:\vThinkBeyondVM\vcpy>python configure_supervisor_cluster.py -s “10.x.x.x” -u “Administrator@vsphere.local” -cl “WCP-cluster-1” -mnw “VM Network” -sip “10.x.x.x” -sm “255.255.x.x” -gw “10.x.x.x” -dns “10.x.x.x” -ntp “10.x.x.x” -sp “k8s-gc-policy” -egress “10.x.x.x” -ingress “10.x.x.x”
Password will be asked on CLI. You might wonder, am I not passing VDS and Edge cluster? please refer the line 161 through 170. REST APIs allowed me to use some trick.
Which UI workflow is automated?
This python script automates below UI worklow, where user will configure workload network, management network, storage etc.
How it looks from UI
once Super visor cluster is enabled, this is how it looks (H5C > Menu > Workload Management)
2. Creating your first namespace using script
Create namespace URL | POST https://{server}/api/vcenter/namespaces/instances |
API payload/spec | payload |
Python script | create_namespace.py |
How to run | Shown below |
How it looks from UI | Shown below |
How to run script:
C:\vThinkBeyondVM\vcpy>python create_namespace.py -s 10.x.x.x -u Administrator@vsphere.local -cl WCP-cluster-1 -role EDIT -st USER -subject Administrator -domain vsphere.local -sp k8s-gc-policy -ns my-ns-2
How it looks from UI ?
I hope you enjoyed learning. Please stay tuned for upcoming posts around vSphere with K8s and other vSphere 7.0 functionality. Let me know if you have any queries, feedback.
Further reading:
1. REST API documentation
2. How to get vSphere with Kubernetes?
3. Introduction to manage vSphere Supervisor Cluster using API
4. Automating supervisor cluster workflows using Java SDK
5. vSphere with Kubernetes 101 is here
6. Official documentation for vSphere with Kubernetes is here
Vikas Shitole is a Staff engineer 2 at VMware (by Broadcom) India R&D. He currently contributes to core VMware products such as vSphere, VMware Private AI foundation and partly VCF . He is an AI and Kubernetes enthusiast. He is passionate about helping VMware customers & enjoys exploring automation opportunities around core VMware technologies. He has been a vExpert since last 11 years (2014-24) in row for his significant contributions to the VMware communities. He is author of 2 VMware flings & holds multiple technology certifications. He is one of the lead contributors to VMware API Sample Exchange with more than 35000+ downloads for his API scripts. He has been speaker at International conferences such as VMworld Europe, USA, Singapore & was designated VMworld 2018 blogger as well. He was the lead technical reviewer of the two books “vSphere design” and “VMware virtual SAN essentials” by packt publishing.
In addition, he is passionate cricketer, enjoys bicycle riding, learning about fitness/nutrition and one day aspire to be an Ironman 70.3
One thought on “Script to Configure vSphere Supervisor Cluster using REST APIs”
Comments are closed.