pyvcloud.vcd.vapp module

class pyvcloud.vcd.vapp.VApp(client, name=None, href=None, resource=None)

Bases: object

add_access_settings(access_settings_list=None)

Add access settings to a particular vapp.

Parameters:access_settings_list

(list of dict): list of access_setting in the dict format. Each dict contains: - type: (str): type of the subject. Only ‘user’ allowed for vapp. - name: (str): name of the user. - access_level: (str): access_level of the particular subject. One

of ‘ReadOnly’, ‘Change’, ‘FullControl’
Returns:A lxml.objectify.StringElement object representing

the updated access control setting of the vapp.

add_disk_to_vm(vm_name, disk_size)

Add a virtual disk to a virtual machine in the vApp.

It assumes that the VM has already at least one virtual hard disk
and will attempt to create another one with similar characteristics.
Parameters:
  • vm_name – (str): The name of the vm to be customized.
  • disk_size – (int): The size of the disk to be added, in MBs.
Returns:

A lxml.objectify.StringElement object describing the asynchronous Task creating the disk.

Raises:

Exception: If the named VM cannot be located or another error occured.

add_vms(specs, deploy=True, power_on=True, all_eulas_accepted=None)

Recompose the vApp and add VMs.

Parameters:
  • specs – An array of VM specifications, see to_sourced_item() method for specification details.
  • deploy – (bool): True if the vApp should be deployed at instantiation
  • power_on – (bool): True if the vApp should be powered-on at instantiation
  • all_eulas_accepted – (bool): True confirms acceptance of all EULAs in the vApp.
Returns:

A lxml.objectify.StringElement object representing a sparsely populated vApp element.

attach_disk_to_vm(disk_href, vm_name)

Attach the independent disk to the VM with the given name.

Parameters:
  • disk_href – (str): The href of the disk to be attached.
  • vm_name – (str): The name of the VM to which the disk will be attached.
Returns:

A lxml.objectify.StringElement object describing the asynchronous Task of attaching the disk.

Raises:

Exception: If the named VM cannot be located or another error occurs.

change_owner(href)

Change the ownership of vApp to a given user.

Parameters:href – Href of the new owner or user.
Returns:None.
connect_org_vdc_network(orgvdc_network_name, retain_ip=None, is_deployed=None, fence_mode='bridged')

Connect the vapp to an orgvdc network.

Parameters:
  • orgvdc_network_name – (str): name of the orgvdc network to be connected
  • retain_ip – (bool): True if the network resources such as IP/MAC of router will be retained across deployments.
  • is_deployed – (bool): True if this orgvdc network has been deployed.
  • fence_mode – (str): Controls connectivity to the parent network. One of bridged, isolated or natRouted. bridged by default.
Returns:

A lxml.objectify.StringElement object representing the asynchronous task that is connecting the network.

Raises:

Exception: If orgvdc network does not exist in the vdc or if

it is already connected to the vapp.

connect_vm(mode='DHCP', reset_mac_address=False)
delete_vms(names)

Recompose the vApp and delete VMs.

Parameters:names – A list or tuple of names (str) of the VMs to delete from the vApp.
Returns:A lxml.objectify.StringElement object representing a sparsely populated vApp element.
deploy(power_on=None, force_customization=None)

Deploys the vApp.

Deploying the vApp will allocate all resources assigned to the vApp. TODO: Add lease_deployment_seconds param after PR 2036925 is fixed. https://jira.eng.vmware.com/browse/VCDA-465 :param power_on: (bool): Specifies whether to power on/off vapp/VM

on deployment. True by default, unless otherwise specified. :param lease_deployment_seconds: (str): Deployment lease in seconds. :param force_customization: (bool): Used to specify whether to force

customization on deployment, if not set default value is false.

Returns:A lxml.objectify.StringElement object describing the asynchronous Task deploying the vApp.
detach_disk_from_vm(disk_href, vm_name)

Detach the independent disk from the VM with the given name.

Parameters:
  • disk_href – (str): The href of the disk to be detached.
  • vm_name – (str): The name of the VM to which the disk will be detached.
Returns:

A lxml.objectify.StringElement object describing the asynchronous Task of detaching the disk.

Raises:

Exception: If the named VM cannot be located or another error occurs.

disconnect_org_vdc_network(orgvdc_network_name)

Disconnect the vapp from an orgvdc network.

Parameters:orgvdc_network_name – (str): name of the orgvdc network to be disconnected.
Returns:A lxml.objectify.StringElement object representing the asynchronous task that is disconnecting the network.
Raises:Exception: If orgvdc network is not connected to the vapp.
get_access_settings()

Get the access settings of the vapp.

Returns:A lxml.objectify.StringElement object representing the access settings of the vapp.
get_admin_password(vm_name)
get_all_networks()

Helper method that returns the list of networks defined in the vApp.

Returns:A lxml.objectify.StringElement object with the list of vApp networks.
get_all_vms()

Retrieve all the VMs in this vApp.

Returns:([vmType]) A array of lxml.objectify.StringElement object describing the requested VMs.
get_metadata()
get_primary_ip(vm_name)
get_resource()
get_vapp_network_name(index=0)

Returns the name of the network defined in the vApp by index.

Parameters:index – (int): The index of the vApp network to retrieve. 0 if omitted.
Returns:A string with the name of the requested network if exists.
get_vm(vm_name)

Retrieve the VM with the given name in this vApp.

Parameters:vm_name – (str): The name of the VM.
Returns:(vmType) A lxml.objectify.StringElement object describing the requested VM.
get_vm_moid(vm_name)
power_off()
power_on()
power_reset()

Resets a vApp.

Returns:A lxml.objectify.StringElement object describing the asynchronous Task resetting the vApp.
reboot()

Reboots the vApp.

Returns:A lxml.objectify.StringElement object describing the asynchronous Task rebooting the vApp.
reload()
remove_access_settings(access_settings_list=None, remove_all=False)

Remove access settings from a particular vapp.

Parameters:
  • access_settings_list – (list of dict): list of access_setting in the dict format. Each dict contains: - type: (str): type of the subject. Only ‘user’ allowed for vapp. - name: (str): name of the user.
  • remove_all – (bool) : True if all access settings of the vapp should be removed
Returns:

A lxml.objectify.StringElement object representing the updated access control setting of the vapp.

set_lease(deployment_lease=0, storage_lease=0)
set_metadata(domain, visibility, key, value, metadata_type='MetadataStringValue')
share_with_org_members(everyone_access_level='ReadOnly')

Share the vapp to all members of the organization.

Parameters:everyone_access_level – (str) : access level when sharing the vapp with everyone. One of ‘ReadOnly’, ‘Change’, ‘FullControl’. ‘ReadOnly’ by default.
Returns:A lxml.objectify.StringElement object representing the updated access control setting of the vapp.
shutdown()

Shutdown the vApp.

Returns:A lxml.objectify.StringElement object describing the asynchronous Task shutting down the vApp.
to_sourced_item(spec)

Creates a VM SourcedItem from a VM specification.

Parameters:spec

(dict) containing: vapp: (resource): (required) source vApp or vAppTemplate resource source_vm_name: (str): (required) source VM name target_vm_name: (str): (optional) target VM name hostname: (str): (optional) target guest hostname password: (str): (optional) set the administrator password of this

machine to this value
password_auto: (bool): (optional) autogenerate administrator
password
password_reset: (bool): (optional) True if the administrator
password for this virtual machine must be reset after first use

cust_script: (str): (optional) script to run on guest customization network: (str): (optional) Name of the vApp network to connect.

If omitted, the VM won’t be connected to any network
storage_profile: (str): (optional) the name of the storage profile
to be used for this VM
Returns:SourcedItem: (lxml.objectify.StringElement): object representing the ‘SourcedItem’ xml object created from the specification.
undeploy(action='default')
unshare_from_org_members()

Unshare the vapp from all members of current organization.

Returns:A lxml.objectify.StringElement object representing the updated access control setting of the vapp.