pyvcloud.vcd.org module

class pyvcloud.vcd.org.Org(client, href=None, resource=None)

Bases: object

add_catalog_access_settings(catalog_name, access_settings_list=None)

Add access settings to a particular catalog.

Parameters:
  • catalog_name (str) – name of the catalog to which access settings needs to be added.
  • access_settings_list (list) –

    list of access_setting in the dict format. Each dict contains:

    • type: (str): type of the subject. Value must be either ‘org’
      or ‘user’.
    • name: (str): name of the user or organization.
    • access_level: (str): access_level of the particular subject.
      Acceptable values are ‘ReadOnly’, ‘Change’ or ‘FullControl’
Returns:

an object containing EntityType.CONTROL_ACCESS_PARAMS XML data representing the updated Access Control List of the catalog.

Return type:

lxml.objectify.ObjectifiedElement

add_rights(rights)

Adds set of rights to the organization.

Parameters:rights (tuple) – names of rights as strings.
Returns:an object containing EntityType.ORG_RIGHTS XML data representing the updated rights in the organization.
Return type:lxml.objectify.ObjectifiedElement
capture_vapp(catalog_resource, vapp_href, catalog_item_name, description, customize_on_instantiate=False, overwrite=False)

Capture vApp as a template into a catalog.

Parameters:
  • catalog_resource (lxml.objectify.ObjectifiedElement) – an object containing EntityType.CATALOG XML data representing the catalog to which we will add the new template.
  • vapp_href (str) – href of the vApp to capture.
  • catalog_item_name (str) – name of the target catalog item.
  • description (str) – description of the catalog item.
  • customize_on_instantiate (bool) – flag indicating if the vApp to be instantiated from this vApp template can be customized.
  • overwrite (bool) – flag indicating if the item in the catalog has to be overwritten if it already exists. If it doesn’t exist, this flag is not used.
Returns:

an object containing EntityType.VAPP_TEMPLATE XML data describing the captured template.

Return type:

lxml.objectify.ObjectifiedElement

change_catalog_owner(catalog_name, user_name)

Change the ownership of catalog to a given user.

This operation can be performed by only users with admin privileges.

Parameters:
  • catalog_name (str) – name of the catalog whose ownership needs to be changed
  • user_name (str) – name of the new owner of the catalog
create_catalog(name, description)

Create a catalog in the organization.

Parameters:
  • name (str) – name of the catalog to be created.
  • description (str) – description of the catalog to be created.
Returns:

an object containing EntityType.ADMIN_CATALOG XML data representing a sparsely populated catalog element.

Return type:

lxml.objectify.ObjectifiedElement

create_org_vdc(vdc_name, provider_vdc_name, description='', allocation_model='AllocationVApp', cpu_units='MHz', cpu_allocated=0, cpu_limit=0, mem_units='MB', mem_allocated=0, mem_limit=0, nic_quota=0, network_quota=0, vm_quota=0, storage_profiles=[], resource_guaranteed_memory=None, resource_guaranteed_cpu=None, vcpu_in_mhz=None, is_thin_provision=None, network_pool_name=None, uses_fast_provisioning=None, over_commit_allowed=None, vm_discovery_enabled=None, is_enabled=True)

Create an Organization VDC in the current organization.

Parameters:
  • vdc_name (str) – name of the new org vdc.
  • provider_vdc_name (str) – (str): The name of an existing provider vdc.
  • description (str) – description of the new org vdc.
  • allocation_model (str) – allocation model used by this vdc. Accepted values are ‘AllocationVApp’, ‘AllocationPool’ or ‘ReservationPool’.
  • cpu_units (str) – unit for compute capacity allocated to this vdc. Accepted values are ‘MHz’ or ‘GHz’.
  • cpu_allocated (int) – capacity that is committed to be available.
  • cpu_limit (int) – capacity limit relative to the value specified for allocation.
  • mem_units (str) – unit for memory capacity allocated to this vdc. Acceptable values are ‘MB’ or ‘GB’.
  • mem_allocated (int) – memory capacity that is committed to be available.
  • mem_limit (int) – memory capacity limit relative to the value specified for allocation.
  • nic_quota (int) – maximum number of virtual NICs allowed in this vdc. Defaults to 0, which specifies an unlimited number.
  • network_quota (int) – maximum number of network objects that can be deployed in this vdc. Defaults to 0, which means no networks can be deployed.
  • vm_quota (int) – maximum number of VMs that can be created in this vdc. Defaults to 0, which specifies an unlimited number.
  • storage_profiles (list) –

    list of provider vdc storage profiles to add to this vdc. Each item is a dictionary that should include the following elements:

    • name: (str): name of the PVDC storage profile.
    • enabled: (bool): True if the storage profile is enabled for
      this vdc.
    • units: (string): Units used to define limit. One of MB or GB.
    • limit: (int): Max number of units allocated for this storage
      profile.
    • default: (bool): True if this is default storage profile for
      this vdc.
  • resource_guaranteed_memory (float) – percentage of allocated CPU resources guaranteed to vApps deployed in this vdc. Value defaults to 1.0 if the element is empty.
  • resource_guaranteed_cpu (float) – percentage of allocated memory resources guaranteed to vApps deployed in this vdc. Value defaults to 1.0 if the element is empty.
  • vcpu_in_mhz (int) – specifies the clock frequency, in MegaHertz, for any virtual CPU that is allocated to a VM.
  • is_thin_provision (bool) – True to request thin provisioning.
  • network_pool_name (str) – name to a network pool in the provider vdc that this org vdc should use.
  • uses_fast_provisioning (bool) – True to request fast provisioning.
  • over_commit_allowed (bool) – False to disallow creation of the VDC if the AllocationModel is AllocationPool or ReservationPool and the ComputeCapacity specified is greater than what the backing provider VDC can supply. Defaults to True, if empty or missing.
  • vm_discovery_enabled (bool) – True, if discovery of vCenter VMs is enabled for resource pools backing this vdc.
  • is_enabled (bool) – True, if this vdc is enabled for use by the organization users.
Returns:

an object containing EntityType.VDC XML data describing the new VDC.

Return type:

lxml.objectify.ObjectifiedElement

create_role(role_name, description, rights)

Creates a role in the organization.

Parameters:
  • role_name (str) – name of the role to be created.
  • description (str) – description of the role.
  • rights (tuple) – names (as str) of zero or more rights to be associated with the role.
Returns:

an object containing EntityType.ROLE XML data describing the role just created.

Return type:

lxml.objectify.ObjectifiedElement

create_user(user_name, password, role_href, full_name='', description='', email='', telephone='', im='', alert_email='', alert_email_prefix='', stored_vm_quota=0, deployed_vm_quota=0, is_group_role=False, is_default_cached=False, is_external=False, is_alert_enabled=False, is_enabled=False)

Create a new user in the current organization.

Parameters:
  • user_name (str) – username of the new user.
  • password (str) – password of the new user (must be at least 6 characters long).
  • role_href (str) – href of the role for the new user.
  • full_name (str) – full name of the user.
  • description (str) – description for the user.
  • email (str) – email address of the user.
  • telephone (str) – The telephone of the user.
  • im (str) – instant message address of the user.
  • alert_email (str) – email address where alerts should be sent.
  • alert_email_prefix (str) – string to prepend to alert message subject line.
  • stored_vm_quota (str) – quota of vApps that this user can store.
  • deployed_vm_quota (str) – quota of vApps that this user can deploy concurrently.
  • is_group_role (bool) – indicates if the user has a group role.
  • is_default_cached (bool) – indicates if user should be cached.
  • is_external (bool) – indicates if user is imported from an external source.
  • is_alert_enabled (bool) – if, True will enable email alert for the user.
  • is_enabled (bool) – if True, will enable the user after creation else will let the user remain disabled after creation.
Returns:

an object containing EntityType.USER XML data describing the user that just got created.

Return type:

lxml.objectify.ObjectifiedElement

delete_catalog(name)

Delete a catalog in the organization.

Parameters:name (str) – name of the catalog to be deleted.
Raises:EntityNotFoundException: if the named catalog can not be found.
Raises:sub-class of VcdResponseException: if the REST call is not successful.
delete_catalog_item(name, item_name)

Delete an item from a catalog.

Parameters:
  • name (str) – name of the catalog whose item needs to be deleted.
  • item_name (str) – name of the item which needs to be deleted.
Raises:

EntityNotFoundException: if the catalog/named item can not be found.

delete_role(name)

Deletes specified role from the organization.

Parameters:name (str) – name of the role to be deleted.
delete_user(user_name)

Deletes an user from the current organization.

This operation needs admin privileges.

Parameters:user_name (str) – name of the user to be deleted.
download_catalog_item(catalog_name, item_name, file_name, chunk_size=1048576, callback=None, task_callback=None)

Downloads an item from a catalog into a local file.

Parameters:
  • catalog_name (str) – name of the catalog whose item needs to be downloaded.
  • item_name (str) – name of the item which needs to be downloaded.
  • file_name (str) – name of the target file on local disk where the contents of the catalog item will be downloaded to.
  • chunk_size (int) – size of chunks in which the catalog item will be downloaded and written to the disk.
  • callback (function) – a function with signature function(bytes_written, total_size) to let the caller monitor progress of the download operation.
  • task_callback (function) – a function with signature function(task) to let the caller monitor the progress of enable download task.
Returns:

number of bytes written to file.

Return type:

int

Raises:

EntityNotFoundException: if the catalog/named item is not found.

get_catalog(name, is_admin_operation=False)

Retrieves a catalog by name.

Parameters:
  • name (str) – name of the catalog to be retrieved.
  • is_admin_operation (bool) – if set True, will return the admin view of the catalog.
Returns:

an object containing EntityType.CATALOG or EntityType.ADMIN_CATALOG XML data representing the catalog.

Return type:

lxml.objectify.ObjectifiedElement

Raises:

EntityNotFoundException: if the named catalog can not be found.

get_catalog_access_settings(catalog_name)

Retrieve the access settings of a catalog.

Parameters:catalog_name (str) – name of the catalog.
Returns:an object containing EntityType.CONTROL_ACCESS_PARAMS XML data representing the Access Control List of the catalog.
Return type:lxml.objectify.ObjectifiedElement
get_catalog_item(name, item_name)

Retrieve an item in a catalog.

Parameters:
  • name (str) – name of the catalog whose item needs to be retrieved.
  • item_name (str) – name of the item which needs to be retrieved.
Returns:

an object containing EntityType.MEDIA or EntityTYPE.VAPP_TEMPLATE XML data describing the entity corresponding to the catalog item.

Return type:

lxml.objectify.ObjectifiedElement

Raises:

EntityNotFoundException: if the catalog/named item can not be found.

get_name()

Retrieves the name of the organization.

Returns:name of the organization.
Return type:str
get_right_record(right_name)

Retrieves corresponding record of the specified right.

Parameters:right_name (str) – name of the right record to be retrieved.
Returns:right record
Return type:dict
get_right_resource(right_name)

Retrieves resource of a given right.

Parameters:right_name (str) – name of the right.
Returns:an object containing EntityType.RIGHT XML data representing the right.
Return type:lxml.objectify.ObjectifiedElement
get_role_record(role_name)

Retrieve role record with a particular name in the current org.

Parameters:role_name (str) – name of the role object to be retrieved.
Returns:role record.
Return type:dict
Raises:EntityNotFoundException: if role with the given name is not found.
get_role_resource(role_name)

Retrieves XML resource of a given role.

Parameters:role_name (str) – name of the role to be retrieved.
Returns:an object containing EntityType.ROLE XML data representing the role.
Return type:lxml.objectify.ObjectifiedElement
get_user(user_name)

Retrieve info of an user in current organization.

Parameters:user_name (str) – name of the user whose info we want to retrieve.
Returns:an object containing EntityType.USER XML data describing the named user.
Return type:lxml.objectify.ObjectifiedElement
get_vdc(name)

Retrieves resource of an org vdc identified by its name.

Parameters:name (str) – name of the org vdc to be retrieved.
Returns:an object containing EtityType.VDC XML data representing the vdc.
Return type:lxml.objectify.ObjectifiedElement
Raises:EntityNotFoundException: if the named vdc can not be found.
list_catalog_items(name)

Retrieve all items in a catalog.

Parameters:name (str) – name of the catalog whose items need to be retrieved.
Returns:a list of dictionaries. Each dict object contains ‘name’ and ‘id’ of an item in the catalog.
Return type:dict
Raises:EntityNotFoundException: if the named catalog can not be found.
list_catalogs()

List all catalogs in the organization.

Returns:a list of dictionaries, where each item contains information about a catalog in the organization.
Return type:list
list_rights_available_in_system(name_filter=None)

Retrieves all rights available in the System organization.

Parameters:name_filter (tuple) – (tuple): filter rights by name. The first item in the tuple must be the string ‘name’ and the second item should be value of the filter as a str.
Returns:rights as a list of dictionaries, where each dictionary contains information about a single right.
Return type:list
list_rights_of_org()

Retrieves the list of rights associated with the current org.

Returns:rights as a list of dictionaries, where each dictionary contains information about a single right.
Return type:list
list_roles(name_filter=None)

Retrieve the list of roles in the current organization.

Parameters:name_filter (tuple) – (tuple): filter roles by name. The first item in the tuple must be the string ‘name’ and the second item should be value of the filter as a str.
Returns:dict objects, each object representing a single role. record.
Return type:list
list_users(name_filter=None)

Retrieve the list of users in the current organization.

Parameters:name_filter (2-tuple) – filters retrieved users by name. First item in the tuple needs to be the string ‘name’ and the second item should be the value of the filter.
Returns:user data in form of lxml.objectify.ObjectifiedElement objects, which contains QueryResultUserRecordType XML data.
Return type:generator object
list_vdcs()

List all vdc that are backing the current organization.

Returns:list of dictionaries, where each dictionary contains ‘name’ and ‘href’ of a vdc in the organization.
Return type:list
reload()

Reloads the resource representation of the organization.

This method should be called in between two method invocations on the Org object, if the former call changes the representation of the organization in vCD.

remove_catalog_access_settings(catalog_name, access_settings_list=None, remove_all=False)

Remove access settings from a particular catalog.

Parameters:
  • catalog_name (str) – name of the catalog from which access_settings need to be removed.
  • access_settings_list (list) –

    list of access_setting in the dict format. Each dict contains,

    • type: (str): type of the subject. Value must be either ‘org’
      or ‘user’.
    • name: (str): name of the user or organization.
  • remove_all (bool) – True, if all access settings of the catalog should be removed.
Returns:

an object containing EntityType.CONTROL_ACCESS_PARAMS XML data representing the updated Access Control List of the catalog.

Return type:

lxml.objectify.ObjectifiedElement

remove_rights(rights)

Removes set of rights from the organization.

Parameters:rights (tuple) – names of rights as strings.
Returns:an object containing EntityType.ORG_RIGHTS XML data representing the updated rights in the organization.
Return type:lxml.objectify.ObjectifiedElement
share_catalog(name, share=True)

Share a catalog with all org-admins of all organizations.

This operation can be performed by only System Administrators.

Parameters:name (str) – name of the catalog to be shared.
Raises:EntityNotFoundException: if the named catalog can not be found.
share_catalog_with_org_members(catalog_name, everyone_access_level='ReadOnly')

Share a catalog with all members of an organization.

Parameters:
  • catalog_name (str) – name of the catalog which needs to be shared.
  • everyone_access_level (str) – access level when sharing the catalog with everyone. Acceptable values are ‘ReadOnly’, ‘Change’, or ‘FullControl’. Default value is ‘ReadOnly’.
Returns:

an object containing EntityType.CONTROL_ACCESS_PARAMS XML data representing the updated Access Control List of the catalog.

Return type:

lxml.objectify.ObjectifiedElement

unshare_catalog_with_org_members(catalog_name)

Unshare a catalog from all members of the current organization.

Parameters:catalog_name (str) – name of the catalog which needs to be unshared from everyone.
Returns:an object containing EntityType.CONTROL_ACCESS_PARAMS XML data representing the updated Access Control List of the catalog.
Return type:lxml.objectify.ObjectifiedElement
update_catalog(old_catalog_name, new_catalog_name, description)

Update the name and/or description of a catalog.

Parameters:
  • old_catalog_name (str) – current name of the catalog.
  • new_catalog_name (str) – new name of the catalog.
  • description (str) – new description of the catalog.
Returns:

an object containing EntityType.ADMIN_CATALOG XML data describing the updated catalog.

Return type:

lxml.objectify.ObjectifiedElement

Raises:

EntityNotFoundException: if the named catalog can not be found.

update_org(is_enabled=None)

Update an organization to enable/disable it.

This operation can only be performed by an user with admin privileges.

Parameters:is_enabled (bool) – flag to enable/disable the organization.
Returns:an object containing EntityType.ADMIN_ORG XML data representing the updated organization.
Return type:lxml.objectify.ObjectifiedElement
update_user(user_name, is_enabled=None)

Update an user.

Parameters:
  • user_name (str) – username of the user.
  • is_enabled (bool) – True, to enable the user, False to disable the user.
Returns:

an object containing EntityType.USER XML data describing the user that just got updated.

Return type:

lxml.objectify.ObjectifiedElement

upload_media(catalog_name, file_name, item_name=None, description='', chunk_size=1048576, callback=None)

Uploads a media file to a catalog.

This method only uploads bits to vCD spool area, doesn’t block while vCD imports the uploaded bit into catalog.

Parameters:
  • catalog_name (str) – name of the catalog where the media file will be uploaded.
  • file_name (str) – name of the media file on local disk which will be uploaded.
  • item_name (str) – this param lets us rename the media file once uploaded to the catalog.If this param is not specified, the catalog item will share the same name as the media file being uploaded.
  • chunk_size (int) – size of chunks in which the file will be uploaded to the catalog.
  • callback (function) – a function with signature function(bytes_written, total_size) to let the caller monitor progress of the upload operation.
Returns:

number of bytes uploaded to the catalog.

Return type:

int

Raises:

EntityNotFoundException: if the catalog is not found.

Raises:

InternalServerException: if item already exists in catalog.

upload_ovf(catalog_name, file_name, item_name=None, description='', chunk_size=1048576, callback=None)

Uploads an ova file to a catalog.

This method only uploads bits to vCD spool area, doesn’t block while vCD imports the uploaded bit into catalog.

Parameters:
  • catalog_name (str) – name of the catalog where the ova file will be uploaded.
  • file_name (str) – name of the ova file on local disk which will be uploaded.
  • item_name (str) – this param let’s us rename the ova file once uploaded to the catalog. If this param is not specified, the catalog item will share the same name as the ova file being uploaded.
  • chunk_size (int) – size of chunks in which the file will be uploaded to the catalog.
  • callback (function) – a function with signature function(bytes_written, total_size) to let the caller monitor progress of the upload operation.
Returns:

number of bytes uploaded to the catalog.

Return type:

int

Raises:

EntityNotFoundException: if the catalog is not found.

Raises:

InternalServerException: if item already exists in catalog.