You can create a local content library programmatically by using the vSphere Automation API. The API allows you to populate the content library with OVF and vApp templates. You can use these templates to deploy virtual machines or vApps in your virtual environment.
Prerequisites
- vCenter Server instance where you want to create the library. on the
- on the destination datastore.
Procedure
Results
What to do next
- Java
-
This example is based on the code in the
LibraryCrud.java sample file.
This example uses the steps that are described in the Create a Local Content Library procedure.
Note: For a complete and up-to-date version of the Java sample code, see the vsphere-automation-sdk-java VMware repository at GitHub.... // Create a StorageBacking instance to back the library content on the local file system. StorageBacking libraryBacking = new StorageBacking(); libraryBacking.setType(Type.OTHER); libraryBacking.setStorageUri(URI.create("file:///tmp")); libraryModel.setStorageBackings(Collections.singletonList(libraryBacking)); // Create a LibraryModel that represents a local library. LibraryModel libraryModel = new LibraryModel(); libraryModel.setType(LibraryModel.LibraryType.LOCAL); libraryModel.setName("AcmeLibrary"); // Access the LocalLibrary service by using the endpoint. LocalLibrary localLibraryService = this.vapiAuthHelper.getStubFactory().createStub(LocalLibrary.class, sessionStubconfig); // Call the create method of the LocalLibrary service passing as an // argument the LibraryModel instance. String libraryId = localLibraryService.create(UUID.randomUUID().toString(), libraryMod
- Python
-
This example creates a local library with name
AcmeLibrary , which is stored on the local file system where
vCenter Server runs.
This example uses the steps that are described in the Create a Local Content Library procedure.
Note: For related code samples, see the vsphere-automation-sdk-python VMware repository at GitHub.... # 1 - Create a storage backing instance on a local file system. library_backing = library_client.StorageBacking() library_backing.type = library_client.StorageBacking.Type.OTHER library_backing.storage_uri = ’file:///tmp’ # 2 - Create a Library model to specify properties of the new library. library_model = content_client.LibraryModel() library_model.type = content_client.LibraryModel.LibraryType.LOCAL library_model.name = ’AcmeLibrary’ library_model.storage_backings = [library_backing] # 3 - Call the create() method, passing the library model as a parameter. idem_token = str(uuid.uuid4()) local_library_stub = content_client.LocalLibrary(my_stub_config) library_id = local_library_stub.create(create_spec=library_model, client_token=idem_token)