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