Use the vSphere Automation API to create queries for libraries that match your criteria. You can also retrieve a list of all libraries or only the libraries of a specific type.

Listing All Content Libraries

You can retrieve a list of all content library IDs in your virtual environment, regardless of their type, by using the Library service.

You can use the list function to retrieve all local and subscribed libraries in your system.
Java
This example shows how to retrieve a list of all content libraries.

This example uses the steps that are described in Listing All Content Libraries.

Note: For a complete and up-to-date version of the Java sample code, see the vsphere-automation-sdk-java VMware repository at GitHub.
...
 
// Access the Library Service.
   Library libraryService = vapiAuthHelper.getStubFactory().createStub(Library.class, sessionStubConfig);

// List all content libraries.
   List<String> allLibraries = libraryService.list();
   System.out.println("List of all library identifiers: /n");
   for (String cl : allLibraries) {
         System.out.println(cl);
   }
Python
This example shows how to retrieve a list of all content libraries.

This example uses the steps that are described in Listing All Content Libraries.

Note: For a complete and up-to-date version of the sample code, see the vsphere-automation-sdk-python VMware repository at GitHub.
...
 
library_stub = content_client.Library(my_stub_config)
libraries = library_stub.list()
print(’List of all library identifiers:’)
for library_id in library_ids :
  library = library_stub.get(library_id)
  print(’Library ID {}: {}’.format(library_id, library.name))

Listing Content Libraries of a Specific Type

You can use the vSphere Automation API to retrieve content libraries of a specific type. For example, you can list only the local libraries in your virtual environment.

If you want to retrieve only a list of the local libraries, you must retrieve the LocalLibrary service and use the list function on the LocalLibrary service. To list only subscribed libraries, you must retrieve the SubscribedLibrary service and call the list function on the SubscribedLibrary service.

Listing Content Libraries by Using Specific Search Criteria

You can filter the list of content libraries and retrieve only the libraries that match your specific criteria. For example, you might want to publish all local libraries with a specific name.

To a filter with specific search criteria, call the find (find_spec) function of the Library service. Pass as argument a LibraryTypes.FindSpec instance that contains your search criteria. Upon a successful completion of the call, you receive a list of all content libraries that match your search criteria.

Java
This example retrieves a list of all local libraries with the name AcmeLibrary that exist in your virtual environment.
Note: For related code samples, see the vsphere-automation-sdk-java VMware repository at GitHub.
...

// Create a FindSpec instance to set your search criteria.
   FindSpec findSpec = new FindSpec();

// Filter the local content libraries by using a library name. 
   findSpec.setName("AcmeLibrary");
   findSpec.setType(LibraryType.LOCAL);
   List<String> ids = libraryService.find(findSpec);
Python
This example retrieves a list of all local libraries with the name AcmeLibrary that exist in your virtual environment.
Note: For related code samples, see the vsphere-automation-sdk-python VMware repository at GitHub.
...
 
# Create a FindSpec object to specify your search criteria.
find_spec = content_client.Library.FindSpec()
find_spec.name = ’AcmeLibrary’
find_spec.type = content_client.LibraryModel.LibraryType.LOCAL
 
# Invoke the find() function by using the FindSpec instance.
library_stub = content_client.Library(my_stub_config)
library_ids = library_stub.find(find_spec)