To make the library content available for other vCenter Server instances across the vSphere Automation environment, you must publish the library. Depending on your workflow, select a method for publishing the local library. You can publish a local library that already exists in your vSphere Automation environment.

Procedure

  1. Retrieve a reference to the LocalLibrary service.
  2. Retrieve an existing local library by using the library ID.
  3. Create a PublishInfo instance to define how the library is published.
  4. Specify the authentication method to be used by a subscribed library to authenticate to the local library. You can enable either basic authentication or no authentication. Basic authentication requires a user name and password.
  5. (Optional) If you publish the library with basic authentication, you must specify a user name and password for the PublishInfo instance, which must be used for authentication.
    Important: Use the predefined user name vcsp or leave the user name undefined. You must set only a password to protect the library.
  6. Set the local library to published.
  7. Use the retrieved local library to configure it with the PublishInfo instance.
  8. Update the properties of the LibraryModel object returned for the local library.

Example

Java
This example is based on the code in the LibraryPublishSubscribe.java sample file.

This example uses the steps that are described in the Publish an Existing 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.
...

// Access the LocalLibrary service.
      LocalLibrary localLibraryService = this.vapiAuthHelper.getStubFactory().createStub(LocalLibrary.class, sessionStubconfig);

// Retrieve an existing local library.
      LibraryModel libraryModel = localLibraryService.get(libraryId);
      PublishInfo publishInfo = new PublishInfo();

// Configure how the local library is published by using BASIC authentication.
      publishInfo.setUserName("vcsp");
      publishInfo.setPassword("password".toCharArray());
      publishInfo.setAuthenticationMethod(AuthenticationMethod.BASIC);

// Set the local library to published and update the library instance.
      publishInfo.setPublished(true);
      libraryModel.setPublishInfo(publishInfo);
      localLibraryService.update(libraryModel.getId(), libraryModel);
Python
This example is based on the code in the library_publish_subscribe.py sample file.

This example uses the steps that are described in the Publish an Existing Content Library procedure.

Note: For a complete and up-to-date version of the sample code, see the vsphere-automation-sdk-python VMware repository at GitHub.
...
 
# Retrieve an existing local library.
local_library_stub = content_client.LocalLibrary(my_stub_config)
local_library = local_library_stub.get(my_library_id)
 
# Specify how the local library is published, using BASIC authentication.
publish_info = library_client.PublishInfo()
publish_info.user_name = ’vcsp’ # Can omit this value; if specified, it must be ’vcsp’.
publish_info.password = ’password’
publish_info.authentication_method = library_client.PublishInfo.AuthenticationMethod.BASIC
publish_info.published = True
 
# Update the LibraryModel object retieved in step 1
# and configure it with the PublishInfo object.
local_library.publish_info = publish_info
 
# Use the LibraryModel object to update the library instance.
local_library_stub.update(library_id=my_library_id,
update_spec=local_library)