tough_siberian_
Enthusiast
Enthusiast

How to get the package workflow belongs to?

Jump to solution

Hi!

Is there a better way to get package (or package list) the workflow belongs to in the script (which is a part of the same workflow), rather than iterating over all server packages and finding specified workflow in them?

Thank you.

0 Kudos
1 Solution

Accepted Solutions
cdecanini_
VMware Employee
VMware Employee

Some code sample. I have updated his from some code I worte so please test it. You need to pass it the workflowId you are looking for.

var allPackages = Server.findAllForType("Package");
var packagesForWorkflow = new Array();

for each (var pack in allPackages) {

    for each (var wf in pack.workflows) {
        if (wf.id == workflowId) packagesForWorkflow.push(pack);
    }

}

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 vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter

View solution in original post

0 Kudos
9 Replies
tschoergez
Leadership
Leadership

No, neither in the vCO Scripting API nor the REST API 😞

Cheers,

Joerg

cdecanini_
VMware Employee
VMware Employee

Also this workflow could be in 0 to n packages.

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 vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
tough_siberian_
Enthusiast
Enthusiast

So the resulting array could contain 0 to N entries Smiley Happy.

0 Kudos
tough_siberian_
Enthusiast
Enthusiast

After investigating a little bit, I found, that there's no easy way to get the list of all installed packages (or maybe I haven't dug deep enough?). If there would be such a way, then I would just iterate over all packages, looking for their workflows having same ID as workflow I am currently running ("workflow.currentWorkflow.id") as I assumed in my first post. But it looks, that to do that I need to register local vCO instance as its own RemoteServer and then I get "RemoteServer.findAllPackages()" method.

That is getting too complicated and time consuming (RemoteServer registration can take minutes).


So I probably will use another approach: in a workflow I'll create an attribute with "Package" type pointing to the package containing this workflow. As I checked, this approach survives "package export/package delete with content/package import" cycle, so after package import attribute still holds proper reference to the package which was just imported.


Can anybody suggest better way to achieve it?

0 Kudos
cdecanini_
VMware Employee
VMware Employee

If you have to do this on remote vCo server then you can use the REST plug-in.

HTTP get on /packages/ gets all the package list

/package/packageName/ get all the content of a workflow.

You will get JSON strings. You can convert these to object doing var pckgDetail = eval(jsonString);

Here is an example when getting the package content

var workflows = pckgDetail.workflows;
        for (var w = 0; w < workflows.length; w++) {
            var workflow = workflows[w];
            var attributes = workflow.attributes;
   
            for (var j = 0; j < attributes.length; j++) {
                var attribute = attributes[j];
                if (attribute.name == "id") {
                    if (attribute.value == workflowId) {

                         packageArray.push(pckgDetail.name);

                    }
                }
            }  
        }

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 vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
tough_siberian_
Enthusiast
Enthusiast

If I understand correctly then I can use REST plug-in of vCO server to make queries against itself?

If so, then this would be viable solution. Smiley Happy

I will try this, thanks.

0 Kudos
cdecanini_
VMware Employee
VMware Employee

If I recall well there is a scripting API for packages so you can list the details of these without using REST. This of course only works if you use a single vCO server.

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 vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
cdecanini_
VMware Employee
VMware Employee

Some code sample. I have updated his from some code I worte so please test it. You need to pass it the workflowId you are looking for.

var allPackages = Server.findAllForType("Package");
var packagesForWorkflow = new Array();

for each (var pack in allPackages) {

    for each (var wf in pack.workflows) {
        if (wf.id == workflowId) packagesForWorkflow.push(pack);
    }

}

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 vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
tough_siberian_
Enthusiast
Enthusiast

Exactly what I need.

Thank you.

I didn't expect that this method can return packages.

0 Kudos