This example shows how to find an item using the item name and then shows 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.

from com.vmware.content import library_client
from com.vmware.content import item_client
 
# 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))