damascushill
Contributor
Contributor

VcFolder walking from Datacenter

Jump to solution

The code below will allow me to walk straight down a path to the bottom of a set of folders Datacenter->Folder Level1->Folder Level2.

I need to walk sideways... I want to look at the next folder at Level1 in the same Datacenter.  The vmFolder given at the datacenter is on an Array type, and there is no "link-list" type chain to follow.

var datacenter_vcFolder = datacenter.vmFolder;

System.log("vmFolder:"+datacenter_vcFolder);

for (var i in datacenter_vcFolder) {

  System.log("Name["+i+"]:"+datacenter_vcFolder[i].name);

  var I_childType = datacenter_vcFolder[i].childType;

  var I_childEntity = datacenter_vcFolder[i].childEntity;

  for (var j in I_childType){

  System.log("childType["+j+"]:"+I_childType[j]);

  System.log("childEntity["+j+"]:"+I_childEntity[j]);

  }

}

0 Kudos
1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee

For me, that code fails right away with an invalid iterator for you first for loop.. according to the API Explorer, the datacenter.vmFolder property returns a Single "VcFolder" object, not an array of anything.

Once you have the VcFolder object, the childType and childEntity properties are each returned as Arrays - so that is where you would need to do your loop.

For example:

var dcFolder = datacenter.vmFolder; // Returns a vcFolder object

System.log("dcFolder:"+dcFolder);

var children = dcFolder.childEntity;

for each (child in children){

    System.log("Child: "+child.name+" :: "+System.getObjectType(child));

}

Generates The following for one of my labs:

[2014-03-17 16:52:41.478] [I] dcFolder:DynamicWrapper (Instance) : [VcFolder]-[class com.vmware.vmo.plugin.vi4.model.VimFolder] -- VALUE : Folder<group-v3>

[2014-03-17 16:52:43.393] [I] Child: vCAC51 :: VC:VirtualMachine

[2014-03-17 16:52:43.394] [I] Child: Zimbra8 :: VC:VirtualMachine

[2014-03-17 16:52:43.394] [I] Child: vPostgres-9.2.4 :: VC:VirtualMachine

[2014-03-17 16:52:43.395] [I] Child: Discovered virtual machine :: VC:VmFolder

[2014-03-17 16:52:43.396] [I] Child: Single Site Base vPod 5.5 GA-v2 :: VC:VirtualApp

[2014-03-17 16:52:43.396] [I] Child: freenas1 :: VC:VirtualMachine

[2014-03-17 16:52:43.396] [I] Child: win7Dev :: VC:VirtualMachine

[2014-03-17 16:52:43.397] [I] Child: Dev :: VC:VmFolder

[2014-03-17 16:52:43.397] [I] Child: loginsight.vcoteam.lab :: VC:VirtualMachine

[2014-03-17 16:52:43.398] [I] Child: vCO51GA :: VC:VirtualMachine

[2014-03-17 16:52:43.398] [I] Child: Base55pod :: VC:VmFolder

[2014-03-17 16:52:43.399] [I] Child: uslab-vcd :: VC:VmFolder

[2014-03-17 16:52:43.399] [I] Child: Prod :: VC:VmFolder

[2014-03-17 16:52:43.403] [I] Child: Templates :: VC:VmFolder

[2014-03-17 16:52:43.403] [I] Child: Test :: VC:VmFolder

[2014-03-17 16:52:43.404] [I] Child: JoomlaServer :: VC:VirtualMachine

[2014-03-17 16:52:43.404] [I] Child: vCD-512 :: VC:VirtualMachine

So you could filter on Object Type or instance of and drill down or sideways as needed.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

0 Kudos
1 Reply
Burke-
VMware Employee
VMware Employee

For me, that code fails right away with an invalid iterator for you first for loop.. according to the API Explorer, the datacenter.vmFolder property returns a Single "VcFolder" object, not an array of anything.

Once you have the VcFolder object, the childType and childEntity properties are each returned as Arrays - so that is where you would need to do your loop.

For example:

var dcFolder = datacenter.vmFolder; // Returns a vcFolder object

System.log("dcFolder:"+dcFolder);

var children = dcFolder.childEntity;

for each (child in children){

    System.log("Child: "+child.name+" :: "+System.getObjectType(child));

}

Generates The following for one of my labs:

[2014-03-17 16:52:41.478] [I] dcFolder:DynamicWrapper (Instance) : [VcFolder]-[class com.vmware.vmo.plugin.vi4.model.VimFolder] -- VALUE : Folder<group-v3>

[2014-03-17 16:52:43.393] [I] Child: vCAC51 :: VC:VirtualMachine

[2014-03-17 16:52:43.394] [I] Child: Zimbra8 :: VC:VirtualMachine

[2014-03-17 16:52:43.394] [I] Child: vPostgres-9.2.4 :: VC:VirtualMachine

[2014-03-17 16:52:43.395] [I] Child: Discovered virtual machine :: VC:VmFolder

[2014-03-17 16:52:43.396] [I] Child: Single Site Base vPod 5.5 GA-v2 :: VC:VirtualApp

[2014-03-17 16:52:43.396] [I] Child: freenas1 :: VC:VirtualMachine

[2014-03-17 16:52:43.396] [I] Child: win7Dev :: VC:VirtualMachine

[2014-03-17 16:52:43.397] [I] Child: Dev :: VC:VmFolder

[2014-03-17 16:52:43.397] [I] Child: loginsight.vcoteam.lab :: VC:VirtualMachine

[2014-03-17 16:52:43.398] [I] Child: vCO51GA :: VC:VirtualMachine

[2014-03-17 16:52:43.398] [I] Child: Base55pod :: VC:VmFolder

[2014-03-17 16:52:43.399] [I] Child: uslab-vcd :: VC:VmFolder

[2014-03-17 16:52:43.399] [I] Child: Prod :: VC:VmFolder

[2014-03-17 16:52:43.403] [I] Child: Templates :: VC:VmFolder

[2014-03-17 16:52:43.403] [I] Child: Test :: VC:VmFolder

[2014-03-17 16:52:43.404] [I] Child: JoomlaServer :: VC:VirtualMachine

[2014-03-17 16:52:43.404] [I] Child: vCD-512 :: VC:VirtualMachine

So you could filter on Object Type or instance of and drill down or sideways as needed.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

0 Kudos