Edit the Settings of a Library Item

You can edit the name, description, and type of a library item.
Verify that you have access to the
Item
service.
  1. Retrieve the item that you want to update.
  2. Create an
    ItemModel
    instance.
  3. Change the human-readable name and description of the library item.
  4. Update the library item with the configured item model.
The settings of the library item are sucessfully edited.
Java
This example shows how to find an item by using the item name and then how to change the name and description of the retrieved item.
This example uses the steps that are described in the Edit the Settings of a Library Item procedure.
For related code samples, see the
vsphere-automation-sdk-java
VMware repository at GitHub.
... // List the items in a published library Item libItemService = this.vapiAuthHelper.getStubFactory().createStub(Item.class, sessionStubconfig); List<String> itemIds = libItemService.list(libraryId.getId()); for (String itemId : itemIds) { ItemModel singleItem = libItemService.get(itemId); // List the files uploaded to each library item and print their names and size com.vmware.content.library.item.File itemFilesService = this.vapiAuthHelper.getStubFactory().createStub(com.vmware.content.library.item.File.class, sessionStubconfig); List<com.vmware.content.library.item.FileTypes.Info> fileInfos = itemFilesService.list(itemId); for (com.vmware.content.library.item.FileTypes.Info singleFile : fileInfos) { System.out.println("Library item with name "+ singleFile.getName() + " has size " + singleFile.getSize()); } // Change the name and description of the library item with the specified name if (singleItem.getName().equals("simpleVmTemplate")) { ItemModel libItemUpdated = new ItemModel(); libItemUpdated.setName("newItemName"); libItemUpdated.setDescription("Description of the newItemName"); libItemService.update(singleItem.getId(), libItemUpdated); } }
Python
This example shows how to find an item by using the item name and then how to change the name and description of the retrieved item.
This example uses the steps that are described in the Edit the Settings of a Library Item procedure.
For related code samples, see the
vsphere-automation-sdk-python
VMware repository at GitHub.
... # 1 - List the items in a published library. item_stub = library_client.Item(my_stub_config) item_ids = item_stub.list(my_library_id) # 2 - List the files uploaded to each library item and print their names and sizes. file_stub = item_client.File(my_stub_config) for item_id in item_ids : item = item_stub.get(item_id) file_infos = file_stub.list(item_id) for file_info in file_infos : print(’Library item {} has file {} with size {}’.format(item.name, file_info.name, file_info.size)) # 3 - For a library item with a specified name, # create an ItemModel to change the name and description of the library item. if item.name == ’simpleVmTemplate’ : print(’Library item {} with description {}’.format(item.name, item.description)) item_model = library_client.ItemModel() item_model.name = ’newItemName’ item_model.description = ’Description of the newItemName’ item_stub.update(library_item_id=item_id, update_spec=item_model) print(’has been changed to:’) print(’library item {} with description {}’.format(item_model.name, item_model.description))