background image

vCloud SDK for Java Developer’s Guide

16

VMware, Inc.

...

//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();

}

Add the vApp Template to a Catalog

After

 

the

 

vAppTemplate

 

has

 

been

 

uploaded,

 

HellovCloud.java

 

uses

 

its

 

createNewCatalogItem

 

method

 

to

 

create

 

a

 

CatalogItem

 

object

 

in

 

the

 

catalog

 

whose

 

name

 

was

 

provided

 

on

 

the

 

command

 

line.

 

The

 

CatalogItem

 

contains

 

the

 

reference

 

to

 

the

 

template

 

that

 

was

 

returned

 

in

 

Example 3

3

.

Instantiate the vApp Template

Now

 

that

 

we

 

have

 

the

 

template

 

in

 

the

 

catalog,

 

we

 

can

 

instantiate

 

it

 

to

 

create

 

a

 

vApp.

 

HellovCloud.java

 

implements

 

a

 

newvAppFromTemplate

 

method

 

that

 

has

 

two

 

parameters:

vAppTemplateReference

:

 

a

 

reference

 

to

 

the

 

template

 

(obtained

 

from

 

the

 

catalog).

Vdc

:

 

a

 

reference

 

to

 

the

 

vDC

 

in

 

which

 

to

 

instantiate

 

the

 

template.

With

 

these

 

inputs,

 

newvAppFromTemplate

 

constructs

 

a

 

simple

 

InstantiateVAppTemplateParams

 

request

 

body,

 

makes

 

the

 

request

 

to

 

the

 

action/instantiateVAppTemplate

 

URL

 

of

 

the

 

vDC,

 

and

 

returns

 

a

 

Vapp

 

helper

 

object

 

that

 

contains

 

(among

 

other

 

things)

 

a

 

reference

 

to

 

the

 

vApp.

 

Example 3-4.  

Instantiating the vApp Template

public static Vapp newvAppFromTemplate(ReferenceType vAppTemplateReference,Vdc vdc) throws 

VCloudException {
...

//get the href of the OrgNetwork to which we can connect the vApp network

NetworkConfigurationType networkConfigurationType = new NetworkConfigurationType();
if (vdc.getAvailableNetworkRefs().size() == 0) {

System.out.println("No Networks in vdc to instantiate the vapp");
System.exit(0);

}

//specify the NetworkConfiguration for the vApp network

networkConfigurationType.setParentNetwork(vdc.getAvailableNetworkRefs() 

.iterator().next());

networkConfigurationType.setFenceMode(FenceModeValuesType.BRIDGED);

VAppNetworkConfigurationType vAppNetworkConfigurationType = new 

VAppNetworkConfigurationType();

vAppNetworkConfigurationType.setConfiguration(networkConfigurationType);
vAppNetworkConfigurationType.setNetworkName("new network");

//fill in the NetworkConfigSection

NetworkConfigSectionType networkConfigSectionType = new NetworkConfigSectionType();
MsgType networkInfo = new MsgType();
networkInfo.setMsgid("1");
networkInfo.setValue("network info");
networkConfigSectionType.setInfo(networkInfo);
List<VAppNetworkConfigurationType> vAppNetworkConfigs = networkConfigSectionType

.getNetworkConfig();

vAppNetworkConfigs.add(vAppNetworkConfigurationType);

//fill in remaining InstatiationParams

InstantiationParamsType instantiationParamsType = new InstantiationParamsType();

Summary of Contents for VCLOUD SDK FOR JAVA 1.0 - DEVELOPER S GUIDE

Page 1: ...Java 1 0 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 docume...

Page 2: ...ts 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 p...

Page 3: ...Development 11 Prerequisites 11 Download the vCloud SDK for Java Package 11 Import the SDK Into Your Java IDE 12 About SSL Access 12 3 Hello vCloud A Structured Java Workflow Example 13 Running the H...

Page 4: ...vCloud SDK for Java Developer s Guide 4 VMware Inc...

Page 5: ...d API applications including interactive clients of VMware Cloud Director This guide assumes you are familiar with the Java programming language Representational State Transfer REST and RESTful progra...

Page 6: ...mware com support services VMware Professional Services VMware Education Services courses offer extensive hands on labs case study examples and course materials designed to be used as on the job refer...

Page 7: ...7 vCloud Object Taxonomy on page 7 vCloud SDK for Java Design The vCloud SDK for Java provides object specific methods for creating updating retrieving and deleting objects defined by the vCloud API...

Page 8: ...igured to provide services such as DHCP NAT and firewalls vCloud Virtual Datacenters A vCloud virtual datacenter vDC is an allocation mechanism for resources such as networks storage CPU and memory In...

Page 9: ...SO or floppy Virtual systems are stored as templates using an open standard format OVF 1 0 These templates can be retrieved from catalogs and transformed into virtual systems called vApps through a pr...

Page 10: ...vCloud SDK for Java Developer s Guide 10 VMware Inc...

Page 11: ...ccount with rights to run the samples The predefined role CatalogAuthor should provide all the necessary rights For more information about roles and rights see the VMware Cloud Director Administrator...

Page 12: ...mples 1 0 sources jar 3 Import the contents of the vcloud java sdk all folder into your Java IDE About SSL Access In the default configuration VMware Cloud Director requires vCloud API clients to use...

Page 13: ...to the vCloud Uploading an OVF package to create a vApp template Adding the vApp template to a catalog Instantiating the vApp template to create a vApp Operating the vApp The file HellovCloud txt in t...

Page 14: ...te to the cloud The vCloud API returns a list of the organizations to which the user has access and the login method in HellovCloud java prints this list In the typical case this list has a single mem...

Page 15: ...equests 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 request...

Page 16: ...AppTemplate URL of the vDC and returns a Vapp helper object that contains among other things a reference to the vApp Example 3 4 Instantiating the vApp Template public static Vapp newvAppFromTemplate...

Page 17: ...tVappTemplParamsType setSource vAppTemplateReference instVappTemplParamsType setInstantiationParams instantiationParamsType make the request and get an href to the vApp in return Vapp vapp vdc instant...

Page 18: ...vCloud SDK for Java Developer s Guide 18 VMware Inc...

Page 19: ...oud sdk Defines the classes that implement the user API Objects accessed by these classes are typically readable by all users and can be modified by users with appropriate rights com vmware vcloud sdk...

Page 20: ...anization Table 4 3 Administrative API Samples Sample Name Description CatalogCRUD java Create retrieve update or delete a catalog OrganizationCRUD java Create retrieve update or delete an organizatio...

Page 21: ...oad 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 us...

Page 22: ...vCloud SDK for Java Developer s Guide 22 VMware Inc...

Reviews: