You can use the objects and methods provided by the Content Library API to manage OVF and OVA packages.

Open Virtualization Format (OVF) is an industry standard that describes metadata about a virtual machine image in an XML format. An OVF package includes an XML descriptor file and optionally disk images, resource files (such as ISO files), manifest files, and certificate files.

An OVA package is a single file that contains all OVF package files in an archived form. After you upload an OVA package to a content library, the OVA file is converted to the standard OVF package.

When you try to upload signed content to a content library, you might receive preview warnings. Signed content can be either OVF or OVA packages that contain manifest and certificate files. If you do not respond to the preview warnings, the upload fails. To complete an upload operation successfully, you must ignore any preview warnings by using the WarningBehavior class.

With the vSphere Automation API, you can use the OVF package in a content library to deploy virtual machines and vApps on hosts, resource pools, and clusters. You can also use the API to create OVF packages in content libraries from vApps and virtual machines on hosts, resource pools, and clusters.

When you create library items to store OVF packages, you must set the item type to ovf. To comply with the specific standards of the OVF packages, the vSphere Automation API provides the LibraryItem class.

Working with OVF and OVA Packages in a Content Library

You can upload an OVF or OVA package to a library item by using the UpdateSession interface. You can also download an OVF and OVA packages from a content library to your local file system.

In case you want to upload an OVF package, the location of the content determines whether you can pull the content from a URL or push the content directly to a content library. For information about uploading content to library items, see Upload a File from a Local System to a Library Item and Upload a File from a URL to a Library Item.

To download the files that are included in an OVF or OVA package to your local file system, use the DownloadSession interface. For more information, see Download Files to a Local System from a Library Item.

Upload an OVF or an OVA Package from a URL to a Library Item

You can upload an OVF or an OVA package from a Web server to a library item.

Note: If you try to upload a signed OVF package and it returns preview warnings, you must ignore the preview warnings to complete the upload.

Prerequisites

  • Create a new local content library or retrieve the desired existing content library.
  • Required privileges: Content library.Add library item and Content library.Update files on the library.

Procedure

  1. Create an empty library item.
  2. Create an update session object.
  3. Create an AddSpec object to describe the properties and the upload location of the OVF descriptor file or of the OVA package file.
  4. Link the AddSpec object to the update session.
    All files that are included in the OVF package are automatically uploaded.
  5. Complete the asynchronous transfer.

Python Example of Uploading an OVF Package from a URL to a Library Item

This example is based on the ovf_import_export.py sample file.

This example uses the steps that are described in the Upload an OVF or an OVA Package from a URL to a Library Item procedure.

Note: For a complete and up-to-date version of the sample code, see the vsphere-automation-sdk-python VMware repository at GitHub.
...

# 1 - Create a empty library item to describe the virtual machine.
item_model = library_client.ItemModel()
item_model.name = “ubuntu-vm”
item_model.description = “ubuntu 7.0”
item_model.library_id = my_library_id
item_model.type = “ovf”
client_token = str(uuid.uuid4())
item_stub = library_client.Item(my_stub_config)
item_id = item_stub.create(create_spec=item_model,
client_token=client_token)

# 2 - Create an update session.
update_session_model = item_client.UpdateSessionModel()
update_session_model.library_item_id = item_id
client_token = str(uuid.uuid4())
update_session_stub = update_session_client.UpdateSession(my_stub_config)
session_id = update_session_stub.create(create_spec=update_session_model,
client_token=client_token)

# 3 - Create a file specification for the OVF envelope file.
file_spec = update_session_client.AddSpec()
file_spec.name = “ubuntu.ovf”
file_spec.source_type = File.SourceType.PULL
endpoint = item_client.TransferEndpoint()
endpoint.uri = “http://www.example.com/images/ubuntu.ovf”
file_spec.source_endpoint = endpoint

# 4 - Link the file specification to the update session.
update_file_stub = update_session_client.File(my_stub_config)
update_file_stub.File.add(update_session_id=session_id,
file_spec=file_spec)

# 5 - Initiate the asynchronous transfer.
update_session_stub.complete(session_id)

Upload an OVF or OVA Package from a Local File System to a Library Item

You can upload an OVF or OVA package from a local file system. This procedure describes how to use the AddSpec object after you have created a library item and initiated an update session.

Note: If you try to upload a signed OVF package and it returns preview warnings, you must ignore the preview warnings to complete the upload.

Prerequisites

  • Create a new local content library or retrieve the desired existing content library.
  • Required privileges: Content library.Add library item and Content library.Update files on the library.

Procedure

  1. Create a library item.
  2. Create an update session.
  3. Create an AddSpec object to describe the properties and the upload locations of the OVF descriptor file or of the OVA package file.
  4. Link the AddSpec object to the update session.
  5. (Optional) Create an AddSpec object for each VMDK file included in the OVF package.
  6. Add all AddSpec objects to the update session.
    If you upload an OVF package and it has a VMDK file included, you must repeat steps 5 and 6. If you are uploading a signed OVF package, steps 5 and 6 must also be repeated for the manifest and certificate files included in the OVF package.
  7. Initiate the upload operation.
  8. Complete the update session.
  9. Delete the session.

Python Example of Uploading an OVA Package to a Library Item

This example is based on the signed_ova_import.py sample file.

This example uses the steps that are described in the Upload an OVF or OVA Package from a Local File System to a Library Item procedure.

Note: For a complete and up-to-date version of the sample code, see the vsphere-automation-sdk-python VMware repository at GitHub.
...

# 1 - Specify the OVA filename and location.
SIGNED_OVA_FILENAME = 'nostalgia-signed.ova'
SIGNED_OVA_RELATIVE_DIR = '../resources/signedOvaWithCertWarning'

# 2 - Create a new library item in the content library for uploading the files.
self.lib_item_id = self.helper.create_library_item(library_id=self.local_lib_id,
                                                   item_name=self.lib_item_name,
                                                   item_description='Sample template from ova file',
                                                   item_type='ovf')

# 3 - Set a pointer to the OVA file you want to upload.
ova_file_map = self.helper.get_ova_file_map(self.SIGNED_OVA_RELATIVE_DIR,
                                            local_filename=self.SIGNED_OVA_FILENAME)

# 4 - Create a new update session for uploading the files.
session_id = self.client.upload_service.create(
    create_spec=UpdateSessionModel(library_item_id=self.lib_item_id),
    client_token=generate_random_uuid())
self.helper.upload_files_in_session(ova_file_map, session_id)

# 5 - Wait for terminal preview state and obtain preview warnings.
self.wait_for_terminal_preview_state(session_id, AVAILABLE)
session = self.client.upload_service.get(session_id)
preview_info = session.preview_info

# 6 - Ignore preview warnings on session, if any.
ignore_warning_behaviors = []
for warning_type in preview_warning_types:
    warning_behavior = WarningBehavior(type=warning_type, ignored=True)
    ignore_warning_behaviors.append(warning_behavior)
self.client.upload_service.update(session_id, update_spec=UpdateSessionModel(
    warning_behavior=ignore_warning_behaviors))

# 7 - Complete the update session.
self.client.upload_service.complete(session_id)

# 8 - Delete the session.
self.client.upload_service.delete(session_id)