VMware Cloud Community
modonnellAgFirs
Contributor
Contributor

Populate XaaS dropdown from Powershell script result (executeExternalPowershellScriptOnHostByName)

Has anyone gotten this action to work correctly?  Or done it a different way?  The example action executeExternalPowershellScriptOnHostByName in com.vmware.vra.powershell looks like exactly what I need.  The problem is that the return type on that action is properties.  That is not an available Entity type in vRA when I create the dropdown. 

When I duplicated this action and switch the return type to either string or array/String, it doesn't work at all.

Also, if anyone has gotten dropdowns to work from a powershell script result, I can do in a different direction.

Thanks

Reply
0 Kudos
18 Replies
ChrisMcCann
VMware Employee
VMware Employee

According to the documentation (PowerShell Script Custom Property Definition), you set the vRA interface type to "Dropdown" of "String" type.

Reply
0 Kudos
vklinden
VMware Employee
VMware Employee

Looking at it quickly, it appears that you would have to return host.name from the getHostByName function vs the whole host object. Let me know if that doesn't work, and I will dive in deeper on it.

Reply
0 Kudos
modonnellAgFirs
Contributor
Contributor

This is the error I get when I try to link it to the current executeExternalPowershellScriptOnHostByName.  I noticed it's looking for properties and not string so duplicated this action and changed the output type to string.  It's still not working. 

Reply
0 Kudos
vklinden
VMware Employee
VMware Employee

So that action for some reason requires the PowerShell Remote PS Object to return as properties vs a string which your script may be doing. In a scriptable task I am showing that I was able to comment out the section that requires it to be a properties object, and then the script runs fine. You could also change the outputType check to be Properties or String. I am not sure what type of PowerShell action would result in a dictionary vs a string... I would have to look more into how to tell PowerShell to return it as a dictionary through the PS Plugin.

Reply
0 Kudos
vklinden
VMware Employee
VMware Employee

This might  be helpful if you want the return type to be a properties. Your code needs to return a hashtable.

Working with PowerShell Results

Reply
0 Kudos
modonnellAgFirs
Contributor
Contributor

Here is more screenshots from the setup.  The dropdown is set to string, and the duplicated action was changed from properties as the return type to string. 

Another strange thing is that my /storage/log/VMware/vcac/catalina.log is not getting nearly the amount of information it had before.

I am seeing the correct result from the hastable coming from the powershell host int he log /var/log/vco/app-server/scripting.log

The powershell script I am running on the external powershell host is the same as what is used as an example in vro.  It's attached as well.


Reply
0 Kudos
vklinden
VMware Employee
VMware Employee

So help me understand what you are trying to accomplish. Are you trying to provide a dropdown for a user selectable script to run during a machine provisioning operation or do you want this to be an XaaS catalog item? Do you want dropdowns for all of the inputs to that action?

Reply
0 Kudos
vklinden
VMware Employee
VMware Employee

An action for a dropdown needs to return an array of strings because that array is used to populate the dropdown. You can use a dropdown for selecting the executed script, the powershell host, etc...) This action won't do anything for a dropdown though because of its return type unless you change that to be a return type of array/string.

Reply
0 Kudos
modonnellAgFirs
Contributor
Contributor

I have also tried array\string with the same result. 

What I am trying to accomplish is to populate the dropdown menu from the result of a powershell script.

Reply
0 Kudos
vklinden
VMware Employee
VMware Employee

The return type isn't actually an array/string or string since your return a properties from the executeExternalPowershellScriptOnHostByName action. You would have to modify the action to actually return that by looping over the properties object.

Reply
0 Kudos
vklinden
VMware Employee
VMware Employee

For example:

pastedImage_0.png

Reply
0 Kudos
modonnellAgFirs
Contributor
Contributor

I'll try your code.  What should I set the return type to be in vro? 

I was able to get a workaround by changing the executeExternalPowerShellScriptOnHostBYName by setting it back to properties after setting it up as a return type string to make the initial connection to vro.  Unfortunately it returned the values, but everything was in a single line and not populating the values and the label from the hashtable.

dropdown_set_properties.PNG

Reply
0 Kudos
vklinden
VMware Employee
VMware Employee

You will want the vRO return type to be array/string, and the XaaS form to be a string type.

The standard machine forms know how to handle properties objects (key-value pairs), but it seems the XaaS ones do not. The work around it to return an array/strings like you would expect with a dropdown.

Reply
0 Kudos
modonnellAgFirs
Contributor
Contributor

Thanks.  Could you post your code so I can copy and paste? 

Reply
0 Kudos
vklinden
VMware Employee
VMware Employee

Here you go

var script =  '& "' + externalScript + '" ' + arguments;

var output = System.getModule("com.vmware.vra.powershell").executePowerShellScriptOnHostByName(hostName, script);

var outputType = System.getObjectClassName(output);

if(outputType === "Properties") {

for each (item in outputType){

var list = [];

list.push(item.Value)

return list;

}

} else {

throw "Powershell Script has to return a Dictionary, actual output is '" + output.toString() + "' of type '" + outputType + "'";

}

Reply
0 Kudos
modonnellAgFirs
Contributor
Contributor

Thanks for posting this.  I was able to get this setup, but it's still not working.  This is something that may be relevant out of the catalina.out log

[UTC:2018-11-26 13:21:10,258 Local:2018-11-26 13:21:10,258] vcac: [component="cafe:advanced-designer" priority="WARN" thread="tomcat-http--28" tenant="me" context="GUx8K03f" parent="GUx8K03f" token="A9lbEYH0"] com.vmware.vcac.designer.service.impl.InventoryTypeServiceImpl.calculatePermissibleValues:119 - Cannot handle field 'com.vmware.vcac.platform.designer.data.layout.DesignerLayoutField@1ac7ea0a' with data type 'PrimitiveDataType[STRING]'. Only field with type 'ObjectDataType' are supported.

Reply
0 Kudos
vklinden
VMware Employee
VMware Employee

Does your workflow have inputs of an Object type? Looks like you have some sort of type mismatch. Component 1ac7ea0a is a string, but the workflow wants an ObjectDataType.

Reply
0 Kudos
modonnellAgFirs
Contributor
Contributor

All 3 inputs on the action are set to string.  The return type is set to Array/String.  The dropdown is set to string in vRA. 

Reply
0 Kudos