VMware Cloud Community
eoinbyrne
Expert
Expert
Jump to solution

Powershell plugin question - dynamically creating a PowerShellHost instance in a workflow

Hi Folks,

Has anyone done this for a host which has never been in the vCO PowerShell inventory? Specifically, how does Kerberos cope with a hostname that might have been re-created since the last time Kerberos tried to authenticate for access to it?

Cheers

Reply
0 Kudos
1 Solution

Accepted Solutions
eoinbyrne
Expert
Expert
Jump to solution

Just wanted to let anyone that was interested know

I got this to work by doing the following in a script

var hostConfig = new PowerShellHostConfig()

hostConfig.name = "example";

     .

     .

     .

     .

     <fill in hostConfig member values>

// get the plugin to create a host instance from this config using the update call

var host = PowerShellHostManager.update(hostConfig);

If the config is correct then you get a valid host instance which you can now invoke commands on. Looking at the Java code for the plugin, the update method does the following

Check the config for a host ID

     If ID is found

          then locate that instance & return it

     else

          create and validate a new host instance for this config and return that


There are some side effects  / gotchas to consider here though


Gotcha 1.     PowerShellHostConfig has no member attribute for a host ID so you will always create a new instance using this method. New instances will be listed in your inventory as duplicate configs with different instance IDs

Gotcha 2.     While validating the hostConfig during host creation, a test connection is made using the specified config. This means you'll see that logged in the server log file so it will look like two connections were made in quick succession if you then do an invoke on the new host

Gotcha 3.     Because of gotcha 1 you should probably do PowerShellHostManager.remove(host) at the end of your script

Gotcha 4.     If you use 3 to keep the inventory clean be aware that if your script/workflow exits with an error/exception then the remove might not happen. So, use Error handling or Finally clause to ensure it gets executed. Obviously if the remove throws an error then all bets are off Smiley Happy

Anyway just thought I'd share

View solution in original post

Reply
0 Kudos
1 Reply
eoinbyrne
Expert
Expert
Jump to solution

Just wanted to let anyone that was interested know

I got this to work by doing the following in a script

var hostConfig = new PowerShellHostConfig()

hostConfig.name = "example";

     .

     .

     .

     .

     <fill in hostConfig member values>

// get the plugin to create a host instance from this config using the update call

var host = PowerShellHostManager.update(hostConfig);

If the config is correct then you get a valid host instance which you can now invoke commands on. Looking at the Java code for the plugin, the update method does the following

Check the config for a host ID

     If ID is found

          then locate that instance & return it

     else

          create and validate a new host instance for this config and return that


There are some side effects  / gotchas to consider here though


Gotcha 1.     PowerShellHostConfig has no member attribute for a host ID so you will always create a new instance using this method. New instances will be listed in your inventory as duplicate configs with different instance IDs

Gotcha 2.     While validating the hostConfig during host creation, a test connection is made using the specified config. This means you'll see that logged in the server log file so it will look like two connections were made in quick succession if you then do an invoke on the new host

Gotcha 3.     Because of gotcha 1 you should probably do PowerShellHostManager.remove(host) at the end of your script

Gotcha 4.     If you use 3 to keep the inventory clean be aware that if your script/workflow exits with an error/exception then the remove might not happen. So, use Error handling or Finally clause to ensure it gets executed. Obviously if the remove throws an error then all bets are off Smiley Happy

Anyway just thought I'd share

Reply
0 Kudos