COT.vm_description.ovf.utilities module

Module providing utility functions for OVF and OVA handling.

Functions

int_bytes_to_programmatic_units Convert a byte count into OVF-style bytes + multiplier.
parse_manifest Parse the given manifest file contents into a dictionary.
programmatic_bytes_to_int Convert a byte value expressed in programmatic units to the raw number.
int_bytes_to_programmatic_units(byte_value)[source]

Convert a byte count into OVF-style bytes + multiplier.

Inverse operation of programmatic_bytes_to_int()

Parameters:byte_value (int) -- Number of bytes
Returns:tuple -- (base_value, programmatic_units)

Examples

>>> int_bytes_to_programmatic_units(2147483648)
('2', 'byte * 2^30')
>>> int_bytes_to_programmatic_units(2147483647)
('2147483647', 'byte')
>>> int_bytes_to_programmatic_units(134217728)
('128', 'byte * 2^20')
>>> int_bytes_to_programmatic_units(134217729)
('134217729', 'byte')
parse_manifest(manifest_text)[source]

Parse the given manifest file contents into a dictionary.

Parameters:manifest_text (str) -- Contents of an OVF manifest file
Returns:dict -- Mapping of filename to (algorithm, checksum_string)

Examples

>>> result = parse_manifest(
... "SHA1(package.ovf)= 237de026fb285b85528901da058475e56034da95\n"
... "SHA1(vmdisk1.vmdk)= 393a66df214e192ffbfedb78528b5be75cc9e1c3\n"
... )
>>> sorted(result.keys())
['package.ovf', 'vmdisk1.vmdk']
>>> result["package.ovf"]
('SHA1', '237de026fb285b85528901da058475e56034da95')
>>> result["vmdisk1.vmdk"]
('SHA1', '393a66df214e192ffbfedb78528b5be75cc9e1c3')
programmatic_bytes_to_int(base_value, programmatic_units)[source]

Convert a byte value expressed in programmatic units to the raw number.

Inverse operation of int_bytes_to_programmatic_units().

Parameters:
  • base_value (str) -- Base value string (value of ovf:capacity, etc.)
  • programmatic_units (str) -- Programmatic units string (value of ovf:capacityAllocationUnits, etc.)
Returns:

int -- Number of bytes

Examples

>>> programmatic_bytes_to_int("128", "byte")
128
>>> programmatic_bytes_to_int("1", "byte * 2^10")
1024
>>> programmatic_bytes_to_int("128", "byte * 2^20")
134217728
>>> programmatic_bytes_to_int("512", "MegaBytes")
536870912