Subscribe

WFA Command - Distribute configuration files with pscp

Hi there,

I am struggling to write a command which should basically distribute a list of configuration-files from WFA-Host to a specfic Linux-Host.

Basically I am trying to utilize putty "pscp" within a WFA-Command and concatenate the list of files as an array. I am able to run a pscp command on the powershell-cli. But in WFA I do get errors while trying to save the command.

Here is my code snippet. Are there any other solutions out there

++++

param (

  [parameter(Mandatory=$false, HelpMessage="Hostname or IP address")]

  [string]$SourceHostName,

 

[parameter(Mandatory=$false, HelpMessage="Hostname or IP address")]

  [string]$TargetHostName,

[parameter(Mandatory=$false, HelpMessage="UserName")]

  [string]$UserName,

 

[parameter(Mandatory=$false, HelpMessage="PrivateKeyFile in openSSH Format")]

  [string]$PrivateKeyFile="D:\Downloads\opensshkey",

 

[parameter(Mandatory=$false, HelpMessage="PrivateKeyFile in openSSH Format")]

  [string]$PathToPSCPEXE="D:\temp\pscp.exe",

 

  [parameter(Mandatory=$false, HelpMessage="PrivateKeyFile in openSSH Format")]

  [string]$UploadPath="/tmp/wfa_plugin/",

 

  [parameter(Mandatory=$false, HelpMessage="")]

  [string]$FileCloneXML="D:\NetApp\wfa_plugins\build1\clone_S96.xml",

[parameter(Mandatory=$false, HelpMessage="")]

  [string]$FileDBCloneMountDB="D:\NetApp\wfa_plugins\build1\db_clone_mount_db.sh",

  [parameter(Mandatory=$false, HelpMessage="")]

  [string]$FileDBClonePurgeFS="D:\NetApp\wfa_plugins\build1\db_clone_purge_fs.sh",

 

  [parameter(Mandatory=$false, HelpMessage="")]

  [string]$FileDBCloneStartDB="D:\NetApp\wfa_plugins\build1\db_clone_start_database.sh",

  [parameter(Mandatory=$false, HelpMessage="")]

  [string]$FileDBCloneStopDB="D:\NetApp\wfa_plugins\build1\db_clone_stop_database.sh",

  [parameter(Mandatory=$false, HelpMessage="")]

  [string]$FileDBCloneUmount="D:\NetApp\wfa_plugins\build1\db_clone_umount.sh"

)

try

{

     $PathToUploadFile = $FileCloneXML, $FileDBCloneMountDB, $FileDBCloneUmount, $FileDBClonePurgeFS, $FileDBCloneStartDB, $FileDBCloneStopDB

     if ($TargetHostname)

        {

            $Arguments = "-i", $PrivateKeyFile, $PathToUploadFile,($UserName,"@",$TargetHostName,":",$UploadPath,$PathToUploadFile.Split("\")[-1] -join "")

            & $PathToPSCPEXE $Arguments

        }

catch

{

      Get-WFALogger -Warn -message ("Failed")

}

Re: WFA Command - Distribute configuration files with pscp

I am not an expert in powershell script. However i modified the script a little and I am able to save.

Let us know if you need any more help.

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

param (

  [parameter(Mandatory=$false, HelpMessage="Hostname or IP address")]

  [string]$SourceHostName,

 

[parameter(Mandatory=$false, HelpMessage="Hostname or IP address")]

  [string]$TargetHostName,

[parameter(Mandatory=$false, HelpMessage="UserName")]

  [string]$UserName,

 

[parameter(Mandatory=$false, HelpMessage="PrivateKeyFile in openSSH Format")]

  [string]$PrivateKeyFile="D:\Downloads\opensshkey",

 

[parameter(Mandatory=$false, HelpMessage="PrivateKeyFile in openSSH Format")]

  [string]$PathToPSCPEXE="D:\temp\pscp.exe",

 

  [parameter(Mandatory=$false, HelpMessage="PrivateKeyFile in openSSH Format")]

  [string]$UploadPath="/tmp/wfa_plugin/",

 

  [parameter(Mandatory=$false, HelpMessage=" ")]

  [string]$FileCloneXML="D:\NetApp\wfa_plugins\build1\clone_S96.xml",

[parameter(Mandatory=$false, HelpMessage=" ")]

  [string]$FileDBCloneMountDB="D:\NetApp\wfa_plugins\build1\db_clone_mount_db.sh",

  [parameter(Mandatory=$false, HelpMessage=" ")]

  [string]$FileDBClonePurgeFS="D:\NetApp\wfa_plugins\build1\db_clone_purge_fs.sh",

 

  [parameter(Mandatory=$false, HelpMessage=" ")]

  [string]$FileDBCloneStartDB="D:\NetApp\wfa_plugins\build1\db_clone_start_database.sh",

  [parameter(Mandatory=$false, HelpMessage=" ")]

  [string]$FileDBCloneStopDB="D:\NetApp\wfa_plugins\build1\db_clone_stop_database.sh",

  [parameter(Mandatory=$false, HelpMessage=" ")]

  [string]$FileDBCloneUmount="D:\NetApp\wfa_plugins\build1\db_clone_umount.sh"

)

try

{

     $PathToUploadFile = $FileCloneXML, $FileDBCloneMountDB, $FileDBCloneUmount, $FileDBClonePurgeFS, $FileDBCloneStartDB, $FileDBCloneStopDB

     if ($TargetHostname)

        {

            $Arguments = "-i", $PrivateKeyFile, $PathToUploadFile,($UserName,"@",$TargetHostName,":",$UploadPath,$PathToUploadFile.Split("\")[-1] -join "")

            & $PathToPSCPEXE $Arguments

        }

}

catch

{

      Get-WFALogger -Warn -message ("Failed")

}

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

-Abhi

Re: WFA Command - Distribute configuration files with pscp

Abhi, many thanks for your quick response. I was able to save the cmdlet within WFA. Right now I am testing the file copies with pscp. Once successful I`m going to post here the final implementation.

Re: WFA Command - Distribute configuration files with pscp

Hi rtoubali,

Without having to install pscp and jump through hoops, you can use the built-in PowerShell Toolkit cmdlets "Read-NaFile" and "Write-NaFile".  If it's for clustered ONTAP, there are similar cmdlets, "Read-NcFile", and "Write-NcFile".

I posted an example workflow/command here: https://communities.netapp.com/docs/DOC-23962#comment-16913

There's also a thread talking about issues with blank lines and workarounds here:

https://communities.netapp.com/message/104746#104746

Hope this helps.

Cheers,

Dave