The following code fragments establish connections both with the vCenter Server and the Storage Policy Server. These examples are based on the BasicConnection sample which is located in the Storage Policy SDK connection sample directory:The BasicConnection sample uses an instance of the LoginByTokenSample class. See vCenter LoginByToken Example. The LoginByToken example saves the HTTP cookie produced during the intial connection sequence and then restores the cookie after the vCenter Server connection has been established. Although the LoginByToken example creates a vCenter Server connection, the BasicConnection sample establishes its own connection with the vCenter Server. A different implementation might integrate those capabilities to reduce the number of vCenter Server connections.
1 Retrieve the VimPort interface. This provides access to the vSphere API methods.
3 Set the session cookie in the request context. The cookie (cookieVal) is obtained from the vCenter LoginByToken Example.
4 Call the RetrieveServiceContent method to establish the HTTP connection with the vCenter Server.Example: vCenter Server ConnectionThe following code fragment uses a vCenter session cookie to create a Storage Policy Server session.
1 Extract the actual cookie value from the name=value expression in the cookie string obtained from the vCenter session connection.
2 Create a PbmService object.
4 Retrieve the PbmPort object for access to the Storage Policy API methods.
6 Call the PbmRetrieveServiceContent method to establish the HTTP connection to the Storage Policy Server.Example: Storage Policy Server Connection