background image

vCloud SDK for PHP Developer’s Guide

10

VMware, Inc.

Creating a Data Object

Each

 

data

 

object

 

class

 

includes

 

a

 

constructor

 

method

 

whose

 

parameters

 

represent

 

attributes

 

of

 

the

 

class

 

and

 

all

 

of

 

its

 

ancestors.

 

Attributes

 

are

 

marked

 

as

 

protected

 

to

 

restrict

 

their

 

visibility.

 

All

 

classes

 

contain

 

setter

 

and

 

getter

 

methods

 

for

 

XML

 

elements

 

and

 

attributes.

 

The

 

general

 

form

 

of

 

these

 

method

 

names

 

is

 

operation

_

attribute

name

 

for

 

attributes

 

and

 

operation

ElementName

 

for

 

elements,

 

where

 

operation

 

is

 

one

 

of

 

set

 

or

 

get

.

 

For

 

example,

 

the

 

VMware_VCloud_API_ReferenceType

 

class

 

supports

 

set_name()

 

and

 

get_name()

 

methods

 

that

 

get

 

or

 

set

 

the

 

value

 

of

 

its

 

name

 

attribute,

 

and

 

the

 

VMware_VCloud_API_UserType

 

class

 

supports

 

setFullName()

 

and

 

getFullName()

 

methods

 

that

 

set

 

or

 

get

 

the

 

value

 

of

 

the

 

FullName

 

element

 

in

 

a

 

User

 

object.

To

 

create

 

a

 

data

 

object,

 

you

 

can

 

either

 

invoke

 

an

 

empty

 

constructor

 

and

 

then

 

call

 

the

 

setters

 

for

 

the

 

object

 

(see

 

Example 1

1

),

 

or

 

invoke

 

the

 

constructor

 

with

 

parameters

 

(see

 

Example 1

2

).

Example 1-1.  

Create a Data Object From an Empty Constructor

$ref = new VMware_VCloud_API_ReferenceType();

$ref->set_href($href);
$ref->set_type($type);
$ref->set_name($name);

Example 1-2.  

Create a Data Object With a Parameterized Constructor

$ref = new VMware_VCloud_API_ReferenceType ($href=$href, $type=$type, $name=$name); 

Creating an SDK Object

You

 

can

 

create

 

an

 

SDK

 

object

 

when

 

you

 

need

 

to

 

invoke

 

a

 

lifecycle

 

operation

 

such

 

as

 

create

 

or

 

modify

 

on

 

a

 

vCloud

 

API

 

object.

 

Most

 

class

 

constructors

 

for

 

SDK

 

objects

 

require

 

two

 

parameters:

A

 

VMware_VCloud_SDK_Service

 

object,

 

which

 

contains

 

HTTP

 

connection

 

information.

A

 

ReferenceType

 

data

 

object

 

which

 

contains

 

the

 

request

 

URL.

 

For

 

more

 

information

 

about

 

request

 

URLs,

 

see

 

the

 

vCloud

 

API

 

Programming

 

Guide

.

For

 

example,

 

you

 

could

 

use

 

code

 

similar

 

to

 

the

 

fragment

 

shown

 

in

 

Example 1

3

 

to

 

create

 

a

 

VMware_VCloud_SDK_Org

 

object

 

to

 

use

 

as

 

an

 

entrypoint

 

for

 

client

 

operations.

Example 1-3.  

Creating an SDK Object

// get the list of all organizations in the vCloud
$orgRefs = $service->getOrgRefs($orgName);
// create an object that represents the first organization in the list
$sdkOrg = $service->createSDKObj($orgRefs[0]);

Table 1

3

 

summarizes

 

the

 

types

 

of

 

SDK

 

objects

 

you

 

can

 

create

 

and

 

provides

 

information

 

to

 

help

 

you

 

choose

 

the

 

creation

 

parameters

 

(the

 

container

 

for

 

the

 

object,

 

and

 

a

 

method

 

to

 

use).

 

The

 

table

 

omits

 

the

 

VMware_VCloud_SDK_

 

part

 

of

 

the

 

package

 

names

 

in

 

the

 

SDK

 

Object

 

and

 

Container

 

Object

 

columns.

 

To use the information in the table to create an SDK object

1

Retrieve

 

an

 

array

 

of

 

object

 

references

 

by

 

specifying

 

a

 

container

 

object

 

and

 

a

 

creation

 

method.

$

references

=

Column2

->

Column3

2

For

 

any

 

reference

 

in

 

the

 

array,

 

create

 

an

 

SDK

 

object

 

using

 

the

 

selected

 

reference.

Column1

=$service->createSDKObj($

reference

)

Example 1

3

 

applies

 

this

 

formula

 

to

 

creating

 

an

 

Org

 

object.

Summary of Contents for vCloud SDK 1.0

Page 1: ...SDK 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 documen...

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: ...ct 10 Creating an SDK Object 10 Using a Different HTTP Library 12 Using the HTML Reference Material 12 2 Setting Up for PHP Development 13 Prerequisites 13 Download and Install the vCloud SDK for PHP...

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

Page 5: ...ud Director This guide assumes you are familiar with the PHP programming language Representational State Transfer REST and RESTful programming conventions the Open Virtualization Format Specification...

Page 6: ...ware 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 refere...

Page 7: ...bout running the example applications included in the SDK This chapter includes the following topics vCloud Object Taxonomy on page 7 vCloud SDK for PHP Design on page 9 vCloud Object Taxonomy The vCl...

Page 8: ...s floppy disks and CD ROMs An organization administrator specifies how resources from a provider vDC are distributed to the vDCs in an organization vCloud Catalogs Catalogs contain references to virtu...

Page 9: ...fined in vCloud API vCloud administrative API and vCloud vSphere platform API extensions Classes in this package are generated from the vCloud API XML schema files Each class maps to a complex type de...

Page 10: ...e Creating an SDK Object You can create an SDK object when you need to invoke a lifecycle operation such as create or modify on a vCloud API object Most class constructors for SDK objects require two...

Page 11: ...minOrg getAdminVdcsRefs Catalog Org getCatalogRefs CatalogItem Catalog getCatalogItemRefs CatalogItem AdminCatalog getCatalogItemRefs Extension None See Creating Top Level Objects on page 12 Extension...

Page 12: ...are_VCloud_SDK_Http_Client_Interface interface and then can call the VMware_VCloud_SDK_Service getService method specifying that client service VMware_VCloud_SDK_Service getService myHTTPClient Using...

Page 13: ...ut the vCloud API XML schemas which define the objects and operations that the SDK supports familiarity with the details of the underlying objects and operations as described in the vCloud API Program...

Page 14: ...e with the download or click No to exit without downloading 5 Choose a download option then click the link for the distribution format you want The vCloud SDK for PHP is distributed as a compressed ar...

Page 15: ...help To run the helloVCloud php example use the following command php helloVCloud php s server u user vcloudOrganization p password c config o orgName d vdcName g catalogName i item a vAppName The fol...

Page 16: ...ample creates All options but s u and p must be separated from their arguments by an equals sign For example php helloVCloud php s vcloud example com u user exampleOrg p Pa55w0rd o exampleOrg d exampl...

Page 17: ...mples use for logging in names for objects such as catalogs and vDCs that the examples create and other values that you are required to specify when creating a vCloud API object You must edit this fil...

Page 18: ...sed by all example code updateVmMemory php Edits the memory required by a virtual machine and reduces the existing value by half uploadVAppTemplate php Uploads an OVF package to create a vApp template...

Page 19: ...kage used in examples 13 P packages in this SDK 9 PEAR HTTP_Request2 package 13 PHP versions supported 13 S sample programs privileges required to run 18 runtime environment for 17 sample programs pri...

Page 20: ...vCloud SDK for PHP Developer s Guide 20 VMware Inc...

Reviews: