Skip to main content
OnCommand Workflow Automation 5.1

Guidelines for variables

Contributors

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:

  • Use Pascal case.

  • Do not use underscores.

  • Do not use abbreviations.

$VolumeName

$AutoDeleteOptions

$Size

For script internal variables:

  • Use Camel case.

  • Do not use underscores.

  • Do not use abbreviations.

$newVolume

$qtreeName

$time

For functions:

  • Use Pascal case.

  • Do not use underscores.

  • Do not use abbreviations.

GetVolumeSize

Variable names are not case-sensitive. However, to improve readability, you should not use different capitalization for the same name.

$variable is the same as $Variable.

Variable names should be in plain English and should be related to the functionality of the script.

Use $name and not $a.

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:

  • Use Pascal case.

  • Do not use underscores.

  • Do not use abbreviations.

$VolumeName

$AutoDeleteOptions

$Size

Do not use abbreviations for script internal variables.

$new_volume

$qtree_name

$time

Do not use abbreviations for functions.

get_volume_size

Variable names are case-sensitive. To improve readability, you should not use different capitalization for the same name.

$variable is not the same as $Variable.

Variable names should be in plain English and should be related to the functionality of the script.

Use $name and not $a.

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 ValidateSet annotation for enumerated values. Use explicit “if” statements for cases where argument gets enumerated values.

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:

  • Getopt

    This is used for specifying input parameters.

  • WFAUtil

    This is used for utility functions that are provided for command logging, reporting command progress, connecting to array controllers, and so on.

use Getopt::Long;
use NaServer;
use WFAUtil;