This example is based on code in the service_manager.py sample file. This file is located in the following vCloud Suite SDK for Python directory: client/samples/src/com/vmware/vcloud/suite/sample/common.
This example uses the steps that are described in the Create a Web Services Session procedure.
from urlparse import urlparse import re from pyVim.connect import SmartConnect from vmware.vapi.stdlib.client.factories import StubConfigurationFactory from vmware.vapi.security.session import create_session_security_context # Extract the host name from the endpoint URL. url_scheme, url_host, url_path, url_params, prl_query, url_fragment = urlparse(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_username, password=my_password) # Retrieve the service content. service_content = service_instance_stub.RetrieveContent