Академический Документы
Профессиональный Документы
Культура Документы
This document supports the version of each product listed and supports all subsequent versions until the document is replaced by a new edition. To check for more recent editions of this document, see http://www.vmware.com/support/pubs.
EN-000362-00
You can find the most up-to-date technical documentation on the VMware Web site at: http://www.vmware.com/support/ The VMware Web site also provides the latest product updates. If you have comments about this documentation, submit your feedback to: docfeedback@vmware.com
Copyright 2010 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents. VMware is a registered trademark or trademark of VMware, Inc. in the United States and/or other jurisdictions. All other marks and names mentioned herein may be trademarks of their respective companies.
VMware, Inc.
Contents
AboutThisBook
1 AboutthevCloudSDKforJava 7
vCloudSDKforJavaDesign 7 vCloudObjectTaxonomy 7 vCloudOrganizations 8 vCloudUsersandGroups 8 vCloudNetworks 8 vCloudVirtualDatacenters 8 vCloudCatalogs 9 vCloudTasks 9 VirtualSystemsandMediaImagesinavCloud 9
2 SettingUpforJavaDevelopment 11
Prerequisites 11 DownloadthevCloudSDKforJavaPackage 11 ImporttheSDKIntoYourJavaIDE 12 AboutSSLAccess 12
3 HellovCloud:AStructuredJavaWorkflowExample 13
RunningtheHellovCloudSample 13 LoggingInandGettinganOrganizationList 14 GettingReferencestothevDCandCatalog 14 UploadanOVFPackagetoCreateavAppTemplate 15 AddthevAppTemplatetoaCatalog 16 InstantiatethevAppTemplate 16 OperatethevApp 17
4 OverviewofPackagesandSamples 19
Packages 19 Samples 19
Index 21
VMware, Inc.
VMware, Inc.
Revision History
Thisguideisrevisedwitheachreleaseoftheproductorwhennecessary.Arevisedversioncancontainminor ormajorchanges.Table 1summarizesthesignificantchangesineachversionofthisguide. Table 1. Revision History
Revision 30AUG10 Description Version1.0
Intended Audience
ThisguideisintendedforsoftwaredeveloperswhoarebuildingvCloudAPIapplications,including interactiveclientsofVMwareCloudDirector.ThisguideassumesyouarefamiliarwiththeJavaprogramming language,RepresentationalStateTransfer(REST)andRESTfulprogrammingconventions,theOpen VirtualizationFormatSpecification,andVMwareVirtualmachinetechnology.Familiaritywithother widelydeployedtechnologiessuchasXML,HTTP,andtheWindowsorLinuxoperatingsystemsisalso assumed.
Document Feedback
VMwarewelcomesyoursuggestionsforimprovingourdocumentation.Sendyourfeedbackto docfeedback@vmware.com.
Support Offerings
TofindouthowVMwaresupportofferingscanhelpmeetyourbusinessneeds,goto http://www.vmware.com/support/services.
VMware, Inc.
TheVMwarevCloudAPIprovidessupportfordeveloperswhoarebuildinginteractiveclientsofVMware CloudDirectorusingaRESTfulapplicationdevelopmentstyle.vCloudAPIclientsandserverscommunicate overHTTP,exchangingrepresentationsofvCloudobjects.TheserepresentationstaketheformofXML elements.HTTPGETrequestsareusedtoretrievethecurrentrepresentationofanobject,HTTPPOSTand PUTrequestsareusedtocreateormodifyanobject,andHTTPDELETErequestsaretypicallyusedtodelete anobject. ThevCloudSDKforJavaisaJavalanguagebindingforthevCloudAPI.ItusestheJAXBframeworktocreate JavaclassesfortheresourcesdefinedinthevCloudAPIXMLschemas.ThevCloudSDKforJavaprovides classesandmethodsthatencapsulatetheinterfaces,objects,andoperationssupportedbythevCloudAPI whilepreservingitsRESTfulprogrammingstyleandcompatibilitywiththeHTTPprotocolfamily. ThisvCloudSDKforJavaDevelopersGuideprovidesinformationaboutsettinguptheSDKinadevelopment environment,andinformationaboutrunningthesampleapplicationsincludedintheSDK. Thischapterincludesthesetopics:
vCloudSDKforJavaDesignonpage 7 vCloudObjectTaxonomyonpage 7
VMware, Inc.
Organization vDC1
vApp Media Media vApp template
Catalog 3
Catalogitem em Catalog 2 em em Catalogitem em Catalog 1 em em Catalogitem Catalogitem Catalogitem Catalogitem
vDC2
vApp Media Media vApp template
Network Network
users
groups
TasksList
vCloud Organizations
AvCloudcontainsoneormoreorganizations.AvCloudorganizationisaunitofadministrationfora collectionofusers,groups,andcomputingresources.Usersauthenticateattheorganizationlevel,supplying credentialsestablishedbyanorganizationadministratorwhentheuserwascreatedorimported.
vCloud Networks
Anorganizationcanbeprovisionedwithoneormorenetworks.Theseorganizationnetworkscanbe configuredtoprovideservicessuchasDHCP,NAT,andfirewalls.
AnorganizationadministratorspecifieshowresourcesfromaprovidervDCaredistributedtothevDCsinan organization.
VMware, Inc.
vCloud Catalogs
Catalogscontainreferencestovirtualsystemsandmediaimages.Acatalogcanbesharedtomakeitvisibleto othermembersofanorganization,andcanbepublishedtomakeitvisibletootherorganizations.AvCloud systemadministratorspecifieswhichorganizationscanpublishcatalogs,andanorganizationadministrator controlsaccesstocatalogsbyorganizationmembers.
vCloud Tasks
Longrunningoperationsinitiatedbymembersofanorganizationcreatetasks,whicharekeptonthe organizationstaskslist.
VMware, Inc.
10
VMware, Inc.
Thischapterincludesthesetopics:
Prerequisitesonpage 11 DownloadthevCloudSDKforJavaPackageonpage 11
Prerequisites
ThevCloudSDKforJavarequiresJDK6orlater(theSDKandsamplesweredevelopedusingJDK 1.6.0_14b08).ThisdocumentandtheSDKreferencedocumentationassumethatyouarefamiliarwiththeJava programminglanguageandhaveaccesstoaninstallationofVMwareCloudDirector. Inaddition,youshouldconsiderthefollowing:
AlthoughthevCloudSDKforJavajavadocprovidesinformationaboutthevCloudAPIXMLschemas, whichdefinetheobjectsandoperationsthattheSDKsupports,familiaritywiththedetailsofthe underlyingobjectsandoperations,asdescribedinthevCloudAPIProgrammingGuide,canhelpyou understandthestructureofvCloudAPIobjects,andhowthemethodsinthisSDKoperateonthose objects. Beforeyoucanrunthesamples,youmustusetheCloudDirectorwebconsoleorthevCloudAPItocreate anorganization,catalog,andvDCthatthesamplescanuse.Theorganizationmusthaveauseraccount withrightstorunthesamples.ThepredefinedroleCatalogAuthorshouldprovideallthenecessary rights.Formoreinformationaboutrolesandrights,seetheVMwareCloudDirectorAdministratorsGuide. Severalofthesampleprograms,includingHellovCloud.java,requireyoutohaveanOVFpackage availableontheclienthost.Thispackagemustbeuncompressed,andmustspecifyasinglevmdkfile.For moreinformationaboutOVF,seethevCloudAPIProgrammingGuide.
VMware, Inc.
11
12
VMware, Inc.
ThischapterpresentsanexampleofusingthevCloudSDKforJavatoimplementastructuredworkflow throughthelifecycleofavApp.Itcontainsthefollowingtopics.
where:
VMware, Inc.
13
Forexample:
java HellovCloud https://vcloud/api/versions 1.0 user@SampleOrg Pa55w0rd SampleOrg SampleVdc C:\descriptor.ovf C:\disk.vmdk disk.vmdk SampleCatalog
userName:suppliedintheformuser@vcloudorganization password:theuserspassword
AsshownintheexcerptinExample 31,HellovCloud.javausesthismethodtoauthenticatetothecloud. ThevCloudAPIreturnsalistoftheorganizationstowhichtheuserhasaccess,andtheloginmethodin HellovCloud.javaprintsthislist.Inthetypicalcase,thislisthasasinglemember,theorganizationthatwas suppliedintheuserNameparameter. Example 3-1. Logging In and Getting an Organization List
public static void login(String vCloudVersionsURL, String versionId,String username, String password) ... { ... System.out.println("Organizations:"); System.out.println("-------------"); for (String organizationName : organizationsMap.keySet()) System.out.println("" + organizationName); } else { System.out.println(Try Logging in with valid details"); System.exit(0); }
14
VMware, Inc.
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); }
5 6
Afterallthefilesareuploaded(andvalidatedifamanifestispresent),theserverprocessestheuploads.When processingiscomplete,theserversetsthevalueofthetemplatesstatusattributeto8,indicatingthatthe templateisreadyforuse.(Thisstatusvalueindicatesthatallofthevirtualmachinesinthetemplateare poweredoff.Formoreinformation,seethevCloudAPIProgrammingGuide.) 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.
15
... //get the upload:default URI for the vmdk file and PUT the serialized bits vappTemplate.uploadFile(vmdkfileName, vmdkFileInputStream, vmdkFile .length()); ... //check the status. when status=8, template is complete while (vappTemplate.getResource().getStatus() != 8) { Thread.sleep(5000); vappTemplate = VappTemplate.getVappTemplateByReference(vcloudClient, vappTemplate.getReference()); } ... //return the href of the vAppTemplate return vappTemplate.getReference(); }
vAppTemplateReference:areferencetothetemplate(obtainedfromthecatalog). Vdc:areferencetothevDCinwhichtoinstantiatethetemplate.
16
VMware, Inc.
List<JAXBElement<? extends SectionType>> sections = instantiationParamsType .getSection(); sections.add(new ObjectFactory() .createNetworkConfigSection(networkConfigSectionType)); //create the request body (InstantiateVAppTemplateParams) InstantiateVAppTemplateParamsType instVappTemplParamsType = new InstantiateVAppTemplateParamsType(); instVappTemplParamsType.setName("HellovCloudvAppp"); instVappTemplParamsType.setSource(vAppTemplateReference); instVappTemplParamsType.setInstantiationParams(instantiationParamsType); //make the request, and get an href to the vApp in return Vapp vapp = vdc.instantiateVappTemplate(instVappTemplParamsType); return vapp;
VMware, Inc.
17
18
VMware, Inc.
ThevCloudSDKforJavaincludessampleapplicationcodeandcompletereferencedocumentationonall packages,classes,andmethodsintheSDK.Thischapterisanintroductorytourofthoseitems.
Packages
TheSDKincludesfourpackagesthatsupporttheJAXBbindingstothevCloudAPIXMLschemasandthree packagesthatimplementcreate,retrieve,update,anddelete(CRUD)operationsontheobjectsrepresentedby thoseschemas. Table 4-1. Packages in the vCloud SDK for Java
Package Name com.vmware.vcloud.sdk Description DefinestheclassesthatimplementtheuserAPI.Objectsaccessedby theseclassesaretypicallyreadablebyallusers,andcanbemodified byuserswithappropriaterights. DefinestheclassesthatimplementtheadministrativeAPI.Objects accessedbytheseclassesaretypicallyreadablebyallusers,butcan becreatedandmodifiedonlybyasystemadministrator,organization administratororotherprivilegeduser.Manyoftheseobjectsextend typesthataredefinedintheuserAPI. Definestheclassesthatimplementextensionsthatsupport operationsonthevSpherePlatform.AllvSphereplatformoperations arerestrictedtothesystemadministrator. XMLschemasusedbyJAXBbinding
com.vmware.vcloud.sdk.admin
com.vmware.vcloud.sdk.admin.extension
Samples
InadditiontoHellovCloud.java(seeHellovCloud:AStructuredJavaWorkflowExampleonpage 13),the SDKsamplesdirectory(vcloud-java-sdk-samples-1.0-sources\com\vmware\vcloud\sdk\samples) includesseveralsamplesthatdemonstratehowyoucanusethevCloudSDKforJavatodevelopclient applications.SampleslistedTable 42canberunbyanyuserwithrightstocreateandmodifycatalogitems andvApps.SampleslistedTable 43requireorganizationadministratorprivileges. Table 4-2. User API Samples
Sample Name CatalogInventorySample.java CatalogItemCRUD.java DiskCRUD.java Description Listsnameandhrefforallitemsinallcatalogsintheorganization. Create,retrieve,update,ordeleteacatalogitem. Create,retrieve,update,ordeleteavirtualharddiskinaVmobject.
VMware, Inc.
19
20
VMware, Inc.
Index
C
Catalogs, about 9
G
groups, about 8
H
helper object not garbage collected 7 to use 7
to create from template 16 to delete 17 vApp template about 9 OVF upload workflow 15 to create 13, 15 to instantiate 16 vDC, about 8
L
login 13
N
networks, about 8
O
organizations about 8 list of 14 OVF to upload 13 OVF package to upload 15
P
packages, overview of 19
S
samples HellovCloud sample 13 overview of 19 rights required to run 11 txt file output 11
T
Tasks, about 9 technical support resources 5
U
users, about 8
V
vApp about 9 power state changes 17
VMware, Inc.
21
22
VMware, Inc.