Day-0 Command Example - Setting OnTap Options

by bdave Former NetApp Employee on ‎2012-05-18 08:17 AM - edited on ‎2014-09-25 02:54 PM by allison Former NetApp Employee

This command takes Controller name or IP, OptionName, and OptionValue.  It sets OptionName to OptionValue on the Controller specified.  It uses try/catch so errors should be detected.  I'm also posting a sample workflow that uses this command.

 

To use this command, save the attached file and add a .dar extension. 

Comments
pitrakou Former NetApp Employee

Just added this into my WFA commands, and looking good thus far, well it previews ok 

bdave Former NetApp Employee

Cool.  Let me know how you like it. 

pitrakou Former NetApp Employee

Yup I do like it, allows me to set the options that I need. Out of interest, how do you use the error trapping, so in this:
 

try

{
     Set-NaOption -OptionName
}


catch

{
      $msg = "Failed to set OnTap option: " + $OptionName + " to value: " + $OptionValue + ". Message: " + $_.Exception.Message;

      throw $msg
}


Can you use this to error out the workflow to stop it? The reason I ask I need to be able to run a command on the console, so modified what you wrote to use the

Invoke-NaSsh -Command $Command


But if I put in a bogus command WFA still show this as successfull, so it doesnot look like the error trapping is working?

bdave Former NetApp Employee

Cool.  Glad it's working for you.  It can be used for a lot of things, since so many things are controlled by options.

Absolutely, the 'try' will check all the commands in the code block for errors.  If one occurs, the 'catch' section will be executed.  The 'throw' function then causes the PowerShell command to exit with an error condition.  WFA will consider the Command failed and halt the workflow.

Now, the brilliance here is that someone monitoring WFA execution status can see that the workflow failed, go fix whatever caused it to fail, then 'resume' the workflow.  This retains all the user input variables, etc, and resumes the workflow by retrying the Command that failed.  If it succeeds, the workflow keeps on going like nothing ever happened.  To do this, right-click on the failed workflow from Execution Status and choose "Resume".

WFA resume.png

This works for failed workflows, not aborted/cancelled workflows.

Cheers,

Dave

pitrakou Former NetApp Employee

Hmmm that's odd indeed. So in my code to run a command, this does not seem to work. For example if I get it to run the command "options autosupport.enable 123", which will give a error on the console, it does not return anything.... very odd.

Any thoughts on the below?

This is the code:

param (
  [parameter(Mandatory=$true, HelpMessage="Array name or IP address")]
  [string]$Array,

  [parameter(Mandatory=$true, HelpMessage="Command to run")]
  [string]$Command
)

# connect to controller
Connect-WFAController -Array $Array

Get-WFALogger -Info -message $("Excecuting command: " + $Command + " : on Filer ")

#Execute command

try
{
Invoke-NaSsh -Command $Command
}
catch
{
$msg = "Failed to run the command: " + $Command + " to Array: " + $Array + $_.Exception.Message;
throw $msg
}

bdave Former NetApp Employee

Yes, I think what's happening there is that the actual PowerShell command is "working", it does invoke SSH and it may execute the command, so 'try' may not be seeing an error. 

In my opinion, where there's a PowerShell Toolkit equivalent, it's better to use that than the SSH command.

Also, I have been seeing oddities with PowerShell when I put more than one parameter in the same variable.  I don't know if that has anything to do with your situation or not.

But, the way I've seen others code for Invoke-NaSsh failures is to put the output in a variable and parse that for a string that would indicate a failure, like:

$result = Invoke-NaSsh -Name $DFMServerName -Command $("dfpm dataset create " + $DatasetName)

if ($result.StartsWith("Error:"))
{
    throw $result
}

In this particular case, it would seem a) my command is better.   b) the failed options command has output that starts with the word "option" so if you want to make yours work, try using something like:

$result = Invoke-NaSsh -Command $Command

if ($result.StartsWith("option"))
{
    throw $result
}

Hope this helps,

Dave

pitrakou Former NetApp Employee

Thanks Dave,

It's a pity that console commands (and perhaps the Invoke-NaSsh function) does not return a pass/fail flag I did think about parsing the results after capturing them into an array (have done this in other PowerShell scripts quite successfully) but I was hoping to make this more of a generic command. In fact what I am trying to do is set the lun reservation to disabled after creating the lun with Snap Drive, so trapping the word "option" won't really help me here.

Oh well guess I will just have to blindly run the command and hope for the best. Thanks for your help, and yes your version is better

Cheers

Tony

Occasional Contributor

It won't import into 2.2.0.2.4RC1

bdave Former NetApp Employee

Hmmm....  I haven't tried it on 2.2.  What errors are you getting?

bdave Former NetApp Employee

Also, it's been a while.  I remember updating this command for 2.1.  It may not have been uploaded to this thread, but you can find the updated command and some comments about it in this other post:

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

Thanks,

Dave

Warning!

This NetApp Community is public and open website that is indexed by search engines such as Google. Participation in the NetApp Community is voluntary. All content posted on the NetApp Community is publicly viewable and available. This includes the rich text editor which is not encrypted for https.

In accordance to our Code of Conduct and Community Terms of Use DO NOT post or attach the following:

  • Software files (compressed or uncompressed)
  • Files that require an End User License Agreement (EULA)
  • Confidential information
  • Personal data you do not want publicly available
  • Another’s personally identifiable information
  • Copyrighted materials without the permission of the copyright owner

Files and content that do not abide by the Community Terms of Use or Code of Conduct will be removed. Continued non-compliance may result in NetApp Community account restrictions or termination.