lib Package

lib Package

addr_url_parser Module

vAPI configuration addr url parser

vmware.vapi.lib.addr_url_parser.get_url_scheme(url)[source]

Get the scheme from the url (as described in http://www.rabbitmq.com/uri-spec.html)

Parameters:url (str) – The addr url to parse
Return type:str
Returns:url scheme
vmware.vapi.lib.addr_url_parser.parse_addr_url(url)[source]

Parse addr url (as described in http://www.rabbitmq.com/uri-spec.html) Note: This fn make no attempt to unescape the url, just like the urlparse

Parameters:url (str) – The addr url to parse
Return type:tuple of (scheme, host, port, user, password, path, query_dict) where scheme: url scheme host: hostname port: query_dict is a dictionary of (name, [values])
Returns:Parsed addr url

connect Module

vAPI Connection factory

vmware.vapi.lib.connect.check_file_exists(filename)[source]

Check if name is a file and exists

:type str :param file name

vmware.vapi.lib.connect.get_connector(rpc_provider_name, msg_protocol, ssl_context=None, **kwargs)[source]

Create a connection to the vAPI Provider using the specified arguments

Parameters:
  • rpc_provider_name (str) – The RPC provider to be used for the connection. Valid values are ‘http’, ‘https’ and ‘requests’
  • msg_protocol (str) – The message protocol to be used for the connection. Valid values are ‘json’.
  • ssl_context (OpenSSL.SSL.Context) – SSL context to use for SSL connections
  • kwargs – Additional arguments for the RPC provider
Return type:

vmware.vapi.protocol.client.connector.Connector

Returns:

Connection to the vAPI provider

vmware.vapi.lib.connect.get_requests_connector(session, msg_protocol='json', url=None, timeout=None, pool_size=8)[source]

Create a connection that uses ‘requests’ library for http connections

Parameters:
  • session (requests.Session) – Session object
  • msg_protocol (str) – Message protocol to be used for the connection. Valid values are ‘json’.
  • url (str) – HTTP(S) URL to be used
  • timeout (int) – Request timeout
  • pool_size (int) – Connection pool size to be used
Return type:

vmware.vapi.protocol.client.connector.Connector

Returns:

Connection to the vAPI provider

vmware.vapi.lib.connect.get_saml_hok_connector(rpc_provider_name, msg_protocol='json', ssl_context=None, **kwargs)[source]

Create a connection that uses SAML Hok based authentication to connect to a vAPI Provider

Parameters:
  • rpc_provider_name (str) – The RPC provider to be used for the connection. Valid values are ‘http’, ‘https’ or ‘requests’
  • msg_protocol (str) – The message protocol to be used for the connection. Valid values are ‘json’.
  • ssl_context (OpenSSL.SSL.Context) – SSL context to use for SSL connections
  • kwargs (dict of str and object) – Additional arguments for the RPC provider
Return type:

vmware.vapi.protocol.client.connector.Connector

Returns:

Connection to the vAPI provider

constants Module

String Constants used in vAPI runtime

class vmware.vapi.lib.constants.Introspection[source]

Bases: object

String constants used in introsection service

DATA_DEFINITION = 'com.vmware.vapi.std.introspection.operation.data_definition'
OPERATION_SVC = 'com.vmware.vapi.std.introspection.operation'
PACKAGE = 'com.vmware.vapi.std.introspection'
PROVIDER_SVC = 'com.vmware.vapi.std.introspection.provider'
SERVICE_SVC = 'com.vmware.vapi.std.introspection.service'

context Module

Factory methods for creating application context

vmware.vapi.lib.context.create_default_application_context()[source]

Create a default application context. The created context will only have opId.

Return type:vmware.vapi.core.ApplicationContext
Returns:Newly created application context

converter Module

Convenience methods for converting variable names

class vmware.vapi.lib.converter.Converter[source]

Bases: object

Convenience methods for converting variable names

static canonical_to_pep(name)[source]

Converts the argument from vAPI canonical format to PEP8 compliant parameter or attribute name

Parameters:name (str) – The string to be converted
Return type:str
Returns:The converted string
static capitalize(name)[source]

Capitalize the first letter of the name

Parameters:name (str) – name to be converted
Return type:str
Returns:name with first letter capitalized
static capwords_to_underscore(name)[source]

Convert from CapWords to lower_case_with_underscore format

Parameters:name (str) – name in CapWords format
Return type:str
Returns:name in lower_case_with_underscore format
static mixedcase_to_underscore(name)[source]

Convert from mixedCase to lower_case_with_underscore format

Parameters:name (str) – name in mixedCase format
Return type:str
Returns:name in lower_case_with_underscore format
static pepify(name)[source]

Converts the argument into a name that conforms to PEP8 standard. i.e. lower_case_with_underscore

Parameters:name (str) – The string to be converted
Return type:str
Returns:The converted string
static uncapitalize(name)[source]

Uncapitalize the first letter of the name

Parameters:name (str) – name to be converted
Return type:str
Returns:name with first letter uncapitalized
static underscore_to_capwords(name)[source]

Convert from lower_case_with_underscore to CapWords format

Parameters:name (str) – name in lower_case_with_underscore
Return type:str
Returns:name in CapWords
static underscore_to_mixedcase(name)[source]

Convert from lower_case_with_underscore to mixedCase format

Parameters:name (str) – name in lower_case_with_underscore
Return type:str
Returns:name in mixedCase
static unreserve_name(name)[source]

Converts the argument if it clashes with a python keyword. If the string matches a keyword, adds a trailing underscore, else it returns the same string

Parameters:name (str) – The string to be converted
Return type:str
Returns:The converted string

fingerprint Module

Fingerprint related functions

vmware.vapi.lib.fingerprint.generate_fingerprint(data)[source]

Generate fingerprint for the given data

Return type:str
Returns:fingerprint of the given data

load Module

Convenience methods for dynamic loading

vmware.vapi.lib.load.dynamic_import(constructor)[source]

Dynamically import a module and get the specified module attribute

Parameters:constructor (str) – Fully qualified module attribute
Return type:object
Returns:Python object
vmware.vapi.lib.load.import_multiple_classes(section, property_key)[source]

Import multiple class names provided in the config file

Parameters:
  • section (str) – Name of the section in the config file
  • property_key (str) – Name of the property in the config file
Return type:

list of str

Returns:

List of class references

profiler Module

Convenience methods for loading the profiler

vmware.vapi.lib.profiler.mock_profile(func)[source]

Mock decorator that is used when the PROFILER is not set

vmware.vapi.lib.profiler.profile(func)

Mock decorator that is used when the PROFILER is not set

ssl Module

SSL Context factories

class vmware.vapi.lib.ssl.ClientContextFactory[source]

Bases: object

Context factory base class. This class should be used to set the SSL options

get_context()[source]

Returns the SSL context

class vmware.vapi.lib.ssl.DefaultClientContextFactory(certificate=None, private_key=None, ca_certs=None, ca_certs_dir=None)[source]

Bases: vmware.vapi.lib.ssl.ClientContextFactory

Default SSL context class. This chooses some default options for SSL context. Clients can retrieve the context.

To modify the context and set some options directly. Create a class like below and set the options. Pass this to the get_connector function

class CustomClientContextFactory(DefaultClientContextFactory):
def getContext(self):
ctx = DefaultClientContextFactory.getContext(self) # modify ctx return ctx

Initialize DefaultClientContextFactory

Parameters:
  • certificate (str) – File path of the certificate
  • private_key (str) – File path of the private key
  • ca_certs (str) – File path of ca certificates
  • ca_certs_dir (str) – Directory prepared using the c_rehash tool included with OpenSSL
get_context()[source]

Returns the SSL context

Return type:OpenSSL.SSL.Context
Returns:SSL context

std Module

Helper functions for manipulating vAPI runtime objects corresponding to the standard types (e.g. LocalizableMessage) and errors

vmware.vapi.lib.std.make_error_value_from_error_value_and_msgs(error_def, cause, *msg_list)[source]

Create an error result for a “standard” error from a cause ErrorValue and an list of messages.

The list of message will be prepended to the messages from the cause (if any).

Parameters:
Return type:

vmware.vapi.data.value.ErrorValue

Returns:

ErrorValue containing a single message

vmware.vapi.lib.std.make_error_value_from_msg_id(error_def, msg_id, *args)[source]

Create an error result for a “standard” error

Parameters:
  • error_def (vmware.vapi.data.type.ErrorDefinition) – ErrorDefintion for the error
  • msg_id (str) – Message identifier
  • args (list of str) – Argument list for constructing a Message
Return type:

vmware.vapi.data.value.ErrorValue

Returns:

ErrorValue containing a single message

vmware.vapi.lib.std.make_error_value_from_msgs(error_def, *msg_list)[source]

Create an error result for a “standard” error

Parameters:
  • error_def (vmware.vapi.data.type.ErrorDefinition) – ErrorDefintion for the error
  • msg_list (list of vmware.vapi.message.Message) – list of localizable messages
Return type:

vmware.vapi.data.value.ErrorValue

Returns:

ErrorValue containing a single message

vmware.vapi.lib.std.make_std_error_def(name)[source]

Internal function to create a “standard” ErrorDefinition for use only by the vAPI runtime. :type name: str :param args: Fully qualified name of the standard error type :rtype: vmware.vapi.data.definition.ErrorDefinition :return: ErrorDefinition containing a single message field

thread_pool Module

This module is YATP (Yet another thread pool)

class vmware.vapi.lib.thread_pool.ThreadPool(min_workers=1, max_workers=8, idle_timeout=300, logger=None)[source]

Bases: object

Thread pool

Thread pool constructor

Params min_workers:
 Min number of worker threads
Params max_workers:
 Max number of worker threads
Params idle_timeout:
 Worker threads idle timeout
Params logger:logger to use. Default to stdout
static normalize_works(works)[source]

Generator to return work in normalize form: (fn, args, kwargs)

Parameters:works (iteratable of fn / (fn, args) / (fn, args, kwargs)) – An iteratable of possible functor form
Return type:tuple of (fn, args, kwargs)
Returns:A normalize tuple of (functor, args, kwargs)
queue_work(fn, *args, **kwargs)[source]

Queue work

Returns a work_item when work is queued to work queue The work will start when a ready worker is available to process the work User could call {work_item}.join() to wait for the work item to finish

Parameters:
  • fn (function) – Work item functor
  • args (tuple) – Work item functor positional parameters
  • kwargs (dict) – Work item functor key-value parameters
Return type:

WorkItem

Returns:

work item when work is queued to work queue

queue_work_and_wait(fn, *args, **kwargs)[source]

Queue a work and wait until the work is completed / error out

Parameters:
  • fn (function) – Work item functor
  • args (tuple) – Work item functor positional parameters
  • kwargs (dict) – Work item functor key-value parameters
Return type:

tuple of (bool, object) or (bool, Exception)

Returns:

(True, return val) / (False, exception) when work is done

queue_works_and_wait(works)[source]

Queue a brunch of works and wait until all works are completed / error out

Parameters:works (iteratable of fn / (fn, args) / (fn, args, kwargs)) – An iteratable of possible functor form
Return type:list of {tuple} of bool,:class:object or bool,:class:Exception
Returns:A list of (True, return val) / (False, exception) when all works done
shutdown(no_wait=False)[source]

Shuthdown this thread pool

Parameters:no_wait (bool) – Set to True to return immediately without waiting for all workers to quit
class vmware.vapi.lib.thread_pool.WorkItem(fn, *args, **kwargs)[source]

Bases: object

Work item

Work item constructor

Parameters:
  • fn (function) – Work item functor
  • args (tuple) – Work item functor positional parameters
  • kwargs (dict) – Work item functor key-value parameters
done()[source]

Signal work item is done

join(timeout=inf)[source]

Wait for work item is done

Parameters:timeout (float) – Timeout in seconds
Return type:object
Returns:Work item functor’s return value

visitor Module

Visitor helper class

class vmware.vapi.lib.visitor.VapiVisitor(suffix=None)[source]

Bases: object

Convenience class for visitors used in vAPI Python runtime

Initialize VapiVisitor

Parameters:suffix (str) – The suffix string that should be removed from class name during the dispatch
visit(value)[source]

Dispatch the call to the appropriate method based on the type of the input argument

Parameters:value (object) – The object to be used for dispatch

workers_pool Module

Workers thread pool

vmware.vapi.lib.workers_pool.get_workers_pool(pool_tag)[source]

get workers pool

Parameters:pool_tag (str) – workers pool tag
Return type:vmware.vapi.lib.thread_pool.ThreadPool
Returns:workers pool