Perl Example of
Changing the Settings of a Library Item
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 Perl
samples at GitHub.
... # 1 - List the items in a published library. my $item_stub = $stubFactory->create_stub( 'service_name' => 'Com::Vmware::Content::Library::Item', 'stub_config' => $myStubConfig ); my @item_ids = $item_stub->list('library_id' => $my_library_id); # 2 - List the files uploaded to each library item # and print their names and sizes. my $file_stub = $stubFactory->create_stub( 'service_name' => 'Com::Vmware::Content::Library::Item::File', 'stub_config' => $myStubConfig ); foreach my $item_id (@item_ids) { my $item = $item_stub->get('library_item_id' => $item_id); my $item_name = $item->get_name(); my @file_infos = $file_stub->list('library_item_id' => $item_id); foreach my $info (@file_infos) { my $info_name = $info->get_name(); my $info_size = $info->get_size(); print "Library item $item_name has file $info_name" . " with size $info_size"; } # 3 - For a library item with a specified name, # create an ItemModel to change the name and description of the item. if ($item_name == 'simpleVmTemplate' { my $item_description = $item->get_description(); print "Library item '$item_name' with description" . " '$item.description$'"; my $item_model = new Com::Vmware::Content::Library::ItemModel(); my $new_name = 'newItemName'; my $new_description = 'Description of the newItemName'; $item_model->set_name('name' => $new_name); $item_model->set_description('description' => $new_description); $item_stub->update('library_item_id' => $item_id, 'update_spec' => $item_model); print "\nhas been changed to:\n"; print "Library item '$new_name' with description" . " '$new_description'"; } # if item.name } # foreach $item_id