Script to Configure vSphere Supervisor Cluster using REST APIs

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/HowLink/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
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 scriptGithub 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 runShown 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/specpayload
Python scriptcreate_namespace.py
How to runShown below
How it looks from UIShown 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. I encourage exploring vSphere automation SDKs here
5. vSphere with Kubernetes 101 is here
6. Official documentation for vSphere with Kubernetes is here

One thought on “Script to Configure vSphere Supervisor Cluster using REST APIs

  1. About register Proactive Provider (the form module doesn’t work, this is why I write here) with register_provider.py, I’ve got this error message:
    Traceback (most recent call last):
    File “register_provider.py”, line 31, in
    providerId = heath_update_mgr.RegisterHealthUpdateProvider(name,health_updates)
    File “/usr/local/lib/python3.7/site-packages/pyVmomi/VmomiSupport.py”, line 706, in
    self.f(*(self.args + (obj,) + args), **kwargs)
    File “/usr/local/lib/python3.7/site-packages/pyVmomi/VmomiSupport.py”, line 512, in _InvokeMethod
    return self._stub.InvokeMethod(self, info, args)
    File “/usr/local/lib/python3.7/site-packages/pyVmomi/SoapAdapter.py”, line 1397, in InvokeMethod
    raise obj # pylint: disable-msg=E0702
    pyVmomi.VmomiSupport.InvalidArgument: (vmodl.fault.InvalidArgument) {
    dynamicType = ,
    dynamicProperty = (vmodl.DynamicProperty) [],
    msg = ‘A specified parameter was not correct: providerId’,
    faultCause = ,
    faultMessage = (vmodl.LocalizableMessage) [
    (vmodl.LocalizableMessage) {
    dynamicType = ,
    dynamicProperty = (vmodl.DynamicProperty) [],
    key = ‘com.vmware.vim.healthUpdateManager.associatedEntity’,
    arg = (vmodl.KeyAnyValue) [
    (vmodl.KeyAnyValue) {
    dynamicType = ,
    dynamicProperty = (vmodl.DynamicProperty) [],
    key = ‘arg’,
    value = ‘ProHAProvider1’
    }
    ],
    message = ‘Entity ProHAProvider1 is already associated.’
    }
    ],
    invalidProperty = ‘providerId’
    }

Leave a Reply

Your email address will not be published. Required fields are marked *