vmware.vapi package

Submodules

vmware.vapi.core module

Core Protocol Definition classes

class vmware.vapi.core.ApiInterface

Bases: object

The ApiInterface interface provides introspection APIs for a vAPI interface; it is implemented by API providers.

get_definition()

Returns interface definition

Return type:InterfaceDefinition
Returns:Interface definition
get_identifier()

Returns interface identifier

Return type:InterfaceIdentifier
Returns:Interface identifier
get_method_definition(method_id)

Returns the method definition

Return type:MethodDefinition
Returns:Method definition
invoke(ctx, method_id, input_value)

Invokes the specified method using the execution context and the input provided

Parameters:
  • ctx (ExecutionContext) – Execution context for this method
  • method_id (MethodIdentifier) – Method identifier
  • input_value (vmware.vapi.data.value.StructValue) – Method input parameters
Return type:

MethodResult

Returns:

Result of the method invocation

class vmware.vapi.core.ApiProvider

Bases: object

The ApiProvider interface is used for invocation of operations

invoke(service_id, operation_id, input_value, ctx)

Invokes the specified method using the input value and the the execution context provided

Parameters:
  • service_id (str) – Service identifier
  • operation_id (str) – Operation identifier
  • input_value (vmware.vapi.data.value.StructValue) – Input parameters for the method
  • ctx (ExecutionContext) – Execution context for the method
Return type:

MethodResult

Returns:

Result of the method invocation

class vmware.vapi.core.ApplicationContext(*args, **kwargs)

Bases: vmware.vapi.core.CustomDict

Interface representing additional data associated with the request for method execution represented by this ExecutionContext. The additional data format is key-value pairs of String.

This additional data is provided by the client initiating the execution, it is then transported as is over the wire and is available for the provider-side service implementations on the server. This extra data is completely opaque for the infrastructure, in other words it is a contract between the client and the service implementation only.

class vmware.vapi.core.CustomDict

Bases: dict

Interface for implementing Custom dict classes with additional constraints.

Overriding __setitem__ as not enough for adding additional constraints on key/value pairs of dictionaries. We also have to override update and setdefault, so that even they use __setitem__.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) → None. Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

class vmware.vapi.core.ExecutionContext(application_context=None, security_context=None)

Bases: object

This class provides out-of-band context information that is passed along with a method invocation

class vmware.vapi.core.InterfaceDefinition(id_, method_ids)

Bases: object

The InterfaceDefinition class contains detailed information about a vAPI interface. This should contain all the information required to address an interface in the vAPI runtime.

get_identifier()

Returns the interface identifier

Return type:InterfaceIdentifier
Returns:Returns the interface identifer of this interface
get_method_identifiers()

Returns the list of method identifiers of the methods exposed by this interface. Each method identifier is unique within an interface. The method identifiers returned are unordered

Return type:list of MethodIdentifier
Returns:List of method identifiers of the methods exposed by this interface
class vmware.vapi.core.InterfaceIdentifier(iface)

Bases: object

InterfaceIdentifier has the information required to uniquely address a vAPI interface

get_name()

Returns the string identifier of the interface

Return type:str
Returns:String identifier of the interface
class vmware.vapi.core.MethodDefinition(id_, input_, output, errors)

Bases: object

This class contains detailed information about a vAPI method. This should contain all the information required to address a method in the vAPI runtime.

get_error_definition(error_name)

Returns the error definition with the specified name reported by this method or None if this method doesn’t report an error with the specified name.

Parameters:error_name (str) – Name of the error definition to return
Return type:vmware.vapi.data.definition.ErrorDefinition
Returns:Error definition with the specified name reported by this method or None if this method doesn’t report an error with the specified name.
get_error_definitions()

Returns a set of error definitions describing the errors that this method can report

Return type:set of vmware.vapi.data.definition.ErrorDefinition
Returns:Set of error definitions describing the errors that this method can report
get_identifier()

Returns the method identifier

Return type:MethodIdentifier
Returns:MethodIdentifier of this method
get_input_definition()

Returns the struct definition corresponding to the method’s input parameters. The field names in the struct definition are the parameter names and the field values correspond to the data definition of the respective fields.

Return type:vmware.vapi.data.definition.StructDefinition
Returns:StructDefinition correspoding to the method’s input
get_output_definition()

Returns the data definition of the method’s output

Return type:vmware.vapi.data.definition.DataDefinition
Returns:Data definition of the method’s output
class vmware.vapi.core.MethodIdentifier(iface, method)

Bases: object

This class identifies a ApiMethod instance

get_interface_identifier()

Returns the interface identifier of the method

Return type:InterfaceIdentifier
Returns:InterfaceIdentifier of this method
get_name()

Returns the string identifier of the method

Return type:str
Returns:String identifier of the method
class vmware.vapi.core.MethodResult(output=None, error=None)

Bases: object

The MethodResult class contains the result of a method call. It contains either the output of the method invocation or an error reported by the method invocation. These are mutually exclusive.

Variables:
error
Return type:vmware.vapi.data.value.ErrorValue
Returns:Method error
output
Return type:vmware.vapi.data.value.DataValue
Returns:Method output
success()

Check if the method completed successfully.

Return type:bool
Returns:False if the method reported an error, True otherwise
class vmware.vapi.core.ProviderDefinition(name)

Bases: object

The ProviderDefinition class contains details information about a vAPI provider

get_identifier()

Returns the provider identifier.

Return type:str
Returns:Provider identifier
class vmware.vapi.core.SecurityContext(*args, **kwargs)

Bases: vmware.vapi.core.CustomDict

Implementations of this interface will provide all needed data for authentication for the given invocation.

vmware.vapi.exception module

vAPI CoreException Class

exception vmware.vapi.exception.CoreException(message, cause=None)

Bases: Exception

This exception is raised by various components of the vAPI runtime infrastructure to indicate failures in that infrastructure.

Server-side the exception is caught by specific components and an internal_server_error is reported to the client that invoked the request. Client-side the exception may be raised for certain failures before a request was sent to the server or after the response was received from the server. Similarly, server-side the exception may be raised for failures that occur when a provider implementation invokes the vAPI runtime.

This exception is not part of the vAPI message protocol, and it must never be raised by provider implementations.

Variables:messages – Generator of error messages describing why the Exception was raised
messages
Return type:generator of vmware.vapi.message.Message
Returns:Generator of error messages describing why the Exception was raised

vmware.vapi.message module

vAPI Message class

class vmware.vapi.message.Message(id_, def_msg, *args)

Bases: object

This class encapsulates the concept of a localizable message.

Variables:
  • id – The unique message identifier
  • def_msg – An english language default
  • args – The arguments to be used for the messsage
class vmware.vapi.message.MessageBundle(messages)

Bases: object

Base class for all message bundle classes.

get(msg_id)

Returns the message template for the given message identifier

Parameters:msg_id (str) – Message identifier
Return type:str
Returns:Message template
Raises:KeyError – If the message identifier is not found
class vmware.vapi.message.MessageFactory(msg_bundle, formatter)

Bases: object

A factory class to generate localizable messages

get_message(id_, *args)

Return a message object for the given id with the given args. If the message is not found, a default unknown message is returned.

Parameters:
  • id (string) – The unique message identifier
  • args (list of object) – The arguments to be used for constructing this message
Return type:

Message

Returns:

The message object constructed using the given arguments

class vmware.vapi.message.MessageFormatter

Bases: object

Base class for all message formatter classes

classmethod format_msg(msg, args)

Format the message using the specified arguments

Parameters:
  • msg (str) – Message template
  • args (list of object) – Arguments for the message
Return type:

str

Returns:

Localized message