Retrieving the Service Instance with the JSON Protocol

ServiceInstance
is a singleton managed object that acts as a gateway to the resources available on the server. You can locate other important singletons such as
SessionManager
and
SearchIndex
from
ServiceInstance
properties.
ServiceInstance
is accessible without authentication, so you can retrieve a reference to the
SessionManager
which you can use to authenticate a session.
You need the IP address or FQDN of a vCenter Server to which you will send the request.
To retrieve the properties of the
ServiceInstance
managed object, do the following.
  1. Synthesize a managed object reference to the
    ServiceInstance
    managed object. This managed object reference always has a fixed value of
    {type: "ServiceInstance", value: "ServiceInstance"}
    because it is a prerequisite for access to other managed object references.
    motype = 'ServiceInstance' moid = 'ServiceInstance' moref = motype + '/' + moid
  2. Specify the property to retrieve from the managed object.
    property = 'content'
  3. Assemble the URL from the pieces previously defined.
    scheme = 'https://' domain = 'vc.example.com' endpoint = '/sdk/vim25' version = '8.0.3' url = scheme + domain + endpoint + '/' + version + '/' + moref + '/' + property print(url)
    href="https://vc.example.com/sdk/vim25/8.0.3/ServiceInstance/ServiceInstance/content"
  4. Send the URL in an HTTP GET request.
    from urllib.request import urlopen, Request import ssl # Skip certificate verification on test systems only: unverified_context = ssl._create_unverified_context() request = Request( url, headers=headers or {} ) with urlopen( request, context=unverified_context ) as response : response_headers = response.headers response_body = response.read()
  5. Display the result of the query.
    from pprint import pprint json_body = json.loads(response_body) pprint(json_body)
The program displays a number of managed object references for singletons that you can use for additional requests. The following excerpt includes several important managed objects that you will use for basic operations, including authentication.
Excerpt from Service Content
... 'propertyCollector': {'_typeName': 'ManagedObjectReference', 'type': 'PropertyCollector', 'value': 'propertyCollector'}, 'rootFolder': {'_typeName': 'ManagedObjectReference', 'type': 'Folder', 'value': 'group-d1'}, 'scheduledTaskManager': {'_typeName': 'ManagedObjectReference', 'type': 'ScheduledTaskManager', 'value': 'ScheduledTaskManager'}, 'searchIndex': {'_typeName': 'ManagedObjectReference', 'type': 'SearchIndex', 'value': 'SearchIndex'}, 'serviceManager': {'_typeName': 'ManagedObjectReference', 'type': 'ServiceManager', 'value': 'ServiceMgr'}, 'sessionManager': {'_typeName': 'ManagedObjectReference', 'type': 'SessionManager', 'value': 'SessionManager'}, ...
Use the
SessionManager
URL in the Service Content to open an authenticated session with the vCenter Server instance.