The oslo_vmware.api Module

Session and API call management for VMware ESX/VC server.

This module contains classes to invoke VIM APIs. It supports automatic session re-establishment and retry of API invocations in case of connection problems or server API call overload.

class oslo_vmware.api.RetryDecorator(max_retry_count=-1, inc_sleep_time=10, max_sleep_time=60, exceptions=())

Bases: object

Decorator for retrying a function upon suggested exceptions.

The decorated function is retried for the given number of times, and the sleep time between the retries is incremented until max sleep time is reached. If the max retry count is set to -1, then the decorated function is invoked indefinitely until an exception is thrown, and the caught exception is not in the list of suggested exceptions.

class oslo_vmware.api.VMwareAPISession(host, server_username, server_password, api_retry_count, task_poll_interval, scheme=’https’, create_session=True, wsdl_loc=None, pbm_wsdl_loc=None, port=443, cacert=None, insecure=True, pool_size=10, connection_timeout=None, op_id_prefix=’oslo.vmware’)

Bases: object

Setup a session with the server and handles all calls made to it.

Example:
api_session = VMwareAPISession(‘10.1.2.3’, ‘administrator’,
‘password’, 10, 0.1, create_session=False, port=443)
result = api_session.invoke_api(vim_util, ‘get_objects’,
api_session.vim, ‘HostSystem’, 100)
invoke_api(module, method, *args, **kwargs)

Wrapper method for invoking APIs.

The API call is retried in the event of exceptions due to session overload or connection problems.

Parameters:
  • module – module corresponding to the VIM API call
  • method – method in the module which corresponds to the VIM API call
  • args – arguments to the method
  • kwargs – keyword arguments to the method
Returns:

response from the API call

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException

is_current_session_active()

Check if current session is active.

Returns:True if the session is active; False otherwise
logout()

Log out and terminate the current session.

pbm
pbm_wsdl_loc_set(pbm_wsdl_loc)
vim
wait_for_lease_ready(lease)

Waits for the given lease to be ready.

This method return when the lease is ready. In case of any error, appropriate exception is raised.

Parameters:lease – lease to be checked for
Raises:VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
wait_for_task(task)

Waits for the given task to complete and returns the result.

The task is polled until it is done. The method returns the task information upon successful completion. In case of any error, appropriate exception is raised.

Parameters:task – managed object reference of the task
Returns:task info upon successful completion of the task
Raises:VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException