### Navigation

- index
- modules |
- next |
- previous |
- vSphere Automation SDK for Python 6.5.0 documentation »
- vmware Package »
- vapi Package »

# lib Package

## `lib` Package

## `addr_url_parser` Module

vAPI configuration addr url parser

`vmware.vapi.lib.addr_url_parser.``get_url_scheme`(url)

  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)

  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)

  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)

  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)

  Create a connection that uses ‘requests’ library for http(s) connections to a vAPI Provider.

  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_requests_hok_connector`(session, msg_protocol='json', url=None, timeout=None, pool_size=8)

  Create a connection that uses SAML Hok based authentication using ‘requests’ library to connect to a vAPI Provider.

  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)

  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`

  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`()

  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`

  Bases: `object`

  Convenience methods for converting variable names

  static `canonical_to_pep`(name)

    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)

    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)

    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)

    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)

    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)

    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)

    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)

    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)

    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)

  Generate fingerprint for the given data

  Return type: | `str`
  Returns: | fingerprint of the given data

## `jsonlib` Module

JSON encoder for double values

class `vmware.vapi.lib.jsonlib.``DecimalEncoder`(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)

  Bases: `json.encoder.JSONEncoder`

  Class that adds capability of encoding decimal in JSON

  Constructor for JSONEncoder, with sensible defaults.

  If skipkeys is False, then it is a TypeError to attempt encoding of keys that are not str, int, long, float or None. If skipkeys is True, such items are simply skipped.

  If ensure_ascii is True, the output is guaranteed to be str objects with all incoming unicode characters escaped. If ensure_ascii is false, the output will be unicode object.

  If check_circular is True, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an OverflowError). Otherwise, no such check takes place.

  If allow_nan is True, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.

  If sort_keys is True, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.

  If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

  If specified, separators should be a (item_separator, key_separator) tuple. The default is (‘, ‘, ‘: ‘). To get the most compact JSON representation you should specify (‘,’, ‘:’) to eliminate whitespace.

  If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a `TypeError`.

  If encoding is not None, then all input strings will be transformed into unicode using that encoding prior to JSON-encoding. The default is UTF-8.

  `default`(o)

`vmware.vapi.lib.jsonlib.``canonicalize_double`(o)

  Canonicalize double based on XML schema double canonical format

  The exponent must be indicated by “E”. Leading zeroes and the preceding optional “+” sign are prohibited in the exponent. If the exponent is zero, it must be indicated by “E0”. For the mantissa, the preceding optional “+” sign is prohibited and the decimal point is required. Leading and trailing zeroes are prohibited subject to the following: number representations must be normalized such that there is a single digit which is non-zero to the left of the decimal point and at least a single digit to the right of the decimal point unless the value being represented is zero. The canonical representation for zero is 0.0E0 http://www.w3.org/TR/xmlschema-2/#double

  Parameters: | o (`decimal.Decimal`) – Decimal object to be canonicalized
  Return type: | `str`
  Returns: | Canonical string representation of the decimal

## `load` Module

Convenience methods for dynamic loading

`vmware.vapi.lib.load.``dynamic_import`(constructor)

  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)

  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

## `log` Module

## `profiler` Module

Convenience methods for loading the profiler

`vmware.vapi.lib.profiler.``mock_profile`(func)

  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`

  Bases: `object`

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

  `get_context`()

    Returns the SSL context

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

  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 get_context(self):
      ctx = DefaultClientContextFactory.get_context(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`()

    Returns the SSL context

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

class `vmware.vapi.lib.ssl.``UnverifiedClientContextFactory`

  Bases: `vmware.vapi.lib.ssl.DefaultClientContextFactory`

  Unverified SSL context class. This class retrieves an unverified SSL Context with other options from the DefaultClientContext

## `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)

  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: | error_def (`vmware.vapi.data.type.ErrorDefinition`) – ErrorDefintion for the error cause (`vmware.vapi.data.value.ErrorValue`) – Lower level ErrorValue that “caused” 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_error_value_from_msg_id`(error_def, msg_id, *args)

  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)

  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)

  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)

  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)

    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)

    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)

    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)

    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)

    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)

  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`()

    Signal work item is done

  `join`(timeout=inf)

    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)

  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)

    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)

  get workers pool

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

## Subpackages

### Navigation

- index
- modules |
- next |
- previous |
- vSphere Automation SDK for Python 6.5.0 documentation »
- vmware Package »
- vapi Package »