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.
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.
Bases: object
Setup a session with the server and handles all calls made to it.
‘password’, 10, 0.1, create_session=False, port=443)
api_session.vim, ‘HostSystem’, 100)
Wrapper method for invoking APIs.
The API call is retried in the event of exceptions due to session overload or connection problems.
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
response from the API call
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
Check if current session is active.
True if the session is active; False otherwise
Log out and terminate the current session.
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.
lease – lease to be checked for
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
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.
task – managed object reference of the task
task info upon successful completion of the task
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
Shared constants across the VMware ecosystem.
Add a new port group to the dvs_moref
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
The new portgroup moref
Delete a specific port group
session – vCenter soap session
portgroup_moref – managed portgroup object reference
Get managed DVS object reference.
value – value of the DVS managed object
managed object reference with given value and type ‘VmwareDistributedVirtualSwitch’
Gets the port group spec for a distributed port group
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
The configuration for a port group.
Gets all configured portgroups on the dvs_moref
session – vCenter soap session
dvs_moref – managed DVS object reference
List of tuples that have the following format: (portgroup name, port group moref)
Gets portgroup trunk vlan spec.
session – vCenter soap session
start – the starting id
end – then end id
The configuration when a port uses trunk mode. This allows a guest to manage the vlan id.
Gets portgroup vlan spec.
session – vCenter soap session
vlan_id – the vlan_id for the port
The configuration when a single vlan_id is used for a port
Exception definitions.
Bases: VimException
Bases: VimException
Bases: VimException
Bases: VimException
Bases: VimException
Bases: VimException
Bases: VimException
Bases: VMwareDriverException
Thrown when there is an error during image transfer.
Bases: VimException
Bases: VimException
Bases: VimException
Bases: VMwareDriverException
Bases: VimException
Bases: VimException
Bases: VimException
Bases: VimException
Bases: VimException
Bases: VMwareDriverConfigurationException
Bases: VMwareDriverException
Base class for all configuration exceptions.
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.
Bases: VMwareDriverException
Thrown when a particular attribute cannot be found.
Bases: VMwareDriverException
Thrown when there is a connection problem.
Bases: VMwareDriverException
The base exception class for all VIM related exceptions.
Bases: VimException
Exception thrown when there are unrecognized VIM faults.
Bases: VMwareDriverException
Thrown when there is an API call overload at the VMware server.
Get a named subclass of VimException.
Produce proper VimException subclass object,
The exception is based on a vmodl.LocalizedMethodFault.
excep_msg – Message to set to the exception. Defaults to localizedMessage of the fault.
Functions and classes for image transfer between ESX/VC & image service.
Copy virtual disk from VMware server to the given write handle.
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
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException, ImageTransferException, ValueError
Download file to VMware server.
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
Download flat image from the image service to VMware server.
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
VimConnectionException, ImageTransferException, ValueError
Transfer an image to a datastore.
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
Download stream optimized data to VMware server.
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
managed object reference of the VM created for import to VMware server
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException, ImageTransferException, ValueError
Download stream optimized image from image service to VMware server.
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
managed object reference of the VM created for import to VMware server
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException, ImageTransferException, ValueError
Upload the VM’s disk file to image service.
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
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException, ImageTransferException, ValueError
Get the vmdk name from the given ovf descriptor.
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.
Bases: Service
Service class that provides access to the Storage Policy API.
Set the specified vCenter session cookie in the SOAP header
cookie – cookie to set
Convert given datastore morefs to PbmPlacementHub morefs.
pbm_client_factory – Factory to create PBM API input specs
datastores – list of datastore morefs
list of PbmPlacementHub morefs
Get filtered subset of datastores corresponding to the given hub list.
hubs – list of PbmPlacementHub morefs
datastores – all candidate datastores
subset of datastores corresponding to the given hub list
Filter and return hubs that match the given profile.
hubs – PbmPlacementHub morefs
profile_id – profile ID
subset of hubs that match the given profile
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
Get all the profiles defined in VC server.
PbmProfile data objects
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
Return PBM WSDL file location corresponding to VC version.
vc_version – a dot-separated version string. For example, “1.2”.
the pbm wsdl file location.
Get the profile UUID corresponding to the given profile name.
profile_name – profile name whose UUID needs to be retrieved
profile UUID string or None if profile not found
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
Query storage profiles associated with the given vm.
session – VMwareAPISession instance
vm – vm reference
profile IDs
Get storage profiles by IDs.
session – VMwareAPISession instance
profile_ids – profile IDs
profile objects
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.
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 the file handle.
returns the integer file descriptor by default this is not supported and raises IOError
flushes the internal buffer
Get size of the file to be read.
NotImplementedError
Read a chunk of data.
chunk_size – read chunk size
NotImplementedError
sets the file’s current position at the offset
offset – offset
Get the position of File Handle
position
Write data to the file.
data – data to be written
NotImplementedError
Bases: FileHandle
Read handle for a file in VMware server.
Closes the connection.
Get size of the file to be read.
NotImplementedError
Read data from the file. :param length: amount of data to be read :raises: VimConnectionException, VimException
Bases: FileHandle
Write handle for a file in VMware server.
Get the response and close the connection.
Write data to the file.
data – data to be written
VimConnectionException, VimException
Bases: object
Read handle for glance images.
Close the read handle.
This is a NOP.
Get the next item from the image iterator.
Read an item from the image data iterator.
The input chunk size is ignored since the client ImageBodyIterator uses its own chunk size.
Bases: FileHandle
VMDK handle based on HttpNfcLease.
Updates progress to lease.
This call back to the lease is essential to keep the lease alive across long running write/read operations.
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
Bases: VmdkHandle
VMDK read handle based on HttpNfcLease.
Releases the lease and close the connection.
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
Read a chunk of data from the VMDK file.
chunk_size – size of read chunk
the data
VimException
Get the position of File Handle
position
Bases: VmdkHandle
VMDK write handle based on HttpNfcLease.
This class creates a vApp in the specified resource pool and uploads the virtual disk contents.
Releases the lease and close the connection.
VimAttributeException, VimSessionOverLoadException, VimConnectionException
“Get managed object reference of the VM created for import.
VimException
Get the position of File Handle
position
Write data to the file.
data – data to be written
VimConnectionException, VimException
Common classes that provide access to vSphere services.
Bases: Client
suds client with added cookiejar attribute
The cookiejar properties allow reading/setting the cookiejar used by the underlying transport.
Bases: HTTPAdapter
Transport adapter for local files.
See http://stackoverflow.com/a/22989322
Sends request for a local file.
Bases: ObjectCache
Retrieves the value for a key or None.
Sets the value for a key.
Bases: Transport
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.
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.
Bases: BytesIO
Response with an input stream as source.
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.
Bases: object
Base class containing common functionality for invoking vSphere services
Return the vCenter session cookie.
Bases: MessagePlugin
Suds plug-in handling some special cases while calling VI SDK.
Helper to handle AnyType.
Suds does not handle AnyType properly. But VI SDK requires type attribute to be set when AnyType is used.
node – XML value node
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.
context – send context
Bases: Filter
Filter to mask/truncate vCenter credentials in suds logs.
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.
The VMware API utility module.
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
Builds the object spec.
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
object spec
Builds the property filter spec.
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
property filter spec
Builds the property spec.
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
property spec
Builds recursive traversal spec to traverse managed object hierarchy.
client_factory – factory to get API input specs
recursive traversal spec
Builds the selection spec.
client_factory – factory to get API input specs
name – name for the selection spec
selection spec
Builds the traversal spec.
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
traversal spec
Cancels the retrieve operation if necessary.
vim – Vim object
retrieve_result – result of RetrievePropertiesEx API call
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
Continue retrieving results, if available.
vim – Vim object
retrieve_result – result of RetrievePropertiesEx API call
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
Looks for an existing extension.
vim – Vim object
key – the key to search for
the data object Extension or None
Build a HTTP service request spec.
client_factory – factory to get API input specs
method – HTTP method (GET, POST, PUT)
uri – target URL
Get the inventory path of a managed entity.
vim – Vim object
entity_ref – managed entity reference
max_objects – maximum number of objects that should be returned in a single call
inventory path of the entity_ref
Get managed object reference.
value – value of the managed object
type – type of the managed object
managed object reference with given value and type
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.
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.
Builds the Object Spec object.
Get properties of the given managed object.
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
properties of the given managed object
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
Get properties of the given managed object as a dict.
vim – Vim object
moref – managed object reference
properties_to_collect – names of the managed object properties to be collected
a dict of properties of the given managed object
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
Get property of the given managed object.
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
property of the given managed object
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
Get all managed object references of the given type.
It is the caller’s responsibility to continue or cancel retrieval.
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
all managed object references of the given type
VimException, VimFaultException, VimAttributeException, VimSessionOverLoadException, VimConnectionException
Builds the Property Filter Spec Object.
Builds the Property Spec Object.
Gets the list of properties for the collection of objects of the type specified.
Return the dot-separated vCenter version string. For example, “1.2”.
session – vCenter soap session
vCenter version
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
propset – a property “set” from ObjectContent
dictionary representing property set
Create a new extension.
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
Convert Suds object into serializable format - a dict.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.