Python Example of Creating a Web Services Session

This example is based on code in the
service_manager.py
sample file.
This example uses the steps that are described in the Create a Web Services Session procedure.
This example uses the following global variables.
  • my_ws_url
  • my_sso_username
  • my_sso_password
The
my_ws_url
variable represents the URL of the
vCenter Server
Web Services API endpoint. You can retrieve the endpoint URL from the Lookup Service.
For a complete and up-to-date version of the sample code, see the
vsphere-automation-sdk-python
VMware repository at GitHub.
... # Extract the hostname from the endpoint URL. url_scheme, url_host, url_path, url_params, url_query, url_fragment = \ urlparse(my_ws_url) pattern = '(?P<host>[^:/ ]+).?(?P<port>[0-9]*)' match = re.search(pattern, url_host) host_name = match.group('host') # Invoke the SmartConnect() method by supplying # the host name, user name, and password. service_instance_stub = SmartConnect(host=host_name, user=my_sso_username, pwd=my_sso_password) # Retrieve the service content. service_content = service_instance_stub.RetrieveContent()