pyvcloud.vcd.utils module¶
-
pyvcloud.vcd.utils.
access_settings_to_dict
(control_access_params)¶ Convert a lxml.objectify.ObjectifiedElement access settings to dict.
Parameters: control_access_params (lxml.objectify.ObjectifiedElement) – an object containing EntityType.CONTROL_ACCESS_PARAMS XML data. Returns: dict representation of access control settings. Return type: dict
-
pyvcloud.vcd.utils.
disk_to_dict
(disk)¶ Converts a lxml.objectify.ObjectifiedElement disk object to a dict.
Parameters: disk (lxml.objectify.ObjectifiedElement) – an object containing EntityType.DISK XML data. Returns: dictionary representation of disk object. Return type: dict
-
pyvcloud.vcd.utils.
extract_id
(urn)¶ Extract id from an urn.
‘urn:vcloud:catalog:39867ab4-04e0-4b13-b468-08abcc1de810’ will produce ‘39867ab4-04e0-4b13-b468-08abcc1de810’
Parameters: urn (str) – a vcloud resource urn. Returns: the extracted id Return type: str
-
pyvcloud.vcd.utils.
filter_attributes
(resource_type)¶ Returns a list of attributes for a given resource type.
Parameters: resource_type (str) – type of resource whose list of attributes we want to extract. Valid values are ‘adminTask’, ‘task’, ‘adminVApp’, ‘vApp’ and ‘adminCatalogItem’, ‘catalogItem’. Returns: the list of attributes that are relevant for the given resource type. Return type: list
-
pyvcloud.vcd.utils.
get_admin_extension_href
(href)¶ Returns sys admin version of a given vCD url.
This function is idempotent, which also means that if input href is already an admin extension href no further action would be taken.
Parameters: href (str) – the href whose sys admin version we need. Returns: sys admin version of the href. Return type: str
-
pyvcloud.vcd.utils.
get_admin_href
(href)¶ Returns admin version of a given vCD url.
This function is idempotent, which also means that if input href is already an admin href no further action would be taken.
Parameters: href (str) – the href whose admin version we need. Returns: admin version of the href. Return type: str
-
pyvcloud.vcd.utils.
get_safe_members_in_tar_file
(tarfile)¶ Retrieve members of a tar file that are safe to extract.
Parameters: tarfile (Tarfile) – the archive that has been opened as a TarFile object. Returns: list of members in the archive that are safe to extract. Return type: list
-
pyvcloud.vcd.utils.
org_to_dict
(org)¶ Convert a lxml.objectify.ObjectifiedElement org object to a dict.
Parameters: org (lxml.objectify.ObjectifiedElement) – an object containing EntityType.ORG or EntityType.ADMIN_ORG XML data. Returns: dictionary representation of the org. Return type: dict
-
pyvcloud.vcd.utils.
pvdc_to_dict
(pvdc, refs=None, metadata=None)¶ Converts a Provider Virtual Datacenter resource to a python dictionary.
Parameters: - pvdc (lxml.objectify.ObjectifiedElement) – an object containing EntityType.PROVIDER_VDC XML data.
- refs (lxml.objectify.ObjectifiedElement) – an object containing EntityType.VDC_REFERENCES XML data.
- metadata (lxml.objectify.ObjectifiedElement) – an object containing EntityType.METADATA XML data.
Returns: dictionary representation of pvdc object.
Return type: dict
-
pyvcloud.vcd.utils.
stdout_xml
(the_xml, is_colorized=True)¶ Prints an lxml.objectify.ObjectifiedElement to console.
Parameters: - the_xml (lxml.objectify.ObjectifiedElement) – the object we want to print.
- is_colorized (bool) – if True, will print highlight xml tags and attributes else will print b&w output to the console.
-
pyvcloud.vcd.utils.
task_to_dict
(task)¶ Converts a lxml.objectify.ObjectifiedElement task object to a dict.
Parameters: task (lxml.objectify.ObjectifiedElement) – an object containing EntityType.TASK XML data. Returns: dictionary representation of task object. Return type: dict
-
pyvcloud.vcd.utils.
to_camel_case
(name, names)¶
-
pyvcloud.vcd.utils.
to_dict
(obj, attributes=None, resource_type=None, exclude=['href', 'type'])¶ Converts generic lxml.objectify.ObjectifiedElement to a dictionary.
Parameters: - obj (lxml.objectify.ObjectifiedElement) –
- attributes (list) – list of attributes we want to extract from the XML object.
- resource_type (str) – type of resource in the param obj. Acceptable values are listed in the enum pyvcloud.vcd.client.ResourceType.
- exclude (list) – list of attributes that should be excluded from the dictionary.
Returns: the dictionary representing the object.
Return type: dict
-
pyvcloud.vcd.utils.
to_human
(seconds)¶ Converts seconds to human readable (weeks, days, hours) form.
Parameters: seconds (int) – number of seconds. Returns: (weeks, days, hours) equivalent to the seconds. Return type: str
-
pyvcloud.vcd.utils.
vapp_to_dict
(vapp, metadata=None, access_control_settings=None)¶ Converts a lxml.objectify.ObjectifiedElement vApp object to a dict.
Parameters: - vapp (lxml.objectify.ObjectifiedElement) – an object containing EntityType.VAPP XML data.
- access_control_settings (lxml.objectify.ObjectifiedElement) – an object containing EntityType.CONTROL_ACCESS_PARAMS XML data.
Returns: dictionary representation of vApp object.
Return type: dict
-
pyvcloud.vcd.utils.
vdc_to_dict
(vdc, access_control_settings=None)¶ Convert a lxml.objectify.ObjectifiedElement org vdc object to a dict.
Parameters: - vdc (lxml.objectify.ObjectifiedElement) – an object containing EntityType.VDC XML data.
- access_control_settings (lxml.objectify.ObjectifiedElement) – an object containing EntityType.CONTROL_ACCESS_PARAMS XML data.
Returns: dictionary representation of the org vdc.
Return type: dict