Admin Extensions

Similar to the admin views, you can use a different method of the client connection object to create an admin extension client proxy. You use the admin extension proxy to find provider VDC. A provider VDC includes one or more resource pools and allocates resources from those pools to the Org VDCs that it supports.
The following example shows how to get a Provider VDC.
// Login … // Get dictionary of Provider vDCs: AdminExtension.VcloudAdminExtension adminExt = client.GetVcloudAdminExtension(); string pvdcName = "ProvVDC1"; Dictionary<string, ReferenceType> refs = adminExt.GetVMWProviderVdcRefsByName(); … // Get reference for pvdcName -> pvdcRef ReferenceType pvdcRef = refs[pvdcName]; VMWProviderVdc vmwPvdc = VMWProviderVdc.GetVMWProviderVdcByReference(client, pvdcRef);
Using the vCloud SDK for .NET allows you to access vCloud Director from a C# development environment. These examples show how to use .NET methods. The vCloud SDK for .NET simplifies access to the vCloud API. For more information about using the SDK, see the
vCloud SDK for .NET Developer's Guide
.
The vCloud API is REST-based. For more information about the vCloud API, see the
vCloud API Programming Guide
. The following example shows the REST API calls that accomplish the tasks shown in examples above, after logging in. REST API Calls To Get Provider VDC:
GET https://vCloud/api/admin GET https://vCloud/api/admin/org/id GET https://vCloud/api/admin/vdc/id GET https://vCloud/api/admin/extension GET https://vCloud/api/admin/extension/providervdc/id
In general, if you do not need admin views or provider views, you can use an Organization reference to get a VDC reference, and you can use the VDC reference to get a list of vApps belonging to the VDC. The following example shows how to list the hierarchy of Organizations, VDCs, and vApps known to vCloud Director. This example assumes you have already logged in to vCloud Director.
// List vApps in a VDC for a Given Organization Dictionary<string, ReferenceType> organizationsMap = client.GetOrgRefsByName(); if (organizationsMap != null) {    foreach (string organizationName in organizationsMap.Keys)    {       ReferenceType organizationReference = organizationsMap[organizationName];       Organization org = Organization.GetOrganizationByReference(client, organizationReference);       string OrgID = org.Resource.id;       Console.WriteLine("Organization Name:" + organizationName);       Console.WriteLine("Organization Id :" + OrgID);    }    foreach (ReferenceType orgRef in organizationsMap.Values)    {       Organization org = Organization.GetOrganizationByReference(client, orgRef);       foreach (ReferenceType vdcRef in org.GetVdcRefs())       {          Vdc vdc = Vdc.GetVdcByReference(client, vdcRef);          string vdcId = vdc.Resource.id;          Console.WriteLine("Org vDC Id:" + vdcId);          Console.WriteLine("Org vDC Name:" + vdc.Reference.name);          foreach (ReferenceType vAppRef in Vdc.GetVdcByReference(client, vdcRef).GetVappRefs())          {             Vapp vapp = Vapp.GetVappByReference(client, vAppRef);             Console.WriteLine("vApp Id:" + vapp.Resource.id);             Console.WriteLine("vApp Name:" + vapp.Resource.name);             List<VM> vms = new List<VM>();             try             {                vms = vapp.GetChildrenVms();             }             catch             {                // Handle exception here             }             foreach (VM vm in vms)             {                Console.WriteLine("VM Id : " + vm.Resource.id);                Console.WriteLine("VM Name : " + vm.Resource.name);             }          }       }    } }
The .NET SDK code in the following example translates to the API calls shown in the example below this one. REST API Calls To List vApps in a VDC for a Given Organization:
GET https://vCloud/api/admin GET https://vCloud/api/admin/org/id GET https://vCloud/api/admin/vdc/id GET https://vCloud/api/admin/extension GET https://vCloud/api/admin/extension/providervdc/id
You can use a provider VDC reference to enumerate its associated datastores, as shown in the following example, which assumes you have already logged in to vCloud Director. List Datastores:
/// <summary> /// Returns list of Provider vDCs. /// </summary> /// <returns>ReferenceType</returns> public static List<ReferenceType> GetProviderVdc() {    List<ReferenceType> vdcRefList = new List<ReferenceType>();    foreach (ReferenceType vdcRef1 in       client.GetVcloudAdminExtension().GetVMWProviderVdcRefsByName().Values)    {       vdcRefList.Add(vdcRef1);    }    return vdcRefList; } /// <summary> /// Returns the list of DataStores /// </summary> /// <returns>ReferenceType</returns> public static List<ReferenceType> GetDataStore() {    extension = client.GetVcloudAdminExtension();    List<ReferenceType> vmDatastorelist = new List<ReferenceType>();    foreach (ReferenceType datastoreRef in extension.GetVMWDatastoreRefs())    {       vmDatastorelist.Add(datastoreRef);    }    return vmDatastorelist; } // Get the datastores for the list of Provider vDCs. foreach (ReferenceType providerVdcRef in GetProviderVdc()) {    string providerVdcId = GetId(providerVdcRef.href);    Console.WriteLine("Provider vDC Id:" + providerVdcId);    Console.WriteLine("Provider vDC Name:" + providerVdcRef.name);    foreach (string morefitem in       VMWProviderVdc.GetResourcePoolsByMoref(client, providerVdcRef).Keys)    {       Console.WriteLine("Moref :" + morefitem);    }    foreach (VMWProviderVdcResourcePoolType VcResourcePool in       VMWProviderVdc.GetResourcePoolsByMoref(client, providerVdcRef).Values)    {       string VcResourcePoolId = GetId(VcResourcePool.ResourcePoolVimObjectRef.VimServerRef.href);       Console.WriteLine("VcResourcePoolId :" + VcResourcePoolId);    } } foreach (ReferenceType item in GetDataStore()) {    string DatastoreId = GetId(item.href);    Console.WriteLine("Data Store ID:" + DatastoreId);    Console.WriteLine("DataStore:" + item.name); }