VMware Cloud Community
amacbeth
Contributor
Contributor
Jump to solution

Wrapper Object Properties

This is driving me crazy.  Hopefully I can explain this well enough that someone can help because it's becoming a roadblock for me.

Ok, so I think what I'm trying to do should be pretty easy but I cannot for the life of me figure it out.  I apologize if I'm not using the proper terminology, I'm still pretty new to scripting/vCO.

If I perform a call to vCenter from Orchestrator using VcPlugin.getAllDatastores(); it returns a DynamicWrapper object.  How do I print or otherwise know what properties are available as possible values (like .name)?

If I do a Get-Datastore | fl in PowerCLI it returns a list of the datastores with the properties I can use, but I've noticed that those properties are not necessarily included within the API call when done in vCO.

Hopefully that's clear but if you need clarification just let me know.

Thanks in advance!

1 Solution

Accepted Solutions
virtualsabi
Enthusiast
Enthusiast
Jump to solution

As mentioned by llian lliev you should check the documentation for accurate property naming of VC objects.

Beside the documentation you are able to retrieve all possible public methods for a given class (all getters for example).

Those should be named like the properties (including non-documented properties, too)

e.g.

var datastoreArray = VcPlugin.getAllDatastores();

for (var index in datastoreArray)

{

    var datastore = datastoreArray[index];

    var properties = [];

    var datastoreMethods = datastore.class.getMethods()

    for (var methodIndex in datastoreMethods)

    {

        if (datastoreMethods[methodIndex].getName().substring(0, 3) == "get" && datastoreMethods[methodIndex].getModifiers() == 1) {

            properties.push(datastoreMethods[methodIndex].getName().substring(3).charAt(0).toLowerCase() + datastoreMethods[methodIndex].getName().substring(3).slice(1));

        }

    }

    System.log(properties.sort());

}

View solution in original post

3 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

You can see the list of properties for a given type in the documentation; either online documentation or API Explorer in vCO Java client.

I don't think it is possible to enumerate object properties at runtime.

0 Kudos
virtualsabi
Enthusiast
Enthusiast
Jump to solution

As mentioned by llian lliev you should check the documentation for accurate property naming of VC objects.

Beside the documentation you are able to retrieve all possible public methods for a given class (all getters for example).

Those should be named like the properties (including non-documented properties, too)

e.g.

var datastoreArray = VcPlugin.getAllDatastores();

for (var index in datastoreArray)

{

    var datastore = datastoreArray[index];

    var properties = [];

    var datastoreMethods = datastore.class.getMethods()

    for (var methodIndex in datastoreMethods)

    {

        if (datastoreMethods[methodIndex].getName().substring(0, 3) == "get" && datastoreMethods[methodIndex].getModifiers() == 1) {

            properties.push(datastoreMethods[methodIndex].getName().substring(3).charAt(0).toLowerCase() + datastoreMethods[methodIndex].getName().substring(3).slice(1));

        }

    }

    System.log(properties.sort());

}

amacbeth
Contributor
Contributor
Jump to solution

Thanks for the code!  That is exactly what I was looking for.

I did find the documentation after posting here which is extremely helpful.  I just knew there had to be a way to actually print the properties and it was killing me that I couldn't figure out how to do it.

Thanks!

0 Kudos