This example shows how to upload an OVF package to a library item from your local file system.

This example uses the steps that are described in the Upload an OVF Package from a Local File System to a Library Item procedure.

Note: For related code samples, see the vSphere Automation SDK Java samples at GitHub.
...
 
  // Create an empty library item to describe the virtual machine.
  ItemModel itemModel = new ItemModel();
  itemModel.setName(“ubuntu-vm”);
  itemModel.setDescription(“ubuntu 7.0”);
  itemModel.setLibraryId(myLibraryId);
  itemModel.setType(“ovf”);
  String clientToken = UUID.randomUUID().toString();
  Item itemStub = myStubFactory.createStub(Item.class, myStubConfiguration);
  String itemId = itemStub.create(clientToken, itemModel);
 
  // Create an update session.
  UpdateSessionModel updateSessionModel = UpdateSessionModel();
  updateSessionModel.setLibraryItemId(itemId);
  clientToken = UUID.randomUUID().toString();
  UpdateSession updateSessionStub = myStubFactory.createStub(UpdateSession.class, myStubConfiguration);
  String sessionId = updateSessionStub.create(clientToken, updateSessionModel);
 
  // Create a file spec for the OVF envelope file.
  AddSpec fileSpec = new AddSpec();
  fileSpec.setName(“ubuntu.ovf”);
  fileSpec.setSourceType(SourceType.PULL);
  TransferEndpoint endpoint = new TransferEndpoint();
  endpoint.setUri(“http://www.example.com/images/ubuntu.ovf”);
  fileSpec.setSourceEndpoint(endpoint);
 
  // Link the file spec to the update session.
  File updateFileStub = myStubFactory.createStub(File.class, myStubConfiguration);
  updateFileStub.add(sessionId, fileSpec);
 
  // Initiate the asynchronous transfer.
  updateSessionStub.complete(sessionId);