Guidelines for variables
You must be aware of the guidelines for PowerShell and Perl variables in OnCommand Workflow Automation (WFA) when you create a command or a data source type.
PowerShell variables
Guidelines | Example |
---|---|
For script input parameters:
|
|
For script internal variables:
|
|
For functions:
|
|
Variable names are not case-sensitive. However, to improve readability, you should not use different capitalization for the same name. |
|
Variable names should be in plain English and should be related to the functionality of the script. |
Use |
Declare the data type for each variable, explicitly. |
[string]name [int]size |
Do not use special characters (! @ # & % , .) and spaces. |
None |
Do not use PowerShell reserved keywords. |
None |
Group the input parameters by placing the mandatory parameters first followed by the optional parameters. |
param( [parameter(Mandatory=$true)] [string]$Type, [parameter(Mandatory=$true)] [string]$Ip, [parameter(Mandatory=$false)] [string]$VolumeName ) |
Comment all input variables using HelpMessage annotation with a meaningful help message. |
[parameter(Mandatory=$false,HelpMessage="LUN to map")] [string]$LUNName |
Do not use “Filer” as a variable name; use “Array” instead. |
None |
Use ValidateSet annotation in cases where the argument gets enumerated values. This automatically translates to Enum data type for the parameter. |
[parameter(Mandatory=$false,HelpMessage="Volume state")] [ValidateSet("online","offline","restricted")] [string]$State |
Add an alias to a parameter that ends with “_Capacity” to indicate that the parameter is of capacity type. |
The “Create Volume” command uses aliases as follows: [parameter(Mandatory=$false,HelpMessage="Volume increment size in MB")] [Alias("AutosizeIncrementSize_Capacity")] [int]$AutosizeIncrementSize |
Add an alias to a parameter that ends with “_Password” to indicate that the parameter is of password type. |
param ( [parameter(Mandatory=$false, HelpMessage="In order to create an Active Directory machine account for the CIFS server or setup CIFS service for Storage Virtual Machine, you must supply the password of a Windows account with sufficient privileges")] [Alias("Pwd_Password")] [string]$ADAdminPassword ) |
Perl variables
Guidelines | Example |
---|---|
For script input parameters:
|
|
Do not use abbreviations for script internal variables. |
|
Do not use abbreviations for functions. |
|
Variable names are case-sensitive. To improve readability, you should not use different capitalization for the same name. |
|
Variable names should be in plain English and should be related to the functionality of the script. |
Use |
Group the input parameters by placing the mandatory parameters first, followed by the optional parameters. |
None |
In GetOptions function, explicitly declare the data type of each variable for input parameters. |
GetOptions( "Name=s"=>\$Name, "Size=i"=>\$Size ) |
Do not use “Filer” as a variable name; use “Array” instead. |
None |
Perl does not include the |
if (defined$SpaceGuarantee&&!($SpaceGuaranteeeq'none'||$SpaceGuaranteeeq'volume'||$SpaceGuaranteeeq'file')) { die'Illegal SpaceGuarantee argument: \''.$SpaceGuarantee.'\''; } |
All Perl WFA commands must use the “strict” pragma to discourage the use of unsafe constructs for variables, references, and subroutines. |
use strict; # the above is equivalent to use strictvars; use strictsubs; use strictrefs; |
All Perl WFA commands must use the following Perl modules:
|
use Getopt::Long; use NaServer; use WFAUtil; |