improvingdaily
Enthusiast
Enthusiast

List all properties of an object

Jump to solution

How do you list all the properties of an object in VMware Orchestrator?  For example I have a test workflow that contains a scriptable task.  I have a vm attribute I have assigned.  I want to list all the properties of that vm object in the System.log.  I also will need to do the same thing for a disk attached to a vm.  Thanks

0 Kudos
1 Solution

Accepted Solutions
qc4vmware
Virtuoso
Virtuoso

It doesn't get much easier than importing a package but here are the guts of what is going on:

// the workflow takes any object so I created a wrapper workflow to pick a vm then pass that into the main workflow.

var obj = obj;

var properties = []; 

var other = [];

var methods = obj.class.getMethods(); 

for (var methodIndex in methods) { 

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

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

}

else {

other.push(methods[methodIndex].getName()); 

}

System.log("Attributes: " + properties.sort()); 

System.log("other: " + other.sort());

for each (var prop in properties) {

System.log(prop + " ::: " + obj[prop]);

}

​function getAllMethods(object) {

    return Object.getOwnPropertyNames(object).filter(function(property) {

        return typeof object[property] == 'function';

    });

}

System.log(getAllMethods(obj));

View solution in original post

0 Kudos
5 Replies
iiliev
VMware Employee
VMware Employee

Hi,

There is no such API that will enumerate and return all the properties of a given object type (virtual machine, disk, etc.).

The closest thing are the following 2 options:

1) Check the list of properties for a given type in vRO API Explorer. All the public properties should be listed there.

2) There is a REST API call to get 'metadata' for types defined in a vRO plug-in. So, for example, if you want to find the properties of virtual machine type (which type comes from vCenter plug-in), you can make a GET request to the following URL

https://{vroaddress}:8281/vco/api/catalog/VC/metadata

and in the response body you should be able to find the metadata of all types coming from vCenter plug-in and their properties.

One important note here is that this metadata REST API returns only 'finder' properties of a given type, not 'scripting' properties. Usually, most properties are both finder and scripting property, but not always (this is decided by the plug-in author).

0 Kudos
qc4vmware
Virtuoso
Virtuoso

Not sure if this is what you are looking for but I have used this in the past to dump info on an object.  May have gotten this from Ilian Iliev actually.  You can probably modify it to get what you need.

0 Kudos
improvingdaily
Enthusiast
Enthusiast

Can you post the content?  Its a pain for me to try to pull in the workflow file into our system.  Its much easier for me to just recreate the workflow from a post.  I am still trying to find the best option here.  Thanks

0 Kudos
qc4vmware
Virtuoso
Virtuoso

It doesn't get much easier than importing a package but here are the guts of what is going on:

// the workflow takes any object so I created a wrapper workflow to pick a vm then pass that into the main workflow.

var obj = obj;

var properties = []; 

var other = [];

var methods = obj.class.getMethods(); 

for (var methodIndex in methods) { 

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

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

}

else {

other.push(methods[methodIndex].getName()); 

}

System.log("Attributes: " + properties.sort()); 

System.log("other: " + other.sort());

for each (var prop in properties) {

System.log(prop + " ::: " + obj[prop]);

}

​function getAllMethods(object) {

    return Object.getOwnPropertyNames(object).filter(function(property) {

        return typeof object[property] == 'function';

    });

}

System.log(getAllMethods(obj));

View solution in original post

0 Kudos
improvingdaily
Enthusiast
Enthusiast

Cool,  Thanks I think this will help.

0 Kudos