Community

Subscribe
Highlighted
Accepted Solution

Invoking Command with no PowerShell cmdlet using WFA

We need to invoke the following commands "cf enable/disable" on a controller. From what we are seeing, there is no PowerShell cmdlet that allows this. Does anyone know of a way to invoke commands like this on a controller when the command does not have a PowerShell cmdlet?

I do see there is a Invoke-NaSsh, but we are not sure how to pass the "Credential" option to it through the WFA without having to manually type it in and exposing the password.

Re: Invoking Command with no PowerShell cmdlet using WFA

It would be pretty easy.  In your command, pass the Cluster name which has a stored username and password in the credential cache.  Use the folllowing snippet to pull the credential from the cache and apply to the command.

$credentials = Get-NaCredentials -Host <StorageArray>

Invoke-NcSsh -Name <StorageArray> -Command 'cf enable' -Credential $credentials

Jeremy Goodrum, NetApp

The Pirate

Twitter: @virtpirate

Blog: www.virtpirate.com

Re: Invoking Command with no PowerShell cmdlet using WFA

Jeremy,

Thank you for your response. Here is the code I am trying:

param (
[parameter(Mandatory=$true, HelpMessage="Controller")]
[string]$Controller

)

#Connect to controller
Connect-WFAController -A $Controller

$naCredentials = Get-NaCredential -Name $Controller

Invoke-NaSsh -Name $Controller -Command 'cf enable' -Credential $naCredentials

When I try to run this using the Test option for my command creation, it locks up with the cursor time watch and does not complete (not even with a failed).

What is the difference between NaSsh and NcSsh? We are 7-mode, not cluster mode.

Re: Invoking Command with no PowerShell cmdlet using WFA

*smacks his forehead* my eyes flipped and I said Invoke-NcSSH (for clustered Data ONTAP) instead of Invoke-NaSSH (for traditional Data ONTAP).  So it looks like the cmdlet does not work with the test feature (honestly, I hadn't tried to use that feature before).  I decided to create a quick command to checks the status of cluster failover and log the output.  This works just fine:

--------------------------------------------

param (

[parameter(Mandatory=$true, HelpMessage="Controller")]

[string]$Controller

)

#Connect to controller

Connect-WFAController -Array $Controller

$msg=Invoke-NaSsh -Command 'cf status'

Get-WFALogger -message ("Test-"+$msg)

--------------------------------------------

18:56:16.780 INFO  [Check Cf Status] ### Command 'Check Cf Status' ###

18:56:17.640 INFO  [Check Cf Status] Executing command: ./Check_Cf_Status6041434406201535123.ps1 -Controller 10.101.100.30

18:56:17.687 INFO  [Check Cf Status] Get-NaCredentials -Host 10.101.100.30

18:56:17.702 INFO  [Check Cf Status] Credentials successfully provided for '10.101.100.30'

18:56:17.718 INFO  [Check Cf Status] Connect-NaController (with credentials) -Name 10.101.100.30

18:56:18.796 INFO  [Check Cf Status] Connected to controller

18:56:19.421 DEBUG  [Check Cf Status] Cluster enabled, p1-3240cl2 is up.

RDMA Interconnect is up (Link 0 up, Link 1 up).

18:56:19.499 INFO  [Check Cf Status] Command completed, took 2719 milliseconds

Re: Invoking Command with no PowerShell cmdlet using WFA

There actually are a couple of PowerShell Toolkit cmdlets for cf enable/disable.  They are simply Disable-NaCluster and Enable-NaCluster.  (And, there's Get-NaCluster for cluster status info.)

There's also a command that already does this (change cluster failover monitor status) in the Day-0 example workflow, published here:

https://communities.netapp.com/docs/DOC-20088

Hope this helps,

Dave

Message was edited by: Dave Boone - added Get-NaCluster comment.

Re: Invoking Command with no PowerShell cmdlet using WFA

Regarding the use of Invoke-NaSsh cmdlet from within a WFA command:

Once you use Connect-WFAController, you don't need to set credentials.  The default credentials are set automatically. 

Looking at your code, you probably want to use a PowerShell variable to capture the output (STDOUT, STDERR) from Invoke-NaSsh.  Just a guess, but WFA may not be handling that output well.  For example, instead of this:

Invoke-NaSsh -Name $Controller -Command 'cf enable' -Credential $naCredentials

try this:

$retVal = Invoke-NaSsh -Name $Controller -Command 'cf enable'

(The better choice would be to use the cmdlet, Enable-NaCluster, but I just wanted to help with using Invoke-NaSsh with WFA in general.)

To take this a few steps further, here are some error checking routine ideas for both checking that Invoke-NaSsh executes successfully, and for parsing the output the command returns:

# connect to controller
Connect-WFAController -Array $Array

# Check that the fileName is in the right location on the array.
if ( ! ( Invoke-NaSsh -Command "software list" | Select-String "\s*$fileName\s*" -Quiet ) )
{
$msg = "Can't find the file $fileName in /etc/software on $Array.  Please make sure the software is staged properly in /etc/software."
throw $msg
}

# Perform the software operation
try
{
$retVal = Invoke-NaSsh -Command "software update $fileName $options"
}
catch
{
$msg = "Failed to upgrade software on: " + $Array + ". Message: " + $_.Exception.Message;
throw $msg
}

if($retVal.StartsWith("WARNING:") -or $retVal.StartsWith("ERROR:") )
{
throw $("Software update error occurred: `n" + $retVal)
}
else
{
Get-WFALogger -Info -message $("Software: " + $fileName + " updated successfully on:  " + $Array)
}

(Above code is part of the '0day - Software Update' command in the Day-0 7-mode example workflow.)

Happy coding,

Dave

Re: Invoking Command with no PowerShell cmdlet using WFA

Thank You all for your responses! I will defenitley go with the cf enable/disable cmdlets (must have missed them), but I really appreaciate seeing how to use the Invoke-NaSsh if we were to ever run into a command in the future where we needed it!