vmware.vsphere¶
- vmware.vsphere.connect(host=None, username=None, password=None, cache=True):
Connect to vCenter
- Parameters:
host (string) – Hostname or IP-address
username (string) – Username
password (string) – Passwords
cache (bool) – Write object to cache if set to True
- Returns:
Service-instance object
- Return type:
object
- vmware.vsphere.default(obj):
Set the object as default vCenter-object (highly recommended)
- Parameters:
obj (object) – The object
- Returns:
Returns the object again
- Return type:
object
- vmware.vsphere.error_no_vc(**kwargs):
Generates an error (function for lazy men)
- Returns:
nothing
- Return type:
none
- vmware.vsphere.get_absolute_path(obj):
Gets the absolute path from the given object as long as there is a parent
- Parameters:
obj (object) – The object
- Returns:
String of all parents seperated by /
- Return type:
string
- vmware.vsphere.get_content(service_instance=None, cache=True):
Get the content of the service_instance It is highly recommended to use vmware.vsphere.default() on the return value
- Parameters:
service_instance (object) – The service_instance created by connect()
cache (bool) – Write object to cache if set to True
- Returns:
Content object
- Return type:
object
- vmware.vsphere.get_first_parent_type(attr, parent_type):
Gets the first parent of an attribute that matches the given type
- Parameters:
obj (string) – The attribute-object
obj – The type of the object
- Returns:
First parent-object that matches the type
- Return type:
object
- vmware.vsphere.get_id(obj):
Get the ID (_moId) of the object
- Parameters:
obj (object) – The object
- Returns:
The ID-string (_moId). Empty string if there is no ID
- Return type:
string
- vmware.vsphere.get_obj(vimtype, name, content=None):
not documented yet
- vmware.vsphere.get_objects_dict(obj, obj_type='*', **kwargs):
Get all objects within an an object-attribute and return them as dict Can filter by object-type if specified
- Parameters:
obj (list) – The object-attribute containing a list of entries
obj_type (string) – Object-type that should be returned. Default is “*” to disable filtering
- Returns:
Dict of matching items
- Return type:
dict
- Keyword Arguments:
key (
string) The name of the attribute that should be used as dict-key.
- vmware.vsphere.get_objects_list(obj, obj_type='*'):
Get all objects within an an object-attribute and return them as list Can filter by object-type if specified
- Parameters:
obj (list) – The object-attribute containing a list of entries
obj_type (string) – Object-type that should be returned. Default is “*” to disable filtering
- Returns:
List of matching items
- Return type:
list
- vmware.vsphere.get_vc_obj(kwargs):
Gets the vc_object from passed kwargs or the default set by vmware.vsphere.default()
- Parameters:
kwargs (dict) – kwargs passed into the parent function
- Returns:
vCenter-object or False
- Return type:
object
- vmware.vsphere.has_parent(obj):
Checks if the object has a parent
- Parameters:
obj (object) – The object
- Returns:
True or False
- Return type:
bool
- vmware.vsphere.is_obj_type(obj, type_name):
Check if passed object is matching the passed type. This is currently not a strict match as “type_name” is a string and needs only to be a subset of str(type(obj))
- Parameters:
obj (object) – The object
type_name (string) – The type
- Returns:
True or False
- Return type:
bool
- vmware.vsphere.is_type(obj):
Check if passed object is a vCenter
- Parameters:
obj (object) – The object
- Returns:
True if it is a vCenter, False if not
- Return type:
bool
- vmware.vsphere.is_vc(obj):
Check if passed object is a vCenter
- Parameters:
obj (object) – The object
- Returns:
True if it is a vCenter, False if not
- Return type:
bool
- vmware.vsphere.list_make_unique(elements):
Removes duplicates from a list of elements
- Parameters:
elements (list) – List of elements
- Returns:
deduplicated list
- Return type:
list
- vmware.vsphere.parent_is_type(obj, parent_type):
Checks if the parent matches the given type
- Parameters:
obj (object) – The object
parent_type (string) – The expected type of the parent
- Returns:
True or False
- Return type:
bool
- vmware.vsphere.recurse_child(obj, childType, key=False):
Recurse all child-objects (childEntity) and feed them into a dict or list. Recurse until no child is left. Childs will also be filtered by childType If a key is passed, a dict will be created. Otherwise it will be a list
- Parameters:
obj (object) – The object containing the childs
childType (string) – Child-type that should be fetched
key (string) – The name of the attribute that should be used as dict-key. May be “rel_path” to construct a unique path. Ommit to get a list
- Returns:
Dict or list of matching items
- Return type:
dict or list
- vmware.vsphere.recurse_child_dict(obj, childType, key, **kwargs):
Recurse all child-objects (childEntity) and feed them into a dict. Recurse until no child is left. Childs will also be filtered by childType
- Parameters:
obj (object) – The object containing the childs
childType (string) – Child-type that should be fetched
key (string) – The name of the attribute that should be used as dict-key. May be “rel_path” to construct a unique path
- Returns:
Dict of matching items
- Return type:
dict
- Keyword Arguments:
key_prepend (
string) String which should be prepended to all keys that are built within this function
- vmware.vsphere.recurse_child_list(obj, childType, **kwargs):
Recurse all child-objects (childEntity) and feed them into a list. Recurse until no child is left. Childs will also be filtered by childType
- Parameters:
obj (object) – The object containing the childs
childType (string) – Child-type that should be fetched
- Returns:
List of matching items
- Return type:
list
- Keyword Arguments:
Currently none
- vmware.vsphere.recurse_objects_dict(obj, attr_name, **kwargs):
Recurse through all objects that are contained in the given attribute (attr_name).
- Parameters:
obj (object) – The object
attr_name (string) – The name of the attribute that shall be recursed
- Returns:
Dict of matching items
- Return type:
dict
- Keyword Arguments:
key (
string) The name of the attribute that should be used as dict-key.key_prepend (
string) String which should be prepended to all keys that are built within this function
- vmware.vsphere.recurse_objects_list(obj, attr_name, **kwargs):
Recurse through all objects that are contained in the given attribute (attr_name).
- Parameters:
obj (object) – The object
attr_name (string) – The name of the attribute that shall be recursed
- Returns:
List of matching items
- Return type:
list
- Keyword Arguments:
Currently none
- vmware.vsphere.recurse_parent_if_type_not(obj, parent_type):
Recurse through parents of the object until the parent type is the given type or no parent is left
- Parameters:
obj (string) – The object
obj – The type of the parent object to look out for
- Returns:
First parent-object that matches the type
- Return type:
object