XModem
Enthusiast
Enthusiast

Construct PowerShell:PowerShellHost object

Jump to solution

Hello everyone!

I'm trying to get an vRO Action to retrieve something dynamically through a PowerShell script and then feed it back into a vRA 7.x Property.

For this I must create a vRO Action, that works autonomously, i.e. I would have to work with either default values, or with parameters passed through from the vRA environment.

But by my current experience with plugin scripting classes, they have no constructor within vRO, opposed to a regular OO programming language. You usually retrieve the objects from the vRO environment or retrieve them through existing script commands and work with them.

I can't see how I am supposed to do this with PowerShell. There are no default PowerShell hosts definable, I cannot pass a PowerShellHost from vRA property to a vRO Action, can't work with attributes (carrying default values) within Actions and can't construct a PowerShellHost dynamically, so I'm a bit stumped as to what to do here.

Any advice?

- Jonas

1 Solution

Accepted Solutions
Hazenet
Enthusiast
Enthusiast

In your action you could also do something like:

var powershellHosts = Server.findAllForType("PowerShell:PowerShellHost",null);


That would give you an array of all PowerShell Hosts in the vRO Inventory.

Then you would have to loop thru them (hoping you don't have a lot of PowerShell Hosts), and find the right one.


The right one, could then be determined by some identifier string value, you pass along from vRA as a input to the Action.

View solution in original post

6 Replies
iiliev
VMware Employee
VMware Employee

Hi Jonas,

It is not true that scripting classes do not have constructors per se. It is up to plug-in author/designer to decide which objects should have constructors and which should have not. For example, PowerShellCommand scripting class has a constructor.

A vRO action can have input(s) of type PowerShellHost or return PowerShellHost as a result.

I'm not familiar with PowerShell plug-in in details, but looking at workflows/actions it provides, it seems there are several options to 'construct' PowerShellHost dynamically:

  • There is a workflow 'Add a PowerShell host'. You can execute this workflow passing the input parameters, and the workflow will return a PowerShellHost object.
  • There is an action com.vmware.library.powershell.configuration.addPowerShellHost (used by the above workflow) that instantiates PowerShellHostConfig object, populates its fields, and passes it to PowerShellHostManager.update(...) method, and as a result you'll get PowerShellHost object.
XModem
Enthusiast
Enthusiast

First of all, thanks for your answer. I think it's entirely possible that vRO plugin scripting classes have constructors and my wording was wrong - I've just not seen any so far.

Your solution would mean, I'd have always to to re-create such a host and then delete it again after I've executed my script within the vRO Action. I can't re-use existing PowerShell hosts. It's a very ugly solution, but it's something I could work with if push comes to shove.

Can you suggest improvments to this plugin in this regard, internally? Or is someone watching with something to say on this? Smiley Wink

0 Kudos
Hazenet
Enthusiast
Enthusiast

In your action you could also do something like:

var powershellHosts = Server.findAllForType("PowerShell:PowerShellHost",null);


That would give you an array of all PowerShell Hosts in the vRO Inventory.

Then you would have to loop thru them (hoping you don't have a lot of PowerShell Hosts), and find the right one.


The right one, could then be determined by some identifier string value, you pass along from vRA as a input to the Action.

igaydajiev
VMware Employee
VMware Employee

> I'd have always to to re-create such a host and then delete it again after I've executed my script

No need to recreate it every time.

It can be created once and then passed as parameter to any workflow/action where needed.

If you create vRO workflow with input parameter of type PowerShell:PowerShellHost when starting the workflow you can select which PSHost to be used from VRO client.

As already pointed by Mads Fog Albrechtslund if you need to use it inside scripting you can always use var powershellHosts = Server.findAllForType("PowerShell:PowerShellHost",null); and apply your custom logic to select given host.


0 Kudos
XModem
Enthusiast
Enthusiast

As I stated in the original post, I'm trying to create a vRO Action which only takes a limited type of parameters passed from vRA7, which does not include any fancy-shmancy types like PowerShellHost, basically only strings. Please read the original post before you reply.

0 Kudos
XModem
Enthusiast
Enthusiast

That was the one I was looking for, but I obviously was looking within PowerShell plugin methods and classes, not considering that generic classes and methods exist for that. Thanks!

0 Kudos