Associating vCloud Resources with vSphere Entities

The admin view of vCloud Director resources provides additional information about the corresponding entities relevant to the vSphere platform. This information is available only when administrative credentials are used to log in to vCloud Director. The additional information does not replace the use of the vSphere API to provide comprehensive information about the entities. It merely provides the bridge between the vCloud and vSphere by mapping the IDs known to the respective systems.
For example, any given virtual machine is known in vCloud Director by a URN that contains the UUID and resource type. The same resource is identified in vSphere using its native identification, a
MoRef
(Managed object reference). Additional information provided in the vCloud API makes the necessary link between the two entities by mapping their ID in the two systems. The mapping context is shown in the following figure.
Mapping vApp to virtual machine
Mapping vApp to VM
The vCloud API describes the mapping in terms of XML elements, shown in the following example. The box in the example highlights XML data that maps a virtual machine from vCloud Director to vSphere. The
MoRef
of the virtual machine is in bold type.The object type is shown as
VIRTUAL_MACHINE
.
// XML Mapping a Virtual Machine URL to a MoRef <Vm needsCustomization="false" deployed="false" status="3" name="RedHat6" id="urn:vcloud:vm:f487ba71-058a-47a9-9e9a-def458c63fd5" type="application/vnd.vmware.vcloud.vm+xml" href="https://10.20.140.167/api/vApp/vm-f487ba71-058a-47a9-9e9a-def458c63fd5">    <VCloudExtension required="false">       <vmext:VmVimInfo> <vmext:VmVimObjectRef> <vmext:VimServerRef type="application/vnd.vmware.admin.vmwvirtualcenter+xml" name="dao_w2k8_vc" href="https://10.20.140.167/api/admin/extension/vimServer/e7026985-19f6-4b9a-9d0d-588629e63347"/> <vmext:MoRef>vm-63</vmext:MoRef> <vmext:VimObjectType>VIRTUAL_MACHINE</vmext:VimObjectType> </vmext:VmVimObjectRef> <vmext:DatastoreVimObjectRef> <vmext:VimServerRef type="application/vnd.vmware.admin.vmwvirtualcenter+xml" name="dao_w2k8_vc" href="https://10.20.140.167/api/admin/extension/vimServer/e7026985-19f6-4b9a-9d0d-588629e63347"/> <vmext:MoRef>datastore-29</vmext:MoRef> <vmext:VimObjectType>DATASTORE</vmext:VimObjectType> </vmext:DatastoreVimObjectRef> <vmext:HostVimObjectRef> <vmext:VimServerRef type="application/vnd.vmware.admin.vmwvirtualcenter+xml" name="dao_w2k8_vc" href="https://10.20.140.167/api/admin/extension/vimServer/e7026985-19f6-4b9a-9d0d-588629e63347"/> <vmext:MoRef>host-28</vmext:MoRef> <vmext:VimObjectType>HOST</vmext:VimObjectType> </vmext:HostVimObjectRef> <vmext:VirtualDisksMaxChainLength>1</vmext:VirtualDisksMaxChainLength> </vmext:VmVimInfo> </VCloudExtension> </Vm>
Besides the virtual machine object itself, the
VmVIMInfo
element encapsulated in the
VCloudExtension
element of the example lists a datastore object and a host object. Each section provides the vSphere entity reference (
MoRef
) for the corresponding entity, along with its type. The types are
DATASTORE
and
HOST
, respectively. In vCloud Director, the virtual machine can be described as virtual machine
vm-63
stored in datastore
datastore-29
and managed by vCenter Server
dao_w2k8_vc
.
Similarly, the following example shows the administrative view of a VDC wherein the
VCloudExtension
element provides additional information about the corresponding entities in vSphere. In this particular case, the VDC in the example is based on a resource pool configured in vCenter Server, named
dao_w2k8_vc
. More information on this server can be obtained by using the vCloud API and its reference URL, which is available as the
href
property. The
MoRef
element provides the ID of the resource pool that backs the given VDC, as known to vSphere. Since a
MoRef
is treated as an opaque value, the
VimObjectType
element specifies the type of object that the
MoRef
points to. Combining these elements enables you to use the vSphere API and to locate the Resource Pool served by the specified vCenter Server. XML mapping a datacenter URL to a MoRef:
<AdminVdc … >    <VCloudExtension required="false">       <vmext:VimObjectRef>          <vmext:VimServerRef
type="application/vnd.vmware.admin.vmwvirtualcenter+xml" name="dao_w2k8_vc"
href="https://10.20.140.167/api/admin/extension/vimServer/e7026985-19f6-..."/>          <vmext:MoRef>resgroup-52</vmext:MoRef>          <vmext:VimObjectType>RESOURCE_POOL</vmext:VimObjectType>       </vmext:VimObjectRef>    </VCloudExtension> ... </AdminVdc … >
The following example shows how to use SDK helper methods to access the vSphere specific information for the virtual machines of a given vApp.
The return value of the methods has type
VimObjectRefType
, which provides a reference to a vCenter Server, a
MoRef
to the vSphere entity, and the type of the entity it is referring to.
// Using the SDK for .NET To Access MoRefs using com.vmware.vcloud.sdk; using com.vmware.vcloud.api.rest.schema; … // Log in with admin privileges and get admin view of vDC containing the vApp. … VApp vapp; // VApp utility class from vCloud SDK // Identify vApp. … List<VM> Vms; // Get list of children VM(s) Vms = vapp.GetChildrenVms(); foreach (VM vm in Vms) { Console.WriteLine(); // Access vSphere information for VM … // VM Info from vSphere VimObjectRefType vmRef = vm.GetVMVimRef(); Console.WriteLine(“VirtualMachine: “ + vmRef.moRefField); // Datastore Info from vSphere for VM VimObjectRefType datastoreRef = vm.GetVMDatastoreVimRef(); Console.WriteLine(“Datastore: “ + datastoreRef.moRefField); // Host info form vSphere for VM VimObjectRefType hostRef = vm.GetVMHostVimRef(); Console.WriteLine(“Host: “ + hostRef.moRefField); }