oslo_vmware package

Subpackages

Submodules

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.

property pbm
pbm_wsdl_loc_set(pbm_wsdl_loc)
property 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

oslo_vmware.constants module

Shared constants across the VMware ecosystem.

oslo_vmware.dvs_util module

oslo_vmware.dvs_util.add_port_group(session, dvs_moref, name, vlan_id=None, trunk_mode=False)

Add a new port group to the dvs_moref

Parameters:
  • session – vCenter soap session

  • dvs_moref – managed DVS object reference

  • name – the name of the port group

  • vlan_id – vlan_id for the port

  • trunk_mode – indicates if the port will have trunk mode or use specific tag above

Returns:

The new portgroup moref

oslo_vmware.dvs_util.delete_port_group(session, portgroup_moref)

Delete a specific port group

Parameters:
  • session – vCenter soap session

  • portgroup_moref – managed portgroup object reference

oslo_vmware.dvs_util.get_dvs_moref(value)

Get managed DVS object reference.

Parameters:

value – value of the DVS managed object

Returns:

managed object reference with given value and type ‘VmwareDistributedVirtualSwitch’

oslo_vmware.dvs_util.get_port_group_spec(session, name, vlan_id, trunk_mode=False)

Gets the port group spec for a distributed port group

Parameters:
  • session – vCenter soap session

  • name – the name of the port group

  • vlan_id – vlan_id for the port

  • trunk_mode – indicates if the port will have trunk mode or use specific tag above

Returns:

The configuration for a port group.

oslo_vmware.dvs_util.get_portgroups(session, dvs_moref)

Gets all configured portgroups on the dvs_moref

Parameters:
  • session – vCenter soap session

  • dvs_moref – managed DVS object reference

Returns:

List of tuples that have the following format: (portgroup name, port group moref)

oslo_vmware.dvs_util.get_trunk_vlan_spec(session, start=0, end=4094)

Gets portgroup trunk vlan spec.

Parameters:
  • session – vCenter soap session

  • start – the starting id

  • end – then end id

Returns:

The configuration when a port uses trunk mode. This allows a guest to manage the vlan id.

oslo_vmware.dvs_util.get_vlan_spec(session, vlan_id)

Gets portgroup vlan spec.

Parameters:
  • session – vCenter soap session

  • vlan_id – the vlan_id for the port

Returns:

The configuration when a single vlan_id is used for a port

oslo_vmware.exceptions module

Exception definitions.

exception oslo_vmware.exceptions.AlreadyExistsException(message=None, cause=None, details=None, **kwargs)

Bases: VimException

code = 409
msg_fmt = 'Resource already exists.'
exception oslo_vmware.exceptions.CannotDeleteFileException(message=None, cause=None, details=None, **kwargs)

Bases: VimException

code = 403
msg_fmt = 'Cannot delete file.'
exception oslo_vmware.exceptions.DuplicateName(message=None, cause=None, details=None, **kwargs)

Bases: VimException

msg_fmt = 'Duplicate name.'
exception oslo_vmware.exceptions.FileAlreadyExistsException(message=None, cause=None, details=None, **kwargs)

Bases: VimException

code = 409
msg_fmt = 'File already exists.'
exception oslo_vmware.exceptions.FileFaultException(message=None, cause=None, details=None, **kwargs)

Bases: VimException

code = 409
msg_fmt = 'File fault.'
exception oslo_vmware.exceptions.FileLockedException(message=None, cause=None, details=None, **kwargs)

Bases: VimException

code = 403
msg_fmt = 'File locked.'
exception oslo_vmware.exceptions.FileNotFoundException(message=None, cause=None, details=None, **kwargs)

Bases: VimException

code = 404
msg_fmt = 'File not found.'
exception oslo_vmware.exceptions.ImageTransferException(message, cause=None)

Bases: VMwareDriverException

Thrown when there is an error during image transfer.

exception oslo_vmware.exceptions.InvalidPowerStateException(message=None, cause=None, details=None, **kwargs)

Bases: VimException

code = 409
msg_fmt = 'Invalid power state.'
exception oslo_vmware.exceptions.InvalidPropertyException(message=None, cause=None, details=None, **kwargs)

Bases: VimException

code = 400
msg_fmt = 'Invalid property.'
exception oslo_vmware.exceptions.ManagedObjectNotFoundException(message=None, cause=None, details=None, **kwargs)

Bases: VimException

code = 404
msg_fmt = 'Managed object not found.'
exception oslo_vmware.exceptions.MissingParameter(message=None, details=None, **kwargs)

Bases: VMwareDriverException

msg_fmt = 'Missing parameter : %(param)s'
exception oslo_vmware.exceptions.NoDiskSpaceException(message=None, cause=None, details=None, **kwargs)

Bases: VimException

msg_fmt = 'Insufficient disk space.'
exception oslo_vmware.exceptions.NoPermissionException(message=None, cause=None, details=None, **kwargs)

Bases: VimException

code = 403
msg_fmt = 'No Permission.'
exception oslo_vmware.exceptions.NotAuthenticatedException(message=None, cause=None, details=None, **kwargs)

Bases: VimException

code = 403
msg_fmt = 'Not Authenticated.'
exception oslo_vmware.exceptions.TaskInProgress(message=None, cause=None, details=None, **kwargs)

Bases: VimException

msg_fmt = 'Entity has another operation in process.'
exception oslo_vmware.exceptions.ToolsUnavailableException(message=None, cause=None, details=None, **kwargs)

Bases: VimException

msg_fmt = 'VMware Tools is not running.'
exception oslo_vmware.exceptions.UseLinkedCloneConfigurationFault(message=None, details=None, **kwargs)

Bases: VMwareDriverConfigurationException

msg_fmt = 'No default value for use_linked_clone found.'
exception oslo_vmware.exceptions.VMwareDriverConfigurationException(message=None, details=None, **kwargs)

Bases: VMwareDriverException

Base class for all configuration exceptions.

msg_fmt = 'VMware Driver configuration fault.'
exception oslo_vmware.exceptions.VMwareDriverException(message=None, details=None, **kwargs)

Bases: Exception

Base oslo.vmware exception

To correctly use this class, inherit from it and define a ‘msg_fmt’ property. That msg_fmt will get printf’d with the keyword arguments provided to the constructor.

property description
property msg
msg_fmt = 'An unknown exception occurred.'
exception oslo_vmware.exceptions.VimAttributeException(message, cause=None)

Bases: VMwareDriverException

Thrown when a particular attribute cannot be found.

exception oslo_vmware.exceptions.VimConnectionException(message, cause=None)

Bases: VMwareDriverException

Thrown when there is a connection problem.

exception oslo_vmware.exceptions.VimException(message=None, cause=None, details=None, **kwargs)

Bases: VMwareDriverException

The base exception class for all VIM related exceptions.

exception oslo_vmware.exceptions.VimFaultException(fault_list, message, cause=None, details=None)

Bases: VimException

Exception thrown when there are unrecognized VIM faults.

property description
exception oslo_vmware.exceptions.VimSessionOverLoadException(message, cause=None)

Bases: VMwareDriverException

Thrown when there is an API call overload at the VMware server.

oslo_vmware.exceptions.get_fault_class(name)

Get a named subclass of VimException.

oslo_vmware.exceptions.register_fault_class(name, exception)
oslo_vmware.exceptions.translate_fault(localized_method_fault, excep_msg=None)

Produce proper VimException subclass object,

The exception is based on a vmodl.LocalizedMethodFault.

Parameters:

excep_msg – Message to set to the exception. Defaults to localizedMessage of the fault.

oslo_vmware.image_transfer module

Functions and classes for image transfer between ESX/VC & image service.

oslo_vmware.image_transfer.copy_stream_optimized_disk(context, timeout_secs, write_handle, **kwargs)

Copy virtual disk from VMware server to the given write handle.

Parameters:
  • context – context

  • timeout_secs – time in seconds to wait for the copy to complete

  • write_handle – copy destination

  • kwargs – keyword arguments to configure the source VMDK read handle

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException, ImageTransferException, ValueError

oslo_vmware.image_transfer.download_file(read_handle, host, port, dc_name, ds_name, cookies, upload_file_path, file_size, cacerts, timeout_secs)

Download file to VMware server.

Parameters:
  • read_handle – file read handle

  • host – VMware server host name or IP address

  • port – VMware server port number

  • dc_name – name of the datacenter which contains the destination datastore

  • ds_name – name of the destination datastore

  • cookies – cookies to build the cookie header while establishing http connection with VMware server

  • upload_file_path – destination datastore file path

  • file_size – source file size

  • cacerts – CA bundle file to use for SSL verification

  • timeout_secs – timeout in seconds to wait for the download to complete

oslo_vmware.image_transfer.download_flat_image(context, timeout_secs, image_service, image_id, **kwargs)

Download flat image from the image service to VMware server.

Parameters:
  • context – image service write context

  • timeout_secs – time in seconds to wait for the download to complete

  • image_service – image service handle

  • image_id – ID of the image to be downloaded

  • kwargs – keyword arguments to configure the destination file write handle

Raises:

VimConnectionException, ImageTransferException, ValueError

oslo_vmware.image_transfer.download_image(image, image_meta, session, datastore, rel_path, bypass=True, timeout_secs=7200)

Transfer an image to a datastore.

Parameters:
  • image – file-like iterator

  • image_meta – image metadata

  • session – VMwareAPISession object

  • datastore – Datastore object

  • rel_path – path where the file will be stored in the datastore

  • bypass – if set to True, bypass vCenter to download the image

  • timeout_secs – time in seconds to wait for the xfer to complete

oslo_vmware.image_transfer.download_stream_optimized_data(context, timeout_secs, read_handle, **kwargs)

Download stream optimized data to VMware server.

Parameters:
  • context – image service write context

  • timeout_secs – time in seconds to wait for the download to complete

  • read_handle – handle from which to read the image data

  • kwargs – keyword arguments to configure the destination VMDK write handle

Returns:

managed object reference of the VM created for import to VMware server

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException, ImageTransferException, ValueError

oslo_vmware.image_transfer.download_stream_optimized_image(context, timeout_secs, image_service, image_id, **kwargs)

Download stream optimized image from image service to VMware server.

Parameters:
  • context – image service write context

  • timeout_secs – time in seconds to wait for the download to complete

  • image_service – image service handle

  • image_id – ID of the image to be downloaded

  • kwargs – keyword arguments to configure the destination VMDK write handle

Returns:

managed object reference of the VM created for import to VMware server

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException, ImageTransferException, ValueError

oslo_vmware.image_transfer.upload_image(context, timeout_secs, image_service, image_id, owner_id, **kwargs)

Upload the VM’s disk file to image service.

Parameters:
  • context – image service write context

  • timeout_secs – time in seconds to wait for the upload to complete

  • image_service – image service handle

  • image_id – upload destination image ID

  • kwargs – keyword arguments to configure the source VMDK read handle

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException, ImageTransferException, ValueError

oslo_vmware.image_util module

oslo_vmware.image_util.get_vmdk_name_from_ovf(ovf_handle)

Get the vmdk name from the given ovf descriptor.

oslo_vmware.pbm module

VMware PBM service client and PBM related utility methods

PBM is used for policy based placement in VMware datastores. Refer http://goo.gl/GR2o6U for more details.

class oslo_vmware.pbm.Pbm(protocol='https', host='localhost', port=443, wsdl_url=None, cacert=None, insecure=True, pool_maxsize=10, connection_timeout=None, op_id_prefix='oslo.vmware')

Bases: Service

Service class that provides access to the Storage Policy API.

retrieve_service_content()

Set the specified vCenter session cookie in the SOAP header

Parameters:

cookie – cookie to set

oslo_vmware.pbm.convert_datastores_to_hubs(pbm_client_factory, datastores)

Convert given datastore morefs to PbmPlacementHub morefs.

Parameters:
  • pbm_client_factory – Factory to create PBM API input specs

  • datastores – list of datastore morefs

Returns:

list of PbmPlacementHub morefs

oslo_vmware.pbm.filter_datastores_by_hubs(hubs, datastores)

Get filtered subset of datastores corresponding to the given hub list.

Parameters:
  • hubs – list of PbmPlacementHub morefs

  • datastores – all candidate datastores

Returns:

subset of datastores corresponding to the given hub list

oslo_vmware.pbm.filter_hubs_by_profile(session, hubs, profile_id)

Filter and return hubs that match the given profile.

Parameters:
  • hubs – PbmPlacementHub morefs

  • profile_id – profile ID

Returns:

subset of hubs that match the given profile

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException

oslo_vmware.pbm.get_all_profiles(session)

Get all the profiles defined in VC server.

Returns:

PbmProfile data objects

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException

oslo_vmware.pbm.get_pbm_wsdl_location(vc_version)

Return PBM WSDL file location corresponding to VC version.

Parameters:

vc_version – a dot-separated version string. For example, “1.2”.

Returns:

the pbm wsdl file location.

oslo_vmware.pbm.get_profile_id_by_name(session, profile_name)

Get the profile UUID corresponding to the given profile name.

Parameters:

profile_name – profile name whose UUID needs to be retrieved

Returns:

profile UUID string or None if profile not found

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException

oslo_vmware.pbm.get_profiles(session, vm)

Query storage profiles associated with the given vm.

Parameters:
  • session – VMwareAPISession instance

  • vm – vm reference

Returns:

profile IDs

oslo_vmware.pbm.get_profiles_by_ids(session, profile_ids)

Get storage profiles by IDs.

Parameters:
  • session – VMwareAPISession instance

  • profile_ids – profile IDs

Returns:

profile objects

oslo_vmware.rw_handles module

Classes defining read and write handles for image transfer.

This module defines various classes for reading and writing files including VMDK files in VMware servers. It also contains a class to read images from glance server.

class oslo_vmware.rw_handles.FileHandle(file_handle)

Bases: object

Base class for VMware server file (including VMDK) access over HTTP.

This class wraps a backing file handle and provides utility methods for various sub-classes.

close()

Close the file handle.

fileno()

returns the integer file descriptor by default this is not supported and raises IOError

flush()

flushes the internal buffer

get_size()

Get size of the file to be read.

Raises:

NotImplementedError

read(chunk_size)

Read a chunk of data.

Parameters:

chunk_size – read chunk size

Raises:

NotImplementedError

seek(offset)

sets the file’s current position at the offset

Parameters:

offset – offset

tell()

Get the position of File Handle

Returns:

position

write(data)

Write data to the file.

Parameters:

data – data to be written

Raises:

NotImplementedError

class oslo_vmware.rw_handles.FileReadHandle(host_or_url, port=None, data_center_name=None, datastore_name=None, cookies=None, file_path=None, scheme='https', cacerts=False, thumbprint=None)

Bases: FileHandle

Read handle for a file in VMware server.

close()

Closes the connection.

get_size()

Get size of the file to be read.

Raises:

NotImplementedError

read(length)

Read data from the file. :param length: amount of data to be read :raises: VimConnectionException, VimException

class oslo_vmware.rw_handles.FileWriteHandle(host_or_url, port=None, data_center_name=None, datastore_name=None, cookies=None, file_path=None, file_size=None, scheme='https', cacerts=False, thumbprint=None)

Bases: FileHandle

Write handle for a file in VMware server.

close()

Get the response and close the connection.

write(data)

Write data to the file.

Parameters:

data – data to be written

Raises:

VimConnectionException, VimException

class oslo_vmware.rw_handles.ImageReadHandle(glance_read_iter)

Bases: object

Read handle for glance images.

close()

Close the read handle.

This is a NOP.

get_next()

Get the next item from the image iterator.

read(chunk_size)

Read an item from the image data iterator.

The input chunk size is ignored since the client ImageBodyIterator uses its own chunk size.

class oslo_vmware.rw_handles.VmdkHandle(session, lease, url, file_handle)

Bases: FileHandle

VMDK handle based on HttpNfcLease.

update_progress()

Updates progress to lease.

This call back to the lease is essential to keep the lease alive across long running write/read operations.

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException

class oslo_vmware.rw_handles.VmdkReadHandle(session, host, port, vm_ref, vmdk_path, vmdk_size)

Bases: VmdkHandle

VMDK read handle based on HttpNfcLease.

close()

Releases the lease and close the connection.

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException

read(chunk_size=65536)

Read a chunk of data from the VMDK file.

Parameters:

chunk_size – size of read chunk

Returns:

the data

Raises:

VimException

tell()

Get the position of File Handle

Returns:

position

class oslo_vmware.rw_handles.VmdkWriteHandle(session, host, port, rp_ref, vm_folder_ref, import_spec, vmdk_size, http_method='PUT')

Bases: VmdkHandle

VMDK write handle based on HttpNfcLease.

This class creates a vApp in the specified resource pool and uploads the virtual disk contents.

close()

Releases the lease and close the connection.

Raises:

VimAttributeException, VimSessionOverLoadException, VimConnectionException

get_imported_vm()

“Get managed object reference of the VM created for import.

Raises:

VimException

tell()

Get the position of File Handle

Returns:

position

write(data)

Write data to the file.

Parameters:

data – data to be written

Raises:

VimConnectionException, VimException

oslo_vmware.service module

Common classes that provide access to vSphere services.

class oslo_vmware.service.CompatibilitySudsClient(*args, **kwargs)

Bases: Client

suds client with added cookiejar attribute

The cookiejar properties allow reading/setting the cookiejar used by the underlying transport.

property cookiejar
class oslo_vmware.service.LocalFileAdapter(pool_maxsize=10)

Bases: HTTPAdapter

Transport adapter for local files.

See http://stackoverflow.com/a/22989322

send(request, stream=False, timeout=None, verify=True, cert=None, proxies=None)

Sends request for a local file.

class oslo_vmware.service.MemoryCache

Bases: ObjectCache

get(key)

Retrieves the value for a key or None.

put(key, value, time=3600)

Sets the value for a key.

class oslo_vmware.service.RequestsTransport(cacert=None, insecure=True, pool_maxsize=10, connection_timeout=None)

Bases: Transport

open(request)

Open the URL in the specified request.

@param request: A transport request. @type request: L{Request} @return: An input stream. @rtype: stream @raise TransportError: On all transport errors.

send(request)
Send SOAP message. Implementations are expected to handle:
  • proxies

  • I{HTTP} headers

  • cookies

  • sending message

  • brokering exceptions into L{TransportError}

@param request: A transport request. @type request: L{Request} @return: The reply @rtype: L{Reply} @raise TransportError: On all transport errors.

class oslo_vmware.service.Response(stream, status=200, headers=None)

Bases: BytesIO

Response with an input stream as source.

get_all(name, default)
getheaders(name)
info()
property msg
read(chunk_size, **kwargs)

Read at most size bytes, returned as a bytes object.

If the size argument is negative, read until EOF is reached. Return an empty bytes object at EOF.

release_conn()
class oslo_vmware.service.Service(wsdl_url=None, soap_url=None, cacert=None, insecure=True, pool_maxsize=10, connection_timeout=None, op_id_prefix='oslo.vmware')

Bases: object

Base class containing common functionality for invoking vSphere services

static build_base_url(protocol, host, port)

Return the vCenter session cookie.

property service_content
class oslo_vmware.service.ServiceMessagePlugin

Bases: MessagePlugin

Suds plug-in handling some special cases while calling VI SDK.

EMPTY_ELEMENTS = ['VirtualMachineEmptyProfileSpec']
add_attribute_for_value(node)

Helper to handle AnyType.

Suds does not handle AnyType properly. But VI SDK requires type attribute to be set when AnyType is used.

Parameters:

node – XML value node

marshalled(context)

Modifies the envelope document before it is sent.

This method provides the plug-in with the opportunity to prune empty nodes and fix nodes before sending it to the server.

Parameters:

context – send context

prune(el)
class oslo_vmware.service.SudsLogFilter(name='')

Bases: Filter

Filter to mask/truncate vCenter credentials in suds logs.

filter(record)

Determine if the specified record is to be logged.

Returns True if the record should be logged, or False otherwise. If deemed appropriate, the record may be modified in-place.

oslo_vmware.version module

oslo_vmware.vim module

class oslo_vmware.vim.Vim(protocol='https', host='localhost', port=None, wsdl_url=None, cacert=None, insecure=True, pool_maxsize=10, connection_timeout=None, op_id_prefix='oslo.vmware')

Bases: Service

Service class that provides access to the VIM API.

retrieve_service_content()

oslo_vmware.vim_util module

The VMware API utility module.

class oslo_vmware.vim_util.WithRetrieval(vim, retrieve_result)

Bases: object

Context to retrieve results.

This context provides an iterator to retrieve results and cancel (when needed) retrieve operation on __exit__.

Example:

with WithRetrieval(vim, retrieve_result) as objects:
for obj in objects:

# Use obj

oslo_vmware.vim_util.build_object_spec(client_factory, root_folder, traversal_specs)

Builds the object spec.

Parameters:
  • client_factory – factory to get API input specs

  • root_folder – root folder reference; the starting point of traversal

  • traversal_specs – filter specs required for traversal

Returns:

object spec

oslo_vmware.vim_util.build_property_filter_spec(client_factory, property_specs, object_specs)

Builds the property filter spec.

Parameters:
  • client_factory – factory to get API input specs

  • property_specs – property specs to be collected for filtered objects

  • object_specs – object specs to identify objects to be filtered

Returns:

property filter spec

oslo_vmware.vim_util.build_property_spec(client_factory, type_='VirtualMachine', properties_to_collect=None, all_properties=False)

Builds the property spec.

Parameters:
  • client_factory – factory to get API input specs

  • type – type of the managed object

  • properties_to_collect – names of the managed object properties to be collected while traversal filtering

  • all_properties – whether all properties of the managed object need to be collected

Returns:

property spec

oslo_vmware.vim_util.build_recursive_traversal_spec(client_factory)

Builds recursive traversal spec to traverse managed object hierarchy.

Parameters:

client_factory – factory to get API input specs

Returns:

recursive traversal spec

oslo_vmware.vim_util.build_selection_spec(client_factory, name)

Builds the selection spec.

Parameters:
  • client_factory – factory to get API input specs

  • name – name for the selection spec

Returns:

selection spec

oslo_vmware.vim_util.build_traversal_spec(client_factory, name, type_, path, skip, select_set)

Builds the traversal spec.

Parameters:
  • client_factory – factory to get API input specs

  • name – name for the traversal spec

  • type – type of the managed object

  • path – property path of the managed object

  • skip – whether or not to filter the object identified by param path

  • select_set – set of selection specs specifying additional objects to filter

Returns:

traversal spec

oslo_vmware.vim_util.cancel_retrieval(vim, retrieve_result)

Cancels the retrieve operation if necessary.

Parameters:
  • vim – Vim object

  • retrieve_result – result of RetrievePropertiesEx API call

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException

oslo_vmware.vim_util.continue_retrieval(vim, retrieve_result)

Continue retrieving results, if available.

Parameters:
  • vim – Vim object

  • retrieve_result – result of RetrievePropertiesEx API call

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException

oslo_vmware.vim_util.find_extension(vim, key)

Looks for an existing extension.

Parameters:
  • vim – Vim object

  • key – the key to search for

Returns:

the data object Extension or None

oslo_vmware.vim_util.get_http_service_request_spec(client_factory, method, uri)

Build a HTTP service request spec.

Parameters:
  • client_factory – factory to get API input specs

  • method – HTTP method (GET, POST, PUT)

  • uri – target URL

oslo_vmware.vim_util.get_inventory_path(vim, entity_ref, max_objects=100)

Get the inventory path of a managed entity.

Parameters:
  • vim – Vim object

  • entity_ref – managed entity reference

  • max_objects – maximum number of objects that should be returned in a single call

Returns:

inventory path of the entity_ref

oslo_vmware.vim_util.get_moref(value, type_)

Get managed object reference.

Parameters:
  • value – value of the managed object

  • type – type of the managed object

Returns:

managed object reference with given value and type

oslo_vmware.vim_util.get_moref_type(moref)

Get the type of a managed object reference

This function accepts a string representation of a ManagedObjectReference like VirtualMachine:vm-123, but is also able to extract it from the actual object as returned by the API.

oslo_vmware.vim_util.get_moref_value(moref)

Get the value/id of a managed object reference

This function accepts a string representation of a ManagedObjectReference like VirtualMachine:vm-123 or only vm-123, but is also able to extract it from the actual object as returned by the API.

oslo_vmware.vim_util.get_obj_spec(client_factory, obj, select_set=None)

Builds the Object Spec object.

oslo_vmware.vim_util.get_object_properties(vim, moref, properties_to_collect, skip_op_id=False)

Get properties of the given managed object.

Parameters:
  • vim – Vim object

  • moref – managed object reference

  • properties_to_collect – names of the managed object properties to be collected

  • skip_op_id – whether to skip putting opID in the request

Returns:

properties of the given managed object

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException

oslo_vmware.vim_util.get_object_properties_dict(vim, moref, properties_to_collect)

Get properties of the given managed object as a dict.

Parameters:
  • vim – Vim object

  • moref – managed object reference

  • properties_to_collect – names of the managed object properties to be collected

Returns:

a dict of properties of the given managed object

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException

oslo_vmware.vim_util.get_object_property(vim, moref, property_name, skip_op_id=False)

Get property of the given managed object.

Parameters:
  • vim – Vim object

  • moref – managed object reference

  • property_name – name of the property to be retrieved

  • skip_op_id – whether to skip putting opID in the request

Returns:

property of the given managed object

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException

oslo_vmware.vim_util.get_objects(vim, type_, max_objects, properties_to_collect=None, all_properties=False)

Get all managed object references of the given type.

It is the caller’s responsibility to continue or cancel retrieval.

Parameters:
  • vim – Vim object

  • type – type of the managed object

  • max_objects – maximum number of objects that should be returned in a single call

  • properties_to_collect – names of the managed object properties to be collected

  • all_properties – whether all properties of the managed object need to be collected

Returns:

all managed object references of the given type

Raises:

VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException

oslo_vmware.vim_util.get_prop_filter_spec(client_factory, obj_spec, prop_spec)

Builds the Property Filter Spec Object.

oslo_vmware.vim_util.get_prop_spec(client_factory, spec_type, properties)

Builds the Property Spec Object.

oslo_vmware.vim_util.get_properties_for_a_collection_of_objects(vim, type_, obj_list, properties, max_objects=None)

Gets the list of properties for the collection of objects of the type specified.

oslo_vmware.vim_util.get_vc_version(session)

Return the dot-separated vCenter version string. For example, “1.2”.

Parameters:

session – vCenter soap session

Returns:

vCenter version

oslo_vmware.vim_util.propset_dict(propset)

Turn a propset list into a dictionary

PropSet is an optional attribute on ObjectContent objects that are returned by the VMware API.

You can read more about these at: | http://pubs.vmware.com/vsphere-51/index.jsp | #com.vmware.wssdk.apiref.doc/ | vmodl.query.PropertyCollector.ObjectContent.html

Parameters:

propset – a property “set” from ObjectContent

Returns:

dictionary representing property set

oslo_vmware.vim_util.register_extension(vim, key, type, label='OpenStack', summary='OpenStack services', version='1.0')

Create a new extension.

Parameters:
  • vim – Vim object

  • key – the key for the extension

  • type – Managed entity type, as defined by the extension. This matches the type field in the configuration about a virtual machine or vApp

  • label – Display label

  • summary – Summary description

  • version – Extension version number as a dot-separated string

oslo_vmware.vim_util.serialize_object(obj)

Convert Suds object into serializable format - a dict.

oslo_vmware.vim_util.storage_placement_spec(client_factory, dsc_ref, type, clone_spec=None, config_spec=None, relocate_spec=None, vm_ref=None, folder=None, clone_name=None, res_pool_ref=None, host_ref=None)

Module contents