Vsphere Automation SDK 65 Net Programming Guide
Vsphere Automation SDK 65 Net Programming Guide
Vsphere Automation SDK 65 Net Programming Guide
EN-002090-00
VMware vSphere Automation SDK for .NET Programming Guide
You can find the most up-to-date technical documentation on the VMware Web site at:
http://www.vmware.com/support/
The VMware Web site also provides the latest product updates.
If you have comments about this documentation, submit your feedback to:
docfeedback@vmware.com
Copyright © 2015, 2016 VMware, Inc. All rights reserved. Copyright and trademark information.
VMware, Inc.
3401 Hillview Ave.
Palo Alto, CA 94304
www.vmware.com
2 VMware, Inc.
Contents
4 Authentication Mechanisms 25
Retrieve a SAML Token 26
.NET Example of Retrieving a SAML Token 26
Create a vSphere Automation Session with a SAML Token 27
.NET Example of Creating a vSphere Automation API Session with a SAML Token 27
Create a vSphere Automation Session with User Credentials 28
Create a Web Services Session 29
.NET Example of Creating a Web Services Session 29
VMware, Inc. 3
VMware vSphere Automation SDK for .NET Programming Guide
8 Tagging Service 57
Creating Tags 57
Creating a Tag Category 58
Creating a Tag 58
Creating Tag Associations 59
Assign the Tag to a Content Library 59
Assign a Tag to a Cluster 60
Updating a Tag 60
.NET Example of Updating a Tag Description 60
4 VMware, Inc.
Contents
Operating System 64
CPU and Memory 64
Networks 65
Performing Virtual Machine Power Operations 65
Java Example of Powering On a Virtual Machine 66
Index 67
VMware, Inc. 5
VMware vSphere Automation SDK for .NET Programming Guide
6 VMware, Inc.
About vSphere Automation SDK for .NET
Programming Guide
VMware vSphere Automation SDK for .NET Programming Guide describes how to use the
vSphere Automation SDK for .NET. VMware provides different APIs and SDKs for different applications
and goals. The vSphere Automation SDK for .NET supports the development of clients that use the
vSphere Automation SDK for infrastructure support tasks .
Intended Audience
This information is intended for anyone who will develop applications by using the
vSphere Automation SDK for .NET. Some programming background in C# and .NET is required.
VMware, Inc. 7
VMware vSphere Automation SDK for .NET Programming Guide
8 VMware, Inc.
Introduction to the
vSphere Automation SDKs 1
The vSphere Automation SDKs bundle client libraries for accessing new vSphere Automation features like
Content Library and existing features like Tagging. The vSphere Automation SDKs contain sample
applications and API reference documentation for the Content Library and Tagging services. The
vSphere Automation SDKs also provide sample code that retrieves the endpoints of vSphere Automation
and vSphere services and establishes a secure connection with the vSphere Automation endpoint.
vSphere Automation supports six languages for accessing the vSphere Automation API services and
provides six SDKs for developing client applications for managing components in your virtual environment.
vSphere Automation API client applications communicate with services on the Platform Services Controller
and vCenter Server.
VMware, Inc. 9
VMware vSphere Automation SDK for .NET Programming Guide
Content Тagging
Library Service
vSphere Automation API client applications use the Lookup Service to retrieve the vCenter Single Sign-On
endpoint, the vSphere Automation Endpoint, and the endpoints of services that are exposed through the
vSphere API. To access vSphere Automation services such as Content Library and Tagging, client
applications issue requests to the vSphere Automation Endpoint. By using the vCenter Single Sign-On
service, client applications can either establish an authenticated vSphere Automation session, or
authenticate individual requests to the vSphere Automation Endpoint.
Client applications can access services that are exposed through the vSphere API by using the vSphere
Management SDK.
Depending on the vSphere deployment model, client applications can communicate with
vSphere Automation services on a single vCenter Server instance or multiple vCenter Server instances. For
more information about the vSphere deployment models, see Chapter 2, “Components of the vSphere
Automation Virtualization Layer,” on page 13
SDK Samples
The vSphere Automation SDKs provide sample applications that you can extend to implement client
applications that serve your needs. The code examples in the vSphere Automation SDKs documentation are
based on these sample applications.
10 VMware, Inc.
Chapter 1 Introduction to the vSphere Automation SDKs
VMware, Inc. 11
VMware vSphere Automation SDK for .NET Programming Guide
12 VMware, Inc.
Components of the
vSphere Automation Virtualization
Layer 2
At the core of vSphere Automation is vSphere, which provides the virtualization layer of the software-
defined data center. You can use vSphere deployment options for vCenter Server and ESXi hosts to build
virtual environments of different scales.
In vSphere Automation API client applications, you use the vCenter Single Sign-On and the Lookup Service
on the Platform Services Controller to provide a range of functionality.
Authentication and You use the vCenter Single Sign-On service to establish an authenticated
Session Management session with the vSphere Automation Endpoint. You send credentials to the
vCenter Single Sign-On service and receive a SAML token that you use to
obtain a session ID from the vSphere Automation Endpoint. Alternatively,
you can access the vSphere Automation APIs in a sessionless manner by
including the SAML token in every request that you issue to the
vSphere Automation Endpoint.
Service Discovery You use the Lookup Service to discover the endpoint URL for the vCenter
Single Sign-On service on the Platform Services Controller, the location of the
vCenter Server instances, and the vSphere Automation Endpoint.
VMware, Inc. 13
VMware vSphere Automation SDK for .NET Programming Guide
vCenter Server also provides services that you can access through the vSphere Automation Endpoint.
Content Library Service You can use the Content Library Service to share VM templates, vApp
templates, and other files across the software-defined data center. You can
create, share, and subscribe to content libraries on the same vCenter Server
instance or on a remote instance. This promotes consistency, compliance,
efficiency, and automation in deploying workloads at scale. By using content
libraries, you can also create OVF packages from virtual machines and
virtual appliances in hosts, resource pools, and clusters. You can then use the
OVF packages to provision new virtual machines in hosts, resource pools,
and clusters.
Tagging Service This service supports the definition of tags that you can associate with
vSphere objects or vSphere Automation resources. The vSphere Automation
SDKs provide the capability to manage tags programmatically.
You can use the Platform Services Controller in two ways to establish secure, authenticated sessions for your
client application, by making requests to the Lookup Service and the vCenter Single Sign-On Service.
One way to use the Platform Services Controller is to request an authentication token that can be used to
authenticate requests across services. The client connects to the Lookup Service and retrieves the vCenter
Single Sign-On Service endpoint and the vSphere Automation API endpoint. The client then uses the
vCenter Single Sign-On endpoint to authenticate with user credentials and receive a token that securely
verifies the client's credentials. This allows the client to authenticate with a number of service endpoints
without sending user credentials over the network repeatedly.
Alternatively, if the client connects directly to the vSphere Automation API endpoint, there is no need for
the client to interact with the vCenter Single Sign-On Service. The client sends user credentials to the
vSphere Automation API endpoint, which creates a session identifier that persists across requests.
14 VMware, Inc.
Chapter 2 Components of the vSphere Automation Virtualization Layer
VM or Physical Server
Single Sign-On
Service URL
Lookup vCloud Suite
Service Endpoint URL
vCenter Server
URL
Other Services
URLs
Single
Sign-ON SAML Token
Service
VM
VMware ESXi
vCenter Server
Content Library
Service
vAAPI
Endpoint Тagging
Service VM
Other Services
VMware ESXi
A client application functions in a similar way as in a Platform Services Controller with embedded
vCenter Server deployment. The only difference is that the client application can access services on multiple
vCenter Server instances, or services only on a particular vCenter Server instance.
VMware, Inc. 15
VMware vSphere Automation SDK for .NET Programming Guide
VM or Physical Server
Single Sign-On
Service URL
Lookup vCloud Suite
Service Endpoint URL
vCenter Server
URL
Other Services
URLs
Single
Sign-ON SAML Token
Service
VM VM VM VM
16 VMware, Inc.
Retrieving Service Endpoints 3
To access services and resources in the virtual environment, vSphere Automation API client applications
must know the endpoints of vSphere Automation and vSphere services. Client applications retrieve service
endpoints from the Lookup Service that runs on the Platform Services Controller.
The Lookup Service provides service registration and discovery by using a Web services API. By using the
Lookup Service, you can retrieve endpoints of services on the Platform Services Controller and
vCenter Server. The following endpoints are available from the Lookup Service.
n The vCenter Single Sign-On endpoint on the Platform Services Controller. You use the vCenter Single
Sign-On service to get a SAML token and establish an authenticated session with a vSphere Automation
endpoint or a vCenter Server endpoint.
n The vSphere Automation Endpoint on vCenter Server. Through the vSphere Automation Endpoint, you
can make requests to vSphere Automation API services such as virtual machine management, Content
Library, and Tagging.
n The vCenter Server endpoint. In an environment with external Platform Services Controller instances,
you can use the vCenter Server endpoint to get the node ID of a particular vCenter Server instance. By
using the node ID , you can retrieve service endpoints on that vCenter Server instance.
n The vSphere API endpoint and endpoints of other vSphere services that run on vCenter Server.
1 Connect to the Lookup Service on the Platform Services Controller and service registration object so
that you can query for registered services.
2 Create a service registration filter for the endpoints that you want to retrieve.
3 Use the filter to retrieve registration information for services from the Lookup Service.
4 Extract one or more endpoint URLs from the array of registration information that you receive from the
Lookup Service.
n “Connect to the Lookup Service and Retrieve the Service Registration Object,” on page 19
VMware, Inc. 17
VMware vSphere Automation SDK for .NET Programming Guide
Optionally, you can include the node ID parameter in the filter to identify the vCenter Server instance where
the endpoint is hosted. When the node ID is omitted, the List() function returns the set of endpoint URLs
for all instances of the service that are hosted on different vCenter Server instances in the environment.
For example, a LookupServiceRegistrationFilter for queering the vSphere Automation service has these
service endpoint elements.
For information about the filter parameter of the available predefined service endpoints, see “Filter
Parameters for Predefined Service Endpoints,” on page 18.
Table 3‑2. Input Data for URL Retrieval for the Lookup Service Registration Filter
Service Input Data Value
18 VMware, Inc.
Chapter 3 Retrieving Service Endpoints
Table 3‑2. Input Data for URL Retrieval for the Lookup Service Registration Filter (Continued)
Service Input Data Value
protocol vapi.json.https.public
endpoint type com.vmware.vapi.endpoint
vCenter Server product namespace com.vmware.cis
service type vcenterserver
protocol vmomi
endpoint type com.vmware.vim
vCenter Storage Monitoring product namespace com.vmware.vim.sms
Service
service type sms
protocol https
endpoint type com.vmware.vim.sms
vCenter Storage Policy-Based product namespace com.vmware.vim.sms
Management
service type sms
protocol https
endpoint type com.vmware.vim.pbm
vSphere ESX Agent Manager product namespace com.vmware.vim.sms
service type cs.eam
protocol vmomi
endpoint type com.vmware.cis.cs.eam.sdk
Procedure
1 Connect to the Lookup Service.
a Configure a connection stub for the Lookup Service endpoint, which uses SOAP bindings, by using
the HTTPS protocol.
With the service registration object, you can make registration queries.
VMware, Inc. 19
VMware vSphere Automation SDK for .NET Programming Guide
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using vmware.lookupservice;
Prerequisites
n Establish a connection with the Lookup Service.
Procedure
1 Create a registration filter object, which contains the following parts:
20 VMware, Inc.
Chapter 3 Retrieving Service Endpoints
Option Description
Omit the node ID parameter Retrieves the endpoint URLs of the service on all vCenter Server instances.
Include the node ID parameter Retrieves the endpoint URL of the service on a particular vCenter Server
instance.
Depending on whether you included the node ID parameter, the List() function returns one of the
following results:
n A list of endpoint URLs for a service that is hosted on all vCenter Server instances in the environment.
What to do next
Call the function that you implemented to retrieve service endpoints. You can pass different filter
parameters depending on the service endpoints that you need. For more information, see “Filter Parameters
for Predefined Service Endpoints,” on page 18.
To retrieve a service endpoint on a particular vCenter Server instance, you must retrieve the node ID of that
instance and pass it to the function. For information about how to retrieve the ID of a vCenter Server
instance, see “Retrieve a vCenter Server ID by Using the Lookup Service,” on page 22.
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using vmware.lookupservice;
VMware, Inc. 21
VMware vSphere Automation SDK for .NET Programming Guide
Managed services are registered with the instance name of the vCenter Server instance where they run. The
instance name maps to a unique vCenter Server ID. The instance name of a vCenter Server system is
specified during installation and might be an FQDN or an IP address.
Prerequisites
n Establish a connection with the Lookup Service.
Procedure
1 List the vCenter Server instances.
2 Find the matching node name of the vCenter Server instance and save the ID.
Use the node ID of the vCenter Server instance to filter subsequent endpoint requests. You can use the node
ID in a function that retrieves the endpoint URL of a service on a vCenter Server instance. For information
about implementing such a function, see “Retrieve Service Endpoints on vCenter Server Instances,” on
page 20.
using System;
using System.Linq;
using vmware.vapi.util.security;
22 VMware, Inc.
Chapter 3 Retrieving Service Endpoints
{
return service.nodeId;
}
}
}
}
Prerequisites
n Establish a connection with the Lookup Service.
n Determine the node ID of the vCenter Server instance where the vSphere Automation service runs.
n Implement a function that retrieves the endpoint URL of a service on a vCenter Server instance.
Procedure
1 Invoke the function for retrieving the endpoint URL of a service on a vCenter Server instance by
passing filter strings that are specific to the vSphere Automation endpoint.
targetNodeId = getMgmtNodeId(target_node_fqdn)
var serviceInfo = LookupSingleServiceUrl("com.vmware.cis",
"cs.vapi",
"vapi.json.https",
"com.vmware.vapi.endpoint",
targetNodeId);
var vapiUrl = serviceInfo[0].serviceEndpoints[0].url;
VMware, Inc. 23
VMware vSphere Automation SDK for .NET Programming Guide
24 VMware, Inc.
Authentication Mechanisms 4
To perform operations on services in the vSphere environment, you must create an authenticated connection
to the services that you want to use. With the vSphere Automation SDK for .NET you can authenticate and
access vSphere Automation services.
Client applications can choose from two supported authentication patterns for accessing services in the
virtual environment.
For better security, client applications can request a security token to authenticate connections with the
vSphere Automation services.
To invoke operations on services, client applications must create a security context. The security context
represents the client authentication. You can achieve authentication by using one of the following
mechanisms.
Password-Based To authenticate with user name and password, you connect to the
Authentication vSphere Automation Endpoint with vCenter Single Sign-On user credentials
and obtain a session identifier (ID). The user account credentials are
validated by the vSphere Automation Endpoint, and must be present in the
vCenter Single Sign-On identity store. The session ID is valid only for the
service endpoint that you want to access and that issues the session ID.
Token-Based Client applications can authenticate by using the vCenter Single Sign-On
Authentication component on thePlatform Services Controller. vCenter Single Sign-On
includes the Security Token Service (STS) that issues security tokens. The
token must comply with the Security Assertion Markup Language (SAML)
specification, which defines an XML-based encoding for communicating
authentication data.
vCenter Single Sign-On supports two types of security tokens: bearer token
and Holder-of-Key (HoK) token. To acquire a SAML token, client
applications must issue a token request to vCenter Single Sign-On.
To retrieve a session ID for the vSphere Web Services endpoint, you provide
the SAML token to the vSphere Web services endpoint. For more information
about creating an authenticated session to access the vSphere Web Services,
see the vSphere Web Services SDK Programming Guide documentation.
VMware, Inc. 25
VMware vSphere Automation SDK for .NET Programming Guide
Client applications use the vCenter Single Sign-On service to retrieve SAML tokens. For more information
about how to acquire a SAML security token, see the vCenter Single Sign-On Programming Guide
documentation.
The vSphere Automation SDK for .NET provides the SsoConnection utility class. The utility creates a
connection with the vCenter Single Sign-On service and acquires a SAML token. The security token is
required for securing the communication between the client application and the services running in your
virtual environment. The source file of the utility is in the vSphere Automation SDK for .NET directory:
client/samples/src/Samples/vmware/vcloud/suite/samples/common/SsoConnection.cs.
Prerequisites
Verify that you have the vCenter Single Sign-On URL. You can use the Lookup Service on the
Platform Services Controller to obtain the endpoint URL. For information about retrieving service
endpoints, see Chapter 3, “Retrieving Service Endpoints,” on page 17.
Procedure
1 Create a connection object to communicate with the vCenter Single Sign-On service.
Pass the vCenter Single Sign-On endpoint URL, which you can get from the Lookup Service.
2 Issue a security token request by sending valid user credentials to the vCenter Single Sign-On service
on the Platform Services Controller.
What to do next
You can present the SAML token to the vSphere Automation API Endpoint or other endpoints, such as the
vSphere Web Services Endpoint. The endpoint returns a session ID and establishes a persistent session with
that endpoint. Each endpoint that you connect to uses your SAML token to create its own session.
using System;
using System.Linq;
using vmware.vapi.util.security;
// Create a connection object to communicate with the vCenter Single Sign-On service.
var ssoUrl = FindSsoUrl();
26 VMware, Inc.
Chapter 4 Authentication Mechanisms
Prerequisites
n Retrieve the vSphere Automation Endpoint URL from the Lookup Service.
Procedure
1 Create a connection by specifying the vSphere Automation API Endpoint URL and the message
protocol to be used for the connection.
Note To transmit your requests securely, use https for the vSphere Automation API Endpoint URL.
2 Create the request options or stub configuration and set the security context to be used.
The security context object contains the SAML token retrieved from the vCenter Single Sign-On service.
Optionally, the security context might contain the private key of the client application.
3 Create an interface stub or a REST path that uses the stub configuration instance.
The interface stub corresponds to the interface containing the method to be invoked.
The service creates an authenticated session and returns a session identification cookie to the client.
6 Update the stub configuration instance with the session security context.
What to do next
Use the updated stub configuration with the session ID to create a stub for the interface that you want to
use. Method calls on the new stub use the session ID to authenticate.
using System;
using System.Security.Cryptography;
using vmware.vapi.bindings;
using vmware.vapi.dsig;
using vmware.vapi.protocol;
using vmware.vapi.security;
VMware, Inc. 27
VMware vSphere Automation SDK for .NET Programming Guide
CspParameters());
myStubFactory = new StubFactory(protocolConnection.GetApiProvider());
// 5 - Use the session ID to replace the SAML token for the vSphere
Automation API session.
myStubConfiguration = new StubConfiguration();
myStubConfiguration.SetSecurityContext(new SessionSecurityContext(sessionId));
mySession = myStubFactory.CreateStub<Session>(myStubConfiguration);
You connect to the vSphere Automation Endpoint by using a user name and password known to the
vCenter Single Sign-On service. The vSphere Automation uses your credentials to authenticate with the
vCenter Single Sign-On Service and obtain a SAML token.
Prerequisites
n Retrieve the vSphere Automation Endpoint URL from the Lookup Service.
n Verify that you have valid user credentials for the vCenter Single Sign-On identity store.
Procedure
1 Create a connection stub by specifying the vSphere Automation Endpoint URL and the message
protocol to be used for the connection.
2 Create a stub configuration instance and set the specific security context to be used.
The security context object uses the user name and password that are used for authenticating to the
vCenter Single Sign-On service.
4 Call the create operation on the Session stub to create an authenticated session to the
vSphere Automation Endpoint.
6 Update the stub configuration instance with the session security context.
28 VMware, Inc.
Chapter 4 Authentication Mechanisms
What to do next
You can use the authenticated session to access vSphere Automation services. For more information about
creating stubs to the vSphere Automation services, see Chapter 5, “Accessing vSphere Automation
Services,” on page 31.
The vSphere Web Services API also supports session-based access. To establish an authenticated session, you
can send the SAML token retrieved from the vCenter Single Sign-On service to a vSphere Web Service. In
return you receive a session identifier that you can use to access the service. For more information about
accessing Web Services, see the vSphere Web Services SDK Programming Guide documentation.
Prerequisites
n Retrieve the vSphere Web Services endpoint URL from the Lookup Service.
Procedure
1 Connect to the vSphere Web Services endpoint.
2 Send the SAML token to a specific Web service to create an authenticated session.
The Service Content object gives you access to several server-side managed objects that represent
vSphere services and components.
using System;
using System.IdentityModel.Tokens;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using vmware.vim25;
VMware, Inc. 29
VMware vSphere Automation SDK for .NET Programming Guide
30 VMware, Inc.
Accessing vSphere Automation
Services 5
vSphere Automation SDK provides mechanisms for creating remote stubs to give clients access to
vSphere Automation services.
The sequence of tasks you must follow to create a remote stub starts with creating a ProtocolFactory. You
use the protocol factory object to create a ProtocolConnection. Connection objects provide the basis for
creating stub interfaces tovSphere Automation services.
When you establish a connection to the vSphere Automation Endpoint, you can create a StubFactory object
and a StubConfiguration object. With these objects, you can create the remote stub for the
vSphere Automation service that you want to access.
The complete connection sequence also includes SSL truststore support and a temporary StubConfiguration
that you use for SAML token authentication and session creation.
Prerequisites
Establish a connection to the vSphere Automation Endpoint URL. For more information about the
authentication mechanisms that you can use, see Chapter 4, “Authentication Mechanisms,” on page 25.
Procedure
1 Create a protocol factory object.
The vSphere Automation API clients use ApiProvider instances to invoke operations on services
running in the virtual environment. To invoke an operation, you must specify the target service and
operation, input parameters, and execution context.
4 Create a StubConfiguration instance and set the security context to be used for the service stub.
VMware, Inc. 31
VMware vSphere Automation SDK for .NET Programming Guide
5 Create the stub for the vSphere Automation service interface by calling the create method of the
StubFactory instance. Pass the service class and the StubConfiguration instance as arguments.
32 VMware, Inc.
Content Library Service 6
The Content Library Service provides means for managing content libraries in the context of a single or
multiple vCenter Server instances deployed in your virtual environment. You can use the
vSphere Automation APIs to access the Content Library Service through the vSphere Automation Endpoint.
Administrators can use content libraries to share VM templates, vApp templates, and other types of files
across vCenter Server instances in the virtual environment. Sharing templates across your virtual
environment promotes consistency, compliance, efficiency, and automation in deploying workloads at scale.
VMware, Inc. 33
VMware vSphere Automation SDK for .NET Programming Guide
n You can create a local library as the source for content you want to save or share. Create the local library
on a single vCenter Server instance. You can add items to a local library or remove them. You can
publish a local library and as a result this content library service endpoint can be accessed by other
vCenter Server instances in your virtual environment. When you publish a library, you can configure
the authentication method, which a subscribed library must use to authenticate to it.
n You can create a subscribed library and populate its content by synchronizing to a local library. A
subscribed library contains copies of the local library files or just the metadata of the library items. The
local library can be located on the same vCenter Server instance as the subscribed library, or the
subscribed library can reference a local library on a different vCenter Server instance. You cannot add
library items to a subscribed library. You can only add items to the source library. After synchronization,
both libraries will contain the same items.
For information about the tasks that you can perform by using the content library service, see “Content
Libraries,” on page 36.
Depending on the type of storage that you have, you can use Virtual Machine File System (VMFS) or
Network File System (NFS) for storing content on a datastore.
For storing content on a remote file system, you can enter the path to the NFS storage that is mounted on the
Linux file system of the vCenter Server Appliance. For example, you can use the following URI formats:
nfs://<server>/<path>?version=4 and nfs://<server>/<path>. If you have a vCenter Server instance that
runs on a Windows machine, you can specify the Server Massage Block (SMB) URI to the Windows shared
folders that store the library content. For example, you can use the following URI format: smb://<unc-
server>/<path>.
...
using vmware.content;
using vmware.content.library;
34 VMware, Inc.
Chapter 6 Content Library Service
You can use the list function to retrieve all local and subscribed libraries in your system.
...
// Create a vSphere
Automation session (not shown).
VMware, Inc. 35
VMware vSphere Automation SDK for .NET Programming Guide
If you want to retrieve only a list of the local libraries, you must retrieve the LocalLibrary service and use
the list function on the LocalLibrary service. To list only subscribed libraries, you must retrieve the
SubscribedLibrary service and call the list function on the SubscribedLibrary service.
Prerequisites
Verify that you have access to the Library service.
Procedure
1 Create a FindSpec instance and specify your search criteria.
.NET Example of Retrieving a List of All Local Libraries with a Specific Name
This example retrieves a list of all local libraries with the name AcmeLibrary that exist in your virtual
environment.
...
using vmware.content;
findSpec.SetName("AcmeLibrary");
findSpec.SetType(vmware.content.LibraryModel.LibraryType.LOCAL)
List<String> libIds = libraryService.Find(findSpec);
Content Libraries
The Content Library API provides services that allow you to create and manage content libraries
programmatically. You can create a local library and publish it for the entire virtual environment. You can
also subscribe to use the contents of a local library and enable automatic synchronization to ensure that you
have the latest content.
36 VMware, Inc.
Chapter 6 Content Library Service
Procedure
1 Create a StorageBacking instance and define the storage location.
2 Create a LibraryModel instance and set the properties of the new local library.
3 Access the LocalLibrary object which is part of the vSphere Automation API service interfaces.
4 Call the create function on the LocalLibrary object and pass the LibraryModel as a parameter.
...
using vmware.content;
using vmware.content.library;
// Create a StorageBacking instance to back the library content on the local file system.
VMware, Inc. 37
VMware vSphere Automation SDK for .NET Programming Guide
Procedure
1 Retrieve a reference to the LocalLibrary service.
4 Specify the authentication method to be used by a subscribed library to authenticate to the local library.
You can enable either basic authentication or no authentication. Basic authentication requires a user
name and password.
5 (Optional) If you publish the library with basic authentication, you must specify a user name and
password for the PublishInfo instance, which must be used for authentication.
Important Use the predefined user name vcsp or leave the user name undefined. You must set only a
password to protect the library.
7 Use the retrieved local library to configure it with the PublishInfo instance.
8 Update the properties of the LibraryModel object returned for the local library.
...
using vmware.content;
using vmware.content.library;
38 VMware, Inc.
Chapter 6 Content Library Service
// Set the local library to published and update the library instance.
publishInfo.SetPublished(true);
libraryModel.SetPublishInfo(publishInfo);
localLibraryService.Update(libraryModel.GetId(), libraryModel);
Procedure
1 Retrieve the LocalLibrary service.
You can enable either basic authentication or no authentication on the library. Basic authentication
requires a user name and password.
4 (Optional) If you publish the library with basic authentication, you must specify a user name and
password for the PublishInfo instance, which must be used for authentication.
Important Use the predefined user name vcsp or leave the user name undefined. You must set only a
password to protect the library.
6 Set the library type to local and use the configured PublishInfo instance to set the library to published.
7 Define where the content of the local library is stored by using the StorageBacking class.
Note If you subscribe to libraries created with basic authentication on a vCenter Serverinstance, make sure
that you pass vcsp as an argument for the user name.
Procedure
1 Create a StorageBacking instance to define the location where the content of the subscribed library is
stored.
VMware, Inc. 39
VMware vSphere Automation SDK for .NET Programming Guide
a Provide the mechanism to be used by the subscribed library to authenticate to the published
library.
You can choose between no authentication and basic authentication depending on the settings of
the published library you subscribe to. If the library is published with basic authentication, you
must set basic authentication in the SubscriptionInfo instance. Set the user name and the
password of the SubscriptionInfo instance to match the credentials of the published library.
b Provide the URL to the endpoint where the metadata of the published library is stored.
You can choose between two synchronization modes: automatic and on demand. If you enable
automatic synchronization for a subscribed library, both the content and the metadata are
synchronized with the published library. To save storage space, you can synchronize the subscribed
library on demand and update only the metadata for the published library content.
d Set the thumbprint that is used for validating the certificate of the published library.
4 Access the SubscribedLibrary service and create the subscribed library instance.
...
using vmware.content;
using vmware.content.library;
...
// Specify that the content of the subscribed library will be downloaded immediately
subscriptionInfo.SetAutomaticSyncEnabled(true);
40 VMware, Inc.
Chapter 6 Content Library Service
libraryModel.SetName("SubscrLibrary");
// Attach the storage backing and the subscription info to the library model.
libraryModel.SetStorageBackings(new List<StorageBacking>() { libraryBacking });
libraryModel.SetSubscriptionInfo(subscriptionInfo);
n You can enable automatic synchronization of the subscribed library and download a copy of the content
of the local library immediately.
n You can save storage space and download only the metadata for the items that are part of the local
library.
To ensure that your subscribed library contains the most recent published library content, you can force a
synchronization task.
Procedure
1 Access the SubscribedLibrary vSphere Automation service.
The synchronization operation depends on the update settings of the subscribed library. If the subscribed
library is configured to update only on demand, only the metadata of the library items will be synchronized.
VMware, Inc. 41
VMware vSphere Automation SDK for .NET Programming Guide
Local content library You can change the settings of a local library before calling
the update function on the LocalLibrary object:
n Before a library is published, you can edit the following
settings:
n The name of a local library that is retrieved by
using the LocalLibrary object
n The human-readable description of a local library
retrieved by using the LocalLibrary object
n After a library is published, you must first retrieve the
PublishInfo instance of the published library you
want. You can use the instance to configure the
following settings.
n Unpublish the local library.
n Change the authentication method of the library.
n Change the password that must be used for
authentication.
Subscribed content library You can edit the settings of a subscribed library if you
retrieve the SubscriptionInfo instance associated with it.
To apply the changes, you must update the library by using
the SubscribedLibrary object.
You can configure the following settings:
n The authentication method required by the local
library
n The user name and password of the subscribed library
for authentication to the local library
n The method for synchronizing the metadata and the
content of the subscribed library
n The thumbprint used for validating the SSL certificate
of the local library
You can create a subscribed library with the option to download the library content on demand. As a result,
only the metadata for the library items is stored in the associated with the subscribed library storage. When
you want to deploy a virtual machine from a VM temple in the subscribed library, you must synchronize the
subscribed library to download the entire published library content. When you no longer need the VM
template, you can call the evict function on the SubscribedLibrary service. You must provide the
subscribed library ID to this function. As a result, the subscribed library content that is cached on the
backing storage is deleted.
If the subscribed library is not configured to synchronize on demand, an exception is thrown. In this case the
subscribed library always attempts to have the most recent published library content.
42 VMware, Inc.
Chapter 6 Content Library Service
Procedure
1 Access the SubscribedLibrary or the LocalLibrary service by using the vSphere Automation Endpoint.
3 Call the delete function on the library service and pass the library ID as argument.
All library items cashed on the storage backing are removed asynchronously. If this operation fails, you
must manually remove the content of the library.
Library Items
A library item groups multiple files within one logical unit. You can perform various tasks with the items in
a content library.
You can upload files to a library item in a local library and update existing items. You can download the
content of a library item from a subscribed library and use the item, for example, to deploy a virtual
machine. You can remove the content of a library item from a subscribed library to free storage space and
keep only the metadata of the library item. When you no longer need local library items, you can delete
them and they are removed from the subscribed library when a synchronization task is completed.
You can create a library item from a specific item type, for example .ovf. The Content Library service must
support the library item type to handle the item correctly. If no support is provided for a specified type, the
Content Library service handles the library item in the default way, without adding metadata to the library
item or guiding the upload process.
VMware, Inc. 43
VMware vSphere Automation SDK for .NET Programming Guide
Procedure
1 Access the Item service by using the vSphere Automation endpoint.
5 Invoke the create function on the Item object to pass the library item specification and the unique client
token.
What to do next
Upload content to the new library item. See “Upload a File from a Local System to a Library Item,” on
page 46 and “Upload a File from a URL to a Library Item,” on page 48.
...
using vmware.content;
using vmware.content.library;
...
// Create an instance of the ItemModel class and specify the item settings.
var libItemSpec = new ItemModel();
libItemSpec.SetName("ESXi ISO image");
libItemSpec.SetDescription("ISO image with the latest security patches for ESXi 5.5 as of
2/3/2015");
libItemSpec.SetType("iso");
You can retrieve a list of all items in a library, retrieve a library item that has a specific type or name, and
find a library item that is not cached on the disk. You can then update the library item content from the
subscribed library.
44 VMware, Inc.
Chapter 6 Content Library Service
Prerequisites
Verify that you have access to the Item service.
Procedure
1 Retrieve the ID of the content library whose items you want to list.
You can see an example query operation in the code example for “Edit the Settings of a Library Item,” on
page 45. The beginning of the example lists the items of a published library and prints a list with the names
and size of each file in the listed items.
Prerequisites
Verify that you have access to the Item service.
Procedure
1 Create an instance in the FindSpec class.
Prerequisites
Verify that you have access to the Item service.
Procedure
1 Retrieve the item that you want to update.
VMware, Inc. 45
VMware vSphere Automation SDK for .NET Programming Guide
...
using vmware.content;
using vmware.content.library;
...
// List the files uploaded to each library item and print their names and size
foreach (var singleFile in itemFilesService.List(itemId))
{
Console.WriteLine("Library item with name " + singleFile.GetName() +
" has size " + singleFile.GetSize());
}
// Change the name and description of the library item with the specified name
var singleItem = libItemService.Get(itemId);
if (singleItem.GetName().Equals("simpleVmTemplate"))
{
var libItemUpdated = new ItemModel();
libItemUpdated.SetName("newItemName");
libItemUpdated.SetDescription("Description of the newItemName");
libItemService.Update(singleItem.GetId(), libItemUpdated);
}
}
Prerequisites
n Create an empty library item. See “Create an Empty Library Item,” on page 44.
n Verify that you have access to the UpdateSession and File services.
Procedure
1 Create an UpdateSessionModel instance to track the changes that you make to the library item.
3 Create an AddSpec instance to describe the upload method and other properties of the file to be
uploaded.
4 Create the request for changing the item by using the File service.
46 VMware, Inc.
Chapter 6 Content Library Service
6 Complete and delete the update session to apply the changes to the library item.
.NET Example of Uploading Files to a Library Item from the Local System
This example shows how to upload an ISO image file from the local system to a library item.
...
using vmware.content;
using vmware.content.library;
using vmware.content.library.item;
using vmware.content.library.item.updatesession;
...
// Create a new library item as described in “.NET Example of Creating a Library Item,” on page 44
...
// Create an UpdateSessionModel instance to track the changes you make to the item.
var updateSessionModel = new UpdateSessionModel();
updateSessionModel.SetLibraryItemId(newItem);
// Create a new AddSpec instance to describe the properties of the file to be uploaded.
var fileSpec = new vmware.content.library.item.updatesession.FileTypes.AddSpec();
fileSpec.SetName("ESXi patch as of 10/2/2015");
fileSpec.SetSourceType(vmware.content.library.item.updatesession.FileTypes.SourceType.PUSH);
var uploadFileService =
ServiceManager.VapiConnection.GetService<vmware.content.library.item.updatesession.File>();
var fileInfo = uploadFileService.Add(sessionId, fileSpec);
var uploadUri = fileInfo.GetUploadEndpoint().GetUri();
var file1 = System.IO.File.Create("/updates/esxi/esxi_patch.iso");
// Use the HTTP PUT request to upload the file to the library item.
httpClient.Upload(file1, uploadUri.ToString());
VMware, Inc. 47
VMware vSphere Automation SDK for .NET Programming Guide
Prerequisites
n Create an empty library item. See “Create an Empty Library Item,” on page 44.
n Verify that you have access to the UpdateSession and File services.
Procedure
1 Create an UpdateSessionModel instance to track the changes that you make to the library item.
3 Create a file specification to describe the upload method and other properties of the file to be uploaded.
6 Create a request for changing the item by using the configured file specification.
7 Complete the update session to apply the changes to the library item.
....
using vmware.content;
using vmware.content.library;
using vmware.content.library.item;
using vmware.content.library.item.updatesession;
...
// Create a new library item. See “Create an Empty Library Item,” on page 44.
...
// Create an UpdateSessionModel instance to track the changes you make to the item.
var updateSessionModel = new UpdateSessionModel();
updateSessionModel.SetLibraryItemId(newItem);
// Create a new AddSpec instance to describe the properties of the file to be uploaded.
var fileSpec = new vmware.content.library.item.updatesession.FileTypes.AddSpec();
fileSpec.SetName("ESXi patch as of 10/2/2015");
fileSpec.SetSourceType(vmware.content.library.item.updatesession.FileTypes.SourceType.PULL);
// Specify the location from which the file is uploaded to the library item.
var endpoint = new TransferEndpoint();
endpoint.SetUri(new Uri("http://www.acme.com/patches_ESXi55/ESXi_patch.iso"));
fileSpec.SetSourceEndpoint(endpoint);
var uploadFileService =
ServiceManager.VapiConnection.GetService<vmware.content.library.item.updatesession.File>();
48 VMware, Inc.
Chapter 6 Content Library Service
uploadFileService.Add(sessionId, fileSpec);
Procedure
1 Create a download session model to specify the item, which contains the file that you want to
download.
2 Access the File service and retrieve the file that you want to export to your system within the new
download session.
3 Prepare the files that you want to download and wait until the files are in the prepared state.
.NET Example of Downloading Files from a Library Item to Your Local System
This example shows how you can download individual files from a library item to your local file system.
...
using System;
using System.IO;
using vmware.content;
using vmware.content.library;
using vmware.content.library.item;
using vmware.content.library.item.downloadsession;
// Access the File service and retrieve the files you want to export.
var downloadFileService =
ServiceManager.VapiConnection.GetService<vmware.content.library.item.downloadsession.File>();
for (var downloadFileInfo in downloadFileService.List(downloadSessionId))
{
// Make sure all files are in prepared state before you precede with the downloading
operation
downloadFileService.Prepare(downloadSessionId, downloadFileInfo.GetName(),
vmware.content.library.item.downloadsession.FileTypes.EndpointType.HTTPS);
VMware, Inc. 49
VMware vSphere Automation SDK for .NET Programming Guide
// When the files are prepared, you can retrieve the download information for each file.
downloadFileInfo = downloadFileService.Get(downloadSessionId,
downloadFileInfo.GetName());
var downloadUrl = downloadFileInfo.GetDownloadEndpoint().GetUri().ToString();
// Execute an HTTP GET request and pass the URLs to the endpoints of the download files.
using(var inputStream = httpClient.DownloadFile(downloadUrl))
{
var tmpDirInfo = Directory.CreateDirectory("tmp");
var fullLocalPath = Path.Combine(tmpDirInfo.FullName, downloadFileInfo.GetName());
using(var localFile = File.Create(fullLocalPath))
{
50 VMware, Inc.
Chapter 6 Content Library Service
Synchronized on demand If the subscribed library is synchronized on demand, you can use the
sync method on the SubscribedItem service and pass as arguments
the library item ID and true. When you perform the task, both the
item metadata and the content are synchronized. To synchronize only
the metadata of the item, pass the library ID and false as arguments
to the method.
Not synchronized on demand If the subscribed library is not synchronized on demand, you can use
the sync method on the SubscribedItem service and pass as
argument the item ID. In this case, the content of the item is always
synchronized and the Boolean value is ignored when the call is
executed.
Synchronized automatically If the subscribed library is synchronized automatically, you can also
use the sync method to force the synchronization of an item. Method
execution depends on whether the subscribed library is synchronized
on demand.
If you create a subscribed library with the option to synchronize library content on demand, only the
metadata for the library items is stored. When you want to use the items in the library, you must force
synchronization on the items to download their content. When you no longer need the files in an item, you
can remove the cached content of the library item and free storage space. To achieve this task use the evict
function of the SubscribedItem object.
To remove a library item from a library, you can call the delete method on the Item object and pass the
library item ID as an argument. The item content is asynchronously removed from the storage.
You cannot remove items from a subscribed library. If you remove an item from a local library, the item is
removed from the subscribed library when you perform a synchronization task on the subscribed library
item.
VMware, Inc. 51
VMware vSphere Automation SDK for .NET Programming Guide
52 VMware, Inc.
Content Library Support for OVF
Packages 7
Open Virtualization Format (OVF) is an industry standard that describes metadata about a virtual machine
image in an XML format. An OVF package includes an XML descriptor file and optionally disk images,
resource files (such as ISO files), manifest files, and certificate files.
With the vSphere Automation API, you can use the virtual machine (VM) and vApp templates from an OVF
package in a content library to deploy VMs and virtual appliances on hosts, resource pools, and clusters.
You can also use the API to create OVF packages in content libraries from virtual appliances and VMs on
hosts, resource pools, and clusters.
When you create library items to store OVF packages, you must set the item type to ovf. You can use the
objects and methods provided by the Content Library API to manage OVF packages. To comply with the
specific standards of the OVF packages, the vSphere Automation API provides the LibraryItem class.
For information about uploading content to library items, see “Upload a File from a Local System to a
Library Item,” on page 46 and “Upload a File from a URL to a Library Item,” on page 48.
To download the files that are included in an OVF package to your local file system, use the
DownloadSession interface. For more information, see “Download Files to a Local System from a Library
Item,” on page 49.
Procedure
1 Create an empty library item.
3 Create an AddSpec object to describe the properties and the upload location of the descriptor file of the
OVF package.
VMware, Inc. 53
VMware vSphere Automation SDK for .NET Programming Guide
All files that are included in the OVF package are automatically uploaded.
Procedure
1 Create a library item.
3 Create an AddSpec object to describe the properties and the upload location of the descriptor file of the
OVF package.
5 Create an AddSpec object for each VMDK file included in the OVF package.
With the vSphere Automation API, you can use the LibraryItem service to deploy virtual machines and
virtual applications from library items that contain OVF packages. You can also use the LibraryItem
vSphere Automation service to create library items from existing virtual machines and virtual appliances.
Procedure
1 Create a DeploymentTarget instance to specify the deployment location of the virtual machine or virtual
appliance.
2 Instantiate the ResourcePoolDeploymentSpec class to define all necessary parameters for the deployment
operation.
For example, you can assign a name for the deployed virtual machine or virtual appliance, and accept
the End User License Agreements (EULAs) to complete the deployment successfully.
3 (Optional) Retrieve information from the descriptor file of the OVF package and use the information
during the OVF package deployment.
54 VMware, Inc.
Chapter 7 Content Library Support for OVF Packages
Procedure
1 Create a DeployableIdentity instance to specify the source virtual machine or virtual appliance to be
captured in an OVF package.
2 Create a CreateTarget instance to identify the content library where the OVF package is stored.
4 Initiate a synchronous create operation by invoking the create function of the LibraryItem service.
VMware, Inc. 55
VMware vSphere Automation SDK for .NET Programming Guide
56 VMware, Inc.
Tagging Service 8
The vSphere Automation Tagging Service supports the definition of tags that you can associate with
vSphere objects or vSphere Automation resources. vSphere has a tagging feature but no public API to
manage tags. With the vSphere Automation SDK, you can manage tags programmatically.
For example, to tag your VMs by guest operating system type, you might create a category called
operating system, and specify that it applies to VMs only. You might also specify that only a single tag can
be applied to a VM at any time. The tags in this category might be Windows, Linux, and Mac OS.
Creating Tags
When you create a tag, you create a tag category and create a tag under the category. After you create the
tag, you can associate the tag with an object.
Tags and categories have global scope. The Platform Services Controller stores tags and categories makes
them available to any vCenter Server system that is registered with the Platform Services Controller.
VMware, Inc. 57
VMware vSphere Automation SDK for .NET Programming Guide
n name
n description
You can associate tags with both vSphere API managed objects and VMware vSphere Automation API
resources.
The category Create() function returns an identifier that you use when you create a tag for that category.
The empty set for the associable types indicates that any object type can be associated with a tag in this
category.
using vmware.cis.tagging;
using System.Collections.Generic;
Creating a Tag
After you create a tag category, you can create tags within that category
n name
n description
n category ID
58 VMware, Inc.
Chapter 8 Tagging Service
This example is based on code in the TagLifecycle.cs sample file. This file is located in the following
vSphere Automation SDK for .NET directory:
client/samples/src/Samples/vmware/vcloud/suite/samples/cis/tagging/
using vmware.cis.tagging;
Tag associations are local to a vCenter Server instance. When you request a list of tag associations from a
vCenter Server system, it enumerates only the associations that it has stored.
When you associate a tag with an object, the object's type must match one of the associable types specified
for the category to which the tag belongs.
Procedure
1 Construct a dynamic object identifier for the library.
VMware, Inc. 59
VMware vSphere Automation SDK for .NET Programming Guide
using vmware.vapi.std;
using vmware.cis.tagging;
This procedure describes the steps for applying tag a to a cluster object in your inventory.
Prerequisites
Obtain the managed object identifier for the specified cluster.
To get the managed object identifier of the ClusterComputeResource, you must access vCenter Server by
using the vSphere Web Services API. For more information about how to access Web Services, see “Create a
Web Services Session,” on page 29.
Procedure
1 Construct a dynamic object identifier for the cluster.
The dynamic identifier includes the type and ID of the managed object reference.
Updating a Tag
To update a tag, you must create an update spec for the tag. In the update spec, you set values for the fields
to be changed, and omit values for the other fields. When you do an update operation using the update spec,
only the fields that contain values are changed.
For example, you might use a timestamp in a tag description to identify a resource's last reconfiguration.
After reconfiguring the resource, you update the tag description to contain the current time.
using System;
using vmware.cis.tagging;
60 VMware, Inc.
Chapter 8 Tagging Service
VMware, Inc. 61
VMware vSphere Automation SDK for .NET Programming Guide
62 VMware, Inc.
Virtual Machine Configuration and
Operations 9
A virtual machine is a software computer that, like a physical computer, runs an operating system and
applications. The virtual machine consists of a set of specification and configuration files and is backed by
the physical resources of a host. Each virtual machine encapsulates a complete computing environment and
runs independently of the underlying hardware.
Starting with vSphere 6.5, you can configure virtual machine settings and perform power operations
through the vSphere Automation SDK for .NET.
You can retrieve a list of up to one thousand virtual machine IDs for a single vCenter Server instance by
filtering them based on a specific requirement, such as a host, cluster, datacenter, or resource pool on which
the VMs are running.
Call the list methods of the VM service to retrieve only a list of the virtual machines that match your specific
criteria. The method takes as parameter the VMTypes.FilterSpec instance that you can use to describe the
virtual machine filter.
To create a virtual machine you must specify the virtual machine attributes by using the CreateSpec class.
For example, you can specify a name, boot options, networking, and memory for the virtual machine. See
“Configuring a Virtual Machine,” on page 64.
All attributes are optional except the virtual machine placement information that you must provide by using
the PlacementSpec class. Use the virtual machine placement specification to set the datastore, cluster, folder,
host, or resource pool of the created virtual machine and make sure that all these vSphere objects are located
in the same data center in a vCenter Server instance.
For more information refer to the API Reference documentation inside the SDK.
VMware, Inc. 63
VMware vSphere Automation SDK for .NET Programming Guide
When you create your virtual machine, use the setName method of the CreateSpec class to pass as argument
the display name of the virtual machine.
You must create also a PlacementSpec instance that describes the location of the virtual machine in regards to
the resources of a given vCenter Server instance. Use the setPlacement(PlacementSpec placement) method
of the CreateSpec class to set the placement information for the virtual machine. You can set one or all of the
following vSphere resources: datastore, cluster, folder, host, and resource pool.
Boot Options
You can configure the boot options of a virtual machine by using the setBoot(CreateSpec boot) method of
the CreateSpec class.
The method takes as argument the BootTypes.CreateSpec class. You can select one of the following settings
when booting the virtual machine:
n Delay - Indicates a delay in milliseconds before starting the firmware boot process when the virtual
machine is powered on.
n Retry - Indicates whether the virtual machine automatically retries to boot after a failure.
n Retry delay - Indicates a delay in milliseconds before retrying the boot process after a failure.
n Enter setup mode - If set to true, indicates that the firmware boot process automatically enters BIOS
setup mode the next time the virtual machine boots. The virtual machine resets this flag to false once it
enters setup mode.
n EFI legacy boot - If set to true, indicates that the EFI legacy boot mode is used.
Operating System
The guest operating system that you specify affects the supported devices and available number of virtual
CPUs.
You specify the guest operating system by using the setGuestOS(GuestOS guestOS) method of the
VMTypes.CreateSpec class. The GuestOS class defines the valid guest OS types that you can use to configure a
virtual machine.
To change the CPU and memory configuration settings, use the CpuTypes.UpdateSpec and
MemoryTypes.UpdateSpec classes.
64 VMware, Inc.
Chapter 9 Virtual Machine Configuration and Operations
CPU Configuration
You can set the number of CPU cores in the virtual machine by using the setCount method of the
CpuTypes.UpdateSpec class. The supported range of CPU cores depends on the guest operating system and
virtual hardware version of the virtual machine. If you set CpuTypes.Info.getHotAddEnabled() and
CpuTypes.Info.getHotRemoveEnabled() to true, you allow virtual processors to be added or removed from
the virtual machine at runtime.
Memory Configuration
You can set the memory size of a virtual machine by using the setSizeMiB method of the
MemoryTypes.UpdateSpec class. The supported range of memory sizes depends on the configured guest
operating system and virtual hardware version of the virtual machine. If you set
MemoryTypes.UpdateSpec.setHotAddEnabled() to true while the virtual machine is not powered on, you
enable adding memory while the virtual machine is running.
Networks
You configure network settings so that a virtual machine can communicate with the host and with other
virtual machines. When you configure a virtual machine, you can add network adapters (NICs) and specify
the adapter type.
You can add virtual Ethernet adapters to a virtual machine by using the VMTypes.CreateSpec.setNics
method. Pass as argument a List of EthernetTypes.CreateSpec objects that provide the configuration
information of the created virtual Ethernet adapters. You can set the MAC address type to
EthernetTypes.MacAddressType.MANUAL, EthernetTypes.MacAddressType.GENERATED, or
EthernetTypes.MacAddressType.ASSIGNED. Select MANUAL to specify the MAC address explicitly.
You can specify also the physical resources that back a virtual Ethernet adapter by using the
EthernetTypes.BackingSpec.setType method. The method takes as argument one of the following types:
EthernetTypes.BackingType.STANDARD_PORTGROUP, HOST_DEVICE, DISTRIBUTED_PORTGROUP, or OPAQUE_NETWORK.
n PowerTypes.State.POWERED_OFF - Indicates that the virtual machine is not running. You can still update
the software on the physical disk of the virtual machine, which is impossible for physical machines.
n PowerTypes.State.SUSPENDED - Indicates that the virtual machine is paused and can be resumed. This
state is the same as when a physical machine is in standby or hibernate state.
To perform a power operation on a virtual machine, you can use one of the methods of the Power class.
Before you call one of the methods to change the power state of a virtual machine, you must first check the
current state of the virtual machine by using the Power.get method. Pass as argument the virtual machine
identifier.
n Power.start - Powers on a powered off or suspended virtual machine. The method takes as argument
the virtual machine identifier.
n Power.stop - Powers off a powered on or suspended virtual machine. The method takes as argument
the virtual machine identifier.
VMware, Inc. 65
VMware vSphere Automation SDK for .NET Programming Guide
n Power.suspend - Pauses all virtual machine activity for a powered on virtual machine. The method takes
as argument the virtual machine identifier.
n Power.reset - Shuts down and restarts the guest operating system without powering off the virtual
machine. Although this method functions as a stop method that is followed by a start method, the two
operations are atomic with respect to other clients, meaning that other power operations cannot be
performed until the reset method completes.
import com.vmware.vcenter.vm.Power;
import vmware.samples.common.SamplesAbstractBase;
import vmware.samples.vcenter.helpers.VmHelper;
...
private String vmName;
private String vmId;
private Power powerService;
...
this.powerService = vapiAuthHelper.getStubFactory().createStub(
Power.class, this.sessionStubConfig);
this.vmId = VmHelper.getVM(vapiAuthHelper.getStubFactory(),
sessionStubConfig,
vmName);
this.powerService.start(this.vmId);
...
66 VMware, Inc.
Index
VMware, Inc. 67
VMware vSphere Automation SDK for .NET Programming Guide
L S
library items SAML token, retrieving 26
creating 44 SAML token session 27
creating .NET 44 security context objects 27
deleting 51 service endpoints 17, 18
downloading .NET 49 service registration 19
editing 45 service endpoint filters 18
editing .NET 46 service registration object 19
filtering 45 SSO endpoint 18
removing 51 subscribe to library, .NET example 40
synchronizing 51 subscribing to a content library 39
uploading files 48 supported programming languages
uploading .NET 47, 48 .NET 11
library items list 45 Java 11
library items, listing 44 Perl 11
library items, searching for 44 Python 11
library items, uploading content 46 Ruby 11
listing library items 45 synchronizing library items 51
local system, downloading files 49
local system, uploading a file 46 T
looking up for services 17 tag associations, assign tag to content library 59
Lookup Service, service endpoints 20 tagging service 57
Tagging Service 9
N tags
name and placement 64 associations 59
create tag 58
O create tag category 58
operating system 64 update description 60
OVF package, uploading from a URL 53 tags, assigning, assigning tags 60
OVF support, content libraries 53
U
update tag, .Net example 60
P
uploading a file from a local system 46
Platform Services Controller 13, 14
uploading an OVF from a local file system 54
power on virtual machine 65
uploading files to library items 48
powering on a virtual machine 66
uploading OVF from a URL 53
predefined service endpoints 18
programming languages 11
V
protocol connection objects 31
vCenter Server 13
protocol factory objects 31
vCenter Service endpoint 18
publishing a library at the time of creation 39
vCenter Single Sign-On Endpoint 18
publishing content libraries, .NET example 38
virtual environment 13
virtual machine networks 65
R
virtual machine configuration and operations 63
removing content from subscribed library 42
virtualization layer 13
REST 11
vSphere 13
retrieving multiple service endpoints 20
vSphere components 13
retrieving node ID 22
vSphere deployment 14
retrieving SAML token, .NET example 26
vSphere services 13
retrieving service endpoints 17, 20
vSphere Automation endpoint 18, 23
retrieving the vSphere Automation 23
vSphere Automation Endpoint 13
retrieving vCenter Server ID 22
vSphere Automation SDK 9
68 VMware, Inc.
Index
VMware, Inc. 69
VMware vSphere Automation SDK for .NET Programming Guide
70 VMware, Inc.