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.
Prerequisites
- Create a new local content library or retrieve the desired existing content library.
- Required privileges: item and on the library.
Procedure
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.
... # 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.
Prerequisites
- Create a new local content library or retrieve the desired existing content library.
- Required privileges: and on the library.
Procedure
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.
... # 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)