Wednesday, August 30, 2017

Debug WFA in your Powershell editor

I use this script all the time, when I'm debugging new wfa commands in powershell.

This script is run on the wfa server (my laptop in my case).  It loads the WFA libraries and adds the default functions
- Get-WfaLogger
- Get-WfaCredentials
- Connect-WfaCluster
- Connect-WfaController
- Set-WfaCommandProgress




When you open your powershell, just run it once, and you are ready to start testing.
Note at the top that it will set the current directory to my desktop (change it to what your default testing directory is)


cd 'C:\Program Files\NetApp\WFA\PoSH\'
. '.\profile.ps1'

cd 'c:\users\mirko\desktop'

function Get-WFALogger{
    param(
        [switch] $Info,
        [switch] $Error,
        [switch] $Warn,
        [string] $Message
    )

    if($Info){
        Write-Host $Message -foregroundColor green
    }
    if($Warn){
        Write-Host $Message -ForegroundColor yellow
    }
    if($Error){
        Write-Host $Message -ForegroundColor red
    }

}
function Get-WfaCredentials($hostname){
   if($hostname -eq "be-pslab.local"){
        $u = "mirko"
        $p = "Netapp12"
   }
   if($hostname -eq "localhost"){
        $u = "admin"
        $p = "Netapp12"
   }
   if($hostname -eq "slash.local"){
        $u = "administrator"
        $p = "Netapp12"
   }
   # add more entries if needed
   # if($hostname -eq ....

   $secpasswd = ConvertTo-SecureString $p -AsPlainText -Force
   return New-Object System.Management.Automation.PSCredential ($u, $secpasswd)
    
}
function Get-WfaInputPassword($EncryptedPassword){
    return $EncryptedPassword
}

function Connect-WfaCluster($Node,$Vserver){
    if($Vserver){
        Connect-NcController -Name $Node -Vserver $Vserver
    }else{
        Connect-NcController -Name $Node
    }
}

function Connect-WfaController($Array,$Vfiler){
    if($Vfiler){
        Connect-NaController -Name $Array -Vfiler $Vfiler
    }else{
        Connect-NaController -Name $Array
    }
}


function Set-WfaCommandProgress($Total,$Current,$ProgressPercentage,$Note){
    if($ProgressPercentage -eq 100){
        Write-Progress   -Activity 'Wfaloop' -Completed
        $global:wfaloopcomplete=$true
    }
    else{
        Write-Progress  -Activity 'Wfaloop'  -status ("$Current" + "/" + "$Total") -percentComplete $ProgressPercentage -currentOperation $Note
    }
}

function Get-WfaRestParameter($name){
    switch($name){
        "userName" {"dummy_user"}
        "workflowName" {"dummy_workflow"}
        "workflowId" {123}
        "jobId"{ 987 }
    }
}

# DATASOURCE LOGGING FUNCTIONS
# LOG INFO
function LogInfo($t){
      Write-Host $t -ForegroundColor Yellow
}
 
# LOG DEBUG
function LogDebug($t){
      Write-Host $t -ForegroundColor Cyan
}
 
# LOG WARN
function LogWarn($t){
      Write-Warning $t
}
 
# LOG ERROR
function LogError($t){
      Write-Host $t -ForegroundColor Red
}
 
# LOG FATAL (throws error & exit)
function LogFatal($t){
      Write-Host $t -ForegroundColor Magenta
}

No comments :

Post a Comment