pyvss

pyvss

Manager

This module sends request to the ITS Private Cloud API.

API Reference.

class pyvss.manager.VssManager(tk=None, api_endpoint=None, debug=False, timeout=None, dry_run=False)

Bases: object

Class containing methods to interact with the VSS REST API.

Example:

vss = VssManager(tk='access-token') vss.whoami() vss.ping()

If tk is none it will get the token from the VSS_API_TOKEN environment variable.

Example:

vss = VssManager() vss.whoami()

DELETE = 'DELETE'

GET = 'GET'

OPTIONS = 'OPTIONS'

PATCH = 'PATCH'

POST = 'POST'

PUT = 'PUT'

ack_user_message(m_id)

Acknowledge given user message.

Parameters:

m_id (int) – message id

Returns:

message object

ack_vm_alarm(vm_id, moref, **kwargs)

Acknowledge given Virtual Machine triggered alarm.

Parameters:

  • vm_id (str) – virtual machine moref or uuid

  • moref – Virtual Machine Alarm managed object reference

Returns:

change request object

keyword arguments include schedule to process request on a given date and time

cancel_retirement_request(request_id: int)

Cancel retirement request.

cancel_scheduled_change_request(request_id)

Cancel scheduled execution of a given change request.

Parameters:

request_id (int) – Change request id

Returns:

request status

clear_vm_alarm(vm_id, moref, **kwargs)

Clear given Virtual Machine alarm.

Parameters:

  • vm_id (str) – virtual machine moref or uuid

  • moref – Virtual Machine Alarm managed object reference

Returns:

change request object

keyword arguments include schedule to process request on a given date and time

confirm_retirement_request(request_id: int)

Confirm retirement request.

Parameters:

request_id (int) – retirement request id

Returns:

object

consolidate_vm_disks(vm_id, **kwargs)

Submit a Virtual Machine disk consolidation request.

Parameters:

vm_id – virtual machine moref or uuid

Returns:

change request object

keyword arguments include schedule to process request on a given date and time

create_folder(moref, name)

Create logical folder under given managed object reference.

Parameters:

  • moref (str) – Parent folder managed object id

  • name (str) – New folder name

Returns:

folder request object

create_inventory_file(props=None, filters=None, transfer=False, fmt='json')

Submit a request to generate a full inventory report of your VMs.

The report will be transferred if set to your space at VSKEY-STOR and also be available via download_inventory_result().

Parameters:

  • props (list) – properties to include in report. exec get_inventory_properties() to get a full list.

  • transfer (bool) – whether to transfer to personal store at vskey-stor

  • fmt (str) – report format <json|csv>. default json

  • filters (list) – Filters to add in the inventory report. attr:value format.

Returns:

inventory request object

See Inventory Docs for more information

create_user_ssh_key(public_key)

Create a new SSH Public Key entry.

Parameters:

public_key (str) – SSH Public Key string

Returns:

 

create_user_ssh_key_path(public_key_path)

Create a new SSH Public Key entry from file path.

Parameters:

public_key_path (str) – Full path to SSH Public Key string

Returns:

 

create_vm(os: str, built: str, client: str, description: str, folder: str, networks: List[Dict], disks: List[int] | List[Dict], scsi: List[str] | List[Dict] | None = None, name: str | None = None, iso: str | None = None, notes: Dict | None = None, usage: str | None = 'Test', cpu: int | Dict | None = 1, memoryGB: int = 1, vss_service: str | None = None, extra_config: List[Dict] | None = None, power_on: bool | None = False, template: bool | None = False, firmware: str | None = None, tpm: bool | None = False, storage_type: str | None = False, retirement: Dict | None = None, **kwargs)

Create single Virtual Machine.

Parameters:

  • os (str) – Operating system id.

  • built – built process

  • client (str) – Client department

  • description (str) – VM description

  • folder (str) – Target VM folder moref

  • networks – list of network adapter objects created based on the network index, then first item in the list is mapped to network adapter 1. If not specified, will be same as source.

Example:

{'network': 'moref', 'type': 'valid_type'}

Parameters:

  • disks (list) –

    list of disk sizes in gb or list of disk specification including capacity_gb, backing_mode and backing_sharing.

    Example:

    {"capacity_gb": 100, "backing_mode": "persistent"} {"capacity_gb": 500, "backing_mode": "independent_persistent"}

     

  • scsi (list) –

    list of scsi controllers types or list of scsi specification including type, bus and sharing.

    Example:

    {"type": "lsilogic", "bus": 0} {"type": "paravirtual", "bus": 1}

     

  • name (str) – name of the new virtual machine

  • iso (str) – ISO image path to be mounted after creation

  • notes (dict) – Custom Notes in key value format to store in the Virtual Machine annotation as meta-data.

  • usage (str) – virtual machine usage

  • cpu (int, dict) –

    vCPU count or count and core per socket configuration

    Example:

    {"count": 4, "cores_per_socket": 2}

     

  • memoryGB (int) – Memory size in GB

  • vss_service (str or int) – VSS Service definition.

  • extra_config (list) – Set VMware guestinfo interface which are available to the VM guest operating system via VMware Tools These properties are stored within the VMX prefixed with “guestinfo.” string. This parameter also can include supported properties available from get_supported_extra_cfg_options().

  • power_on (bool) – Power on virtual machine after successful deployment

  • template (bool) – Mark resulting vm as template.

  • firmware (str) – type of firmware to use. Supported types are available get_supported_firmware_types().

  • retirement (dict) – vm retirement payload. Expected either get_retirement_datetime_spec() or get_retirement_timedelta_spec().

  • tpm (bool) – add trusted platform module to virtual machine.

  • storage_type (str) – type of storage to use. Supported types are available: get_supported_storage_types().

  • kwargs – key value arguments

Returns:

new request object

See also

get_os() for os parameter,

get_images() for image, get_folder() for folder, get_networks() for networks, get_vss_services() for vss_service, get_retirement_datetime_spec() or

get_retirement_timedelta_spec() for retirement.

more information about required attributes available in Virtual Machine

create_vm_cd(vm_id, backings=None, **kwargs)

Create CD/DVD drives.

By default it creates a single CD/DVD unit backed by client pass-through.

Parameters:

  • vm_id (str) – virtual machine moref or uuid

  • backings – either client or iso path or iso image id. I.e [“client”, “iso_id_or_path”]

  • backings – list

  • kwargs

Returns:

change request object

keyword arguments include schedule to process request on a given date and time

create_vm_custom_spec(vm_id, custom_spec, **kwargs)

Create a custom specification for a given virtual machine.

Parameters:

  • vm_id (str) – virtual machine moref or uuid

  • custom_spec (dict) – OS customization specification. Required if the resulting virtual machine needs to be reconfigure upon first boot. The current version of VMware Tools must be installed on the virtual machine or template to customize the guest operating system during cloning or deployment.

  • kwargs

Returns:

 

Virtual machine must be powered on and VMware Tools must be installed.

See also

get_custom_spec() for customization specification.

create_vm_disk(vm_id, disks, **kwargs)

Create virtual machine disks with a given specs.

For every value in GB in the list a virtual disk will be assigned.

Example:

disks = [40, 100, 50] or disks = [ {"capacity_gb": 40}, { "capacity_gb": 100, "backing_mode": "independent_persistent", "backing_vmdk": "[vssUser-xfers] vskey/<user>/FOLDER/disk-0.vmdk" }, ] vss.create_vm_disk(vm_id, disks=disks)

Parameters:

  • vm_id (str) – virtual machine moref or uuid

  • disks (list) – a list of disk capacities in GB or disk specs.

Returns:

change request object

keyword arguments include schedule to process request on a given date and time

create_vm_extra_cfg_options(vm_id, options)

Create VM extra configuration settings.

Extra configuration options are either guestinfo.* or allowed options.

Extra config guestinfo.* options can be queried from the Guest Operating system using VMware Tools:

Example:

vmtoolsd --cmd "info-get guestinfo.<option>"

Parameters:

  • vm_id (str) – virtual machine moref or uuid

  • options – list of dictionaries with key-value options to create.

University of Toronto - Since 1827