VMware Cloud Community
Raimondas
Contributor
Contributor
Jump to solution

Get all vApps from vDC using orchestrator vCloud plugin and vDC ID as input (URN format)

Hi,

I am a newbie in orchestration and now stuck on a problem. I use vCloud plugin and want to get all vApps from specific vDC, then suspend them and disable vDC. Firstly, I should have a vDC ID in URN format as input, e.g. urn:vcloud:vdc:96204229-860b-41c2-ab91-7b8bd3f4c174. However, I cannot find any method in API library to get all vApps from vDC using vDC ID URN format for input, therefore for now I have this script:

var cloudOrgs = System.getModule("com.vmware.library.vCloud.operation").getOrganizationsVCloudHost(vcloud_server);

for (var i in cloudOrgs) {

  var orgVdcs = System.getModule("com.vmware.library.vCloud.operation").getVdcsOrg(cloudOrgs[i]);

  System.log(orgVdcs);

  for (var j in orgVdcs) {

     var vDCvApps = System.getModule("com.vmware.library.vCloud.operation").getVAppsVdc(orgVdcs[j]);

     }

}

System.log prints output of vDCs like this:

DynamicWrapper (Instance) : [VclVdc]-[class com.vmware.vmo.plugin.vcloud.model.Vdc] -- VALUE : com.vmware.vmo.plugin.vcloud.model.Vdc@97eccd50


Tried this:

System.log(orgVdcs.Vdc.id)

Got output: TypeError: Cannot read property "id" from undefined

How can I get vDC ID in URN format from this output?

1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

And here is sample code that also enumerates all vApps in the vDC and prints vApp's ID and name:

var cloudOrgs = System.getModule("com.vmware.library.vCloud.operation").getOrganizationsVCloudHost(vcloud_server);

for (var i in cloudOrgs) {

  var orgVdcs = System.getModule("com.vmware.library.vCloud.operation").getVdcsOrg(cloudOrgs[i]);

  for (var j in orgVdcs) {

    System.log("vDC ID: " + orgVdcs[j].id);

    var vDCvApps = System.getModule("com.vmware.library.vCloud.operation").getVAppsVdc(orgVdcs[j]);

    for (var k in vDCvApps) {

      var vApp = vDCvApps[k];

      System.log("vApp ID: " + vApp.id + "   name: " + vApp.name);

    }

  }

}

View solution in original post

3 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

The call to getVdcsOrg() method returns an array of Vdc objects. You need to iterate over this array and then you can get vDC ID for each Vdc member of this array.

Here is your code modified to print IDs of all vDCs in the array:

var cloudOrgs = System.getModule("com.vmware.library.vCloud.operation").getOrganizationsVCloudHost(vcloud_server);

for (var i in cloudOrgs) {

  var orgVdcs = System.getModule("com.vmware.library.vCloud.operation").getVdcsOrg(cloudOrgs[i]);

  for (var j in orgVdcs) { // iterate over array elements

    System.log("vDC ID: " + orgVdcs[j].id);

  }

}

iiliev
VMware Employee
VMware Employee
Jump to solution

And here is sample code that also enumerates all vApps in the vDC and prints vApp's ID and name:

var cloudOrgs = System.getModule("com.vmware.library.vCloud.operation").getOrganizationsVCloudHost(vcloud_server);

for (var i in cloudOrgs) {

  var orgVdcs = System.getModule("com.vmware.library.vCloud.operation").getVdcsOrg(cloudOrgs[i]);

  for (var j in orgVdcs) {

    System.log("vDC ID: " + orgVdcs[j].id);

    var vDCvApps = System.getModule("com.vmware.library.vCloud.operation").getVAppsVdc(orgVdcs[j]);

    for (var k in vDCvApps) {

      var vApp = vDCvApps[k];

      System.log("vApp ID: " + vApp.id + "   name: " + vApp.name);

    }

  }

}

Raimondas
Contributor
Contributor
Jump to solution

Thanks very much, it worked!

0 Kudos