This document describes the samples that come bundled with the vSphere Automation SDK .NET.
The samples depend on the SDK .NET libraries
Samples PackagingThe samples sub-directory contains the samples solution which in turn contains a samples project with all the source files. The samples are organized by their functionalities into the following namespaces:
Samples Program StructureTo work with the VMware-supported deployment configurations of Platform Services Controllers (Single Sign-On) and vCenter Servers, applications need to dynamically discover service URLs to make service requests. Before making service requests, applications need to authenticate with the Single Sign-On service. Every sample performs the following basic tasks to connect to a service endpoint and initialize.
Each sample is an extension of this abstract class
The following is a code snippet from
/// <summary>
/// Connects to service endpoints.
/// </summary>
public void Connect()
{
ServiceManager = new ManagementNode(this);
ServiceManager.Connect(MgmtNodeName);
}
/// <summary>
/// Runs the sample. Each sample will provider its own implementation
/// for this method.
/// </summary>
public abstract void Run();
/// <summary>
/// Disconnects from service endpoints.
/// </summary>
public void Disconnect()
{
ServiceManager.Disconnect();
}
The public methods
Note that by default vSphere Automation SDK uses certificates signed by VMware Certificate Authority (VMCA). Because these certificates are not signed by an official root Certificate Authority (CA) that is trusted by your client, you must obtain the server root certificate from each server that you plan to target with your client application and install it locally. To enable certificate validation, follow these steps:
Running the SamplesTo run a sample, navigate toSamples\bin\Release directory and then:
ExamplesExample 1: Tag lifecycle sample successfully run.
C:\temp\sdk>VsphereAutomationSamples.exe TagLifecycle --ls-url https://192.0.2.0/lookupservice/sdk --sso-username administrator@vsphere.local --sso-password test
Samples Information: 0 : [PlatformServiceController] : Using infrastructure node: 192.0.2.0
Samples Verbose: 0 : [PlatformServiceController] : LS++ Connection (URL: https://192.0.2.0/lookupservice/sdk)
Samples Verbose: 0 : [PlatformServiceController] : SSO Connection (URL: https://sc-rdops-vm02-dhcp-33-10.eng.vmware.com/sts/STSService/vsphere.local, AssertionId: _badafa57-4324-4978-b278-63336d2b05c0(BEARER))
Samples Information: 0 : [ManagementNode] : Using management node: sc-rdops-vm02-dhcp-33-10.eng.vmware.com
Samples Verbose: 0 : [ManagementNode] : vAPI Connection (URL: https://sc-rdops-vm02-dhcp-33-10.eng.vmware.com:443/api, Authn Scheme: com.vmware.vapi.std.security.session_id)
Samples Verbose: 0 : [ManagementNode] : VIM Connection (URL: https://sc-rdops-vm02-dhcp-33-10.eng.vmware.com:443/sdk, SessionKey: 52985987-a4a4-e589-a448-e36f43ce771c)
Samples Verbose: 0 : [ServiceEndpoint`1] : Instantiating vAPI Service - Tag
Samples Verbose: 0 : [ServiceEndpoint`1] : Instantiating vAPI Service - Category
Samples Information: 0 : [TagLifecycle] : Created category 'Cat-P1xTr'
Samples Information: 0 : [TagLifecycle] : Created tag 'Tag-KwhVr'
Samples Information: 0 : [TagLifecycle] : Updated category description to 'Tag category updated at 11/18/2014 12:51:53 PM'
Samples Information: 0 : [TagLifecycle] : Updated tag description to 'Tag updated at 11/18/2014 12:51:54 PM'
Samples Information: 0 : [TagLifecycle] : Deleted tag 'Tag-KwhVr'
Samples Information: 0 : [TagLifecycle] : Deleted category 'Cat-P1xTr'
Samples Information: 0 : [VimConnection] : Logged out successfully.
Samples Information: 0 : [Application] : Finished running sample.
Example 2: Tag lifecycle sample run with missing required argument '--sso-password'.
C:\temp\sdk>VsphereAutomationSamples.exe TagLifecycle --ls-url https://192.0.2.0/lookupservice/sdk --sso-username administrator@vsphere.local
Usage: VsphereAutomationSamples.exe TagLifecycle [options]
--ls-url Required. Lookup service URL.
--mgmt-node-name Management node's instance name. Ex: IP/FQDN of the node.
--sso-username Required. SSO username.
--sso-password Required. SSO password.
--help Display this help screen.
|