Effective December 3, NetApp adopts Microsoft’s Business-to-Customer (B2C) identity management to simplify and provide secure access to NetApp resources.
For accounts that did not pre-register (prior to Dec 3), access to your NetApp data may take up to 1 hour as your legacy NSS ID is synchronized to the new B2C identity.
To learn more, read the FAQ and watch the video.
Need assistance? Complete this form and select “Registration Issue” as the Feedback Category.

Active IQ Unified Manager Discussions

Unable to pass an array to a custom function

abuchmann

Hello everyone,

I'm stuck while implementing a workflow in our company.

What I would like to achive:

I would like to create a workflow with the following actions:

  1. User enters a server, a SID of an oracle db and the size for arch, data, log
  2. Creation of 3 volumes and qtree according to the data above
  3. Send an E-Mail with the complete "scli disk create" string to the user
  4. APPROVAL POINT
  5. Thin-provisioning of the LUNs

What I have done:

  • Copied and Customized the Send Email command
  • Created a custom command for thin provisioning

The commands

Send EMail with CMD

param (

  [parameter(Mandatory=$true, HelpMessage="SMTP server for sending the email item")]

  [string]$SmtpHost,

 

  [parameter(Mandatory=$true, HelpMessage="Recipient's SMTP email address")]

  [string]$To,

 

  [parameter(Mandatory=$true, HelpMessage="From field's SMTP email address")]

  [string]$From,

   

  [parameter(Mandatory=$true, HelpMessage="Subject of the email item")]

  [string]$Subject,

   

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

  [ValidateRange(1,65535)]

  [int]$SmtpPort = 25,

   

  [parameter(Mandatory=$false, HelpMessage="Use SSL for secure connection if server demands it")]

  [bool]$UseSsl = $false,

 

  [parameter(Mandatory=$true, HelpMessage="The command you would like to generate. Either sdcli disk connect or sdcli disk create")]

  [ValidateSet("connect", "create")]

  [string]$Action,

 

  [parameter(Mandatory=$true, HelpMessage="The Server which the LUNs should be mapped to")]

  [string]$Server,

 

  [parameter(Mandatory=$true, HelpMessage="Domain, which the server belongs to")]

  [string]$DomainName,

 

  [parameter(Mandatory=$true, HelpMessage="The name of the arrays, where the volumes where created")]

  [string]$Controller,

  [parameter(Mandatory=$true, HelpMessage="A list the luns to connect/create, like /vol/volumename/qtree/lunname.lun")]

  [array]$LunList,

 

  [parameter(Mandatory=$false, HelpMessage="A list of the size in GB")]

  [array]$SizeList,    

 

  [parameter(Mandatory=$true, HelpMessage="A list of the mountpoints")]

  [array]$MountList

)

function ConvertFromSecureToPlain{

    param(

        [Parameter(Mandatory=$true)]

        [System.Security.SecureString] $SecurePassword

    )

    # Create a "password pointer"

    $PasswordPointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)

 

    # Get the plain text version of the password

    $PlainTextPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto($PasswordPointer)

    # Free the pointer

    [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($PasswordPointer)

    # Return the plain text password

    $PlainTextPassword

}

if($UseSsl)

{

   if(!$SmtpUserName)

   {

        throw "FOr Secure Connection user details are mandatory"

   }

}

if($SmtpUserName)

{

 

    $SMTPCreds = Get-NaCredentials -Host $SmtpHost

    if (!$SmtpUserPassword -and !$SMTPCreds) {

        throw "Could not find SMTP credentials"

    }

    if ($SMTPCreds) {

        if ($SMTPCreds.Username -ne $SmtpUserName)

        {

            throw "Could not find SMTP credentials of user : " + $SmtpUserName

        }

    }

    if ($SMTPCreds) {

        $SmtpUserPassword =  ConvertFromSecureToPlain -SecurePassword $SMTPCreds.Password

    }

}

if(!$SmtpUserName -and $SmtpUserPassword)

{

    throw "Missing credentials information"

}

$smtpClient = New-Object System.Net.Mail.SmtpClient

$mailMessage = New-Object System.Net.Mail.MailMessage

$smtpClient.host = $SmtpHost

try

{

    $mailMessage.To.add($To)

}

catch

{

    throw "'To' value is not in the SMTP address format"

}

try

{

    $mailMessage.from = $From

}

catch

{

    throw "'From' value is not in the SMTP address format"

}

if( -not (-not $SizeList -or (($LunList.length -eq $SizeList.length) -and ($LunList.length -eq $MountList.length))))

{

          throw "LunList, SizeList and MountList must have the same amount of values"

}

$mailMessage.Subject = $Subject

#$mailMessage.Body = "Email from WFA system:`n"

#$mailMessage.Body += "Workflow Name = “ + $(Get-WfaRestParameter "workflowName") + "`n"

#$mailMessage.Body += "Workflow ID = “ + $(Get-WfaRestParameter "workflowId") + "`n"

#$mailMessage.Body += “Command Name = " + $(Get-WfaRestParameter "commandName") + "`n"

#$mailMessage.Body += “Job ID = " + $(Get-WfaRestParameter "jobId") + "`n"

#$mailMessage.Body += “Workflow executed by User = " + $(Get-WfaRestParameter "userName") + "`n"

# Customized by ABuchmann

$mailMessage.Body += "Führe folgende Zeilen auf dem Server " + $Server + " aus: `n`n"

for($i=0;$i -lt $LunList.Length;$i++)

{

          $Cmd  = "sdcli disk  " + $Action + " -d " + $MountList[$i] + " -p " + $Controller + ":" + $LunList[$i] + " -I %computername% iqn.1991-05.com.microsoft:%computername%." + $DomainName + " -dtype dedicated"

          if($Action -eq "create")

          {

                    $Cmd += " -rs n -z " + $SizeList[$i] + "GB"

          }

          $mailMessage.Body += $Cmd + "`n"

}

$mailMessage.IsBodyHtml = $False

if($SmtpUserName)

{

    $smtpClient.Credentials = New-Object System.Net.NetworkCredential($SmtpUserName, $SmtpUserPassword);

}

$smtpClient.Port = $SmtpPort

$smtpClient.EnableSsl = $UseSsl

Get-WFALogger -Info -message $("Sending email to " + $To)

$smtpClient.Send($mailMessage)


I tested the command above with the "Test"-Button in the "Command Definition"-window. Everything works fine, I can pass arrays to the variable $LunList, $SizeList, $MountList by separating the values using a comma and I am able to send/receive the mail.

But when I try to use the command inside of my workflow, I'm definitly not able to pass comma separated values to the command. it always fails with the following error:

Illegal expression: "/vol/" + datavolume.name + "/" + dataqtree.name + "/" + datavolume.name + ".lun","/vol/" + logvolume.name + "/" + logqtree.name + "/" + logvolume.name + ".lun","/vol/" + archvolume.name + "/" + archqtree.name + "/" + archvolume.name + ".lun"

At command 'Send Email with CMDs', tab 'Parameters', property 'LunList'

I also tried to pass a string list like "vol1", "vol2", "vol3" but I received the same error.

Is there a limitation with array?

It would be nice to use the "Send Email with CMDs"-Command because like that, it can be used for multiple Workflows with a different amount of LUNs

Kind regards,

Adrian

1 ACCEPTED SOLUTION

shailaja

Hi Adrian,

Well, I attempted your command in my setup and when I passed from the workflow the following string. Worked in preview. Did not try execution however.

"/vol/" + datavolume.name + "/" + dataqtree.name + "/" + datavolume.name + ".lun,/vol/" + logvolume.name + "/" + logqtree.name + "/" + logvolume.name + ".lun,/vol/" + archvolume.name + "/" + archqtree.name + "/" + archvolume.name + ".lun"

The difference between your parameter input and this one is that the comma between different lun names is within the quotes.

Thanks,

Shailaja

View solution in original post

4 REPLIES 4

sinhaa

Hello Adrian,

       I haven't tried your command code but l think I know the problem. Can you try providing double // instead of a single / in the Parameters in the workflow. I think this should work.

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

shailaja

Hi Adrian,

Well, I attempted your command in my setup and when I passed from the workflow the following string. Worked in preview. Did not try execution however.

"/vol/" + datavolume.name + "/" + dataqtree.name + "/" + datavolume.name + ".lun,/vol/" + logvolume.name + "/" + logqtree.name + "/" + logvolume.name + ".lun,/vol/" + archvolume.name + "/" + archqtree.name + "/" + archvolume.name + ".lun"

The difference between your parameter input and this one is that the comma between different lun names is within the quotes.

Thanks,

Shailaja

View solution in original post

abuchmann

You are right. Thank you!

May you also know more about the following issue:

If I use the function above to pass multiple volumes to the send-email-param. I sometimes have the problem that the value like

"/vol/" + datavolume.name + "/" + dataqtree.name + "/" + datavolume.name + ".lun,/vol/" + logvolume.name + "/" + logqtree.name + "/" + logvolume.name + ".lun,/vol/" + mastervolume.name + "/" + masterqtree.name + "/" + mastervolume.name + ".lun,/vol/" + snapvolume.name + "/" + snapqtree.name + "/" + snapvolume.name + ".lun"

is too long. I can add it to a command, but I'm unable to save the workflow as I always receive the following error:

Is there a reason why there's a limit of 256 characters per field? Is there a way to set a highter limit?

shailaja

Hi Adrian,

I assume you are referring to each individual field in  this screenshot which is about providing values to specific command parameters in the workflow design.

If yes, you are right that the limit is 255 characters in WFA releases of 2.0 and 2.0.1.

This has been fixed in the upcoming release of WFA 2.1. We were able to expand that limit to 2000 characters as of now.

WFA 2.1 will be available shortly.

Thanks,

Shailaja

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public