public static ReferenceType findCatalogRef(String orgName,String catalogName) throws
VCloudException {
ReferenceType orgRef = vcloudClient.getOrgRefByName(orgName);
Organization org = Organization.getOrganizationByReference(vcloudClient, orgRef);
return org.getCatalogRefByName(catalogName);
}
Upload an OVF Package to Create a vApp Template
The HellovCloud.java command line requires you to supply the name of an OVF descriptor file and the
vmdk file that it references. This information is used in the createUploadvAppTemplate method to upload
the OVF descriptor and vmdk file, create a vApp template, and return a reference to the template that can be
used by other methods in the program.
The createUploadvAppTemplate method and the methods it calls from the vCloud SDK for Java implement
the following workflow to upload the OVF package and create a vApp template.
1
The client POSTs an initial request that specifies a name for the template, a transfer format for the data,
and an optional description.
2
The server returns an unresolved (status="0") vAppTemplate document that includes an upload URL
for the OVF package.
3
The client uses an HTTP PUT request to upload the OVF package descriptor (the .ovf file) to the upload
URL.
4
The server reads the descriptor and constructs a vAppTemplate object that includes an upload URL for
each file listed in the References section of the descriptor). While the server is constructing this
document, the client makes periodic requests for it and examines the response for additional upload
URLs. When the response contains any upload URLs beyond the one returned in Step 2, template is
complete.
5
The client uses HTTP PUT requests to upload each of the files.
6
If the OVF package includes a manifest file, the entire upload is validated against the contents of the
manifest file.
After all the files are uploaded (and validated if a manifest is present), the server processes the uploads. When
processing is complete, the server sets the value of the template's status attribute to 8, indicating that the
template is ready for use. (This status value indicates that all of the virtual machines in the template are
powered off. For more information, see the vCloud API Programming Guide.)
Example 3-3. Upload an OVF Package to Create a vApp Template
public static ReferenceType createUploadvAppTemplate(Vdc vdc, String ovfFileLocation, String
vmdkFileLocation, String vmdkfileName) throws VCloudException, FileNotFoundException,
InterruptedException {
...
//fill in the upload params with name and Description
UploadVAppTemplateParamsType vappTemplParams = new UploadVAppTemplateParamsType();
vappTemplParams.setDescription("HellovCloudvAppTemplate Description");
vappTemplParams.setName("HellovCloudvAppTemplate");
...
//get the action/uploadVappTemplate link
VappTemplate vappTemplate = vdc.createVappTemplate(vappTemplParams);
...
//upload the OVF descriptor
vappTemplate.uploadOVFFile(ovfFileInputStream, ovfFile.length());
...
//using the href of the new vAppTemplate, check to see if the descriptor
// upload is complete (ovfDescriptorUploaded=true)
vappTemplate = VappTemplate.getVappTemplateByReference(vcloudClient,
vappTemplate.getReference());
while (!vappTemplate.getResource().isOvfDescriptorUploaded()) {
Thread.sleep(5000);
VMware, Inc.
Chapter 3 Hello vCloud: A Structured Java Workflow Example
15
Need help?
Do you have a question about the VCLOUD SDK FOR JAVA 1.0 - DEVELOPER S GUIDE and is the answer not in the manual?
Questions and answers