Active IQ Unified Manager Discussions

Working with Variables

knorman
5,696 Views

I’m working on my first WFA development project and have ran into a hurdle I can’t seem to jump over. I ‘m looking for the way to take a location a user specifies and turn it into a local cluster name.  From there I’ll be selecting an aggregate to create a new volume in for a new VMware datastore.

I created the short bit of code below to translate datacenter location to the correct site cluster name as a couple sites have multiple cluster but only one for VMware.  My issue is feeding this newly assigned cluster name into the rest of the workflow so it uses the $ClusterName variable specified below throughout the workflow.  I’m not necessarily looking for a complete solution but rather the general way to make this work.

param (

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

  [string]$DCLocation,

 

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

  [string]$ClusterName

)

if ($DCLocation = 'Valley Forge')

            {$ClusterName = 'Amazon'}

elseif ($DCLocation = 'Denver')

            {$ClusterName = 'Phoenix'}

elseif ($DCLocation = 'Ft. Worth')

            {$ClusterName = 'Griffin'}

5 REPLIES 5

dhruvd
5,620 Views

Hi knorman,

If the version of WFA that you are using is 2.2, you can make use of the powershell commandlets Add-WfaWorkflowParameter and Get-WfaWorkflowParameter. These will help you to add a parameter in one of the commands, which can then be accessed in any of the commands that follow.

You will have add "ClusterName" as a parameter in the command where you are translating the DCLocation to ClusterName in the following manner:

$ParameterName = "ClusterName"

$ParameterValue = $ClusterName

Add-WfaWorkflowParameter -Name $ParameterName -Value $ParameterValue

You can then get this parameter in the other command codes in the following way:

$ParameterName = "ClusterName"

$val = Get-WfaWorkflowParameter -Name $ParameterName

Note: You will not be able to access $ClusterName in other places in the workflow such as filters/loops. This variable will be scoped at command level only.

adaikkap
5,620 Views

Hi Norman,

What you are really trying to do is resource selection based on location of the user who invoke the workflow.

For this you you will somehow need do a mapping of the location to user to resource. In such situation we generally recommend to use playground database to do such persistent mapping.

  • If the mapping is mostly static, then you can use a playground DB and store the mapping from location to cluster name
  • Or, you could use a function to return cluster name given the location and then use that to load the “Cluster by key” in a no-op command
  • After that the rest of the workflow can use the cluster variable where it would be properly filled i.e cluster.name

Other way is

  • Store in playground DB the mapping
  • First user input can be location $Location
  • Once chosen, the next locked query based user input named $ClusterName will be based on $Location (This is query based, but will always have single item in drop-down)

Solution Courtesy, Shailaja

Regards

adai

olson
5,587 Views

Greetings,

                There was a previous conversation that included something that would solve your problem with a function. With a function you can create this sort of hash map.

 

def regionMap(region) {

  return ['Americas' : 'am', 'EMEA' : 'em', 'APAC' : 'ap', 'Switzerland' : 'ch', 'Singapore' : 'sn', 'Hong Kong' : 'hk'].get(region);

}

 

def locationMap(location) {

return ['Singapore':'sg','Tokyo':'tk','Sydney':'sy','Hong Kong':'hk','New York':'ny','London':'ln','Pune':'pn','Mumbai':'mu','Jakarta':'jk','Seoul':'se','Bangkok':'bk','Shanghai':'sh','Kuala Lumpur':'kl','Beijing':'bj','Taipei':'tp','Bangalore':'bg','Atlanta':'at','Boston':'bs','Buenos Aires':'ba','Calgary':'cg','Cayman Islands':'ci','Chicago':'cc','Dallas':'da','Houston':'hs','Las Angeles':'la','Mexico':'mx','Miami':'mi','Philadelphia':'ph','Raleigh':'ra','San Francisco':'sf','Toronto':'to','West Palm Beach':'wp','Paris':'pa','Dubai':'du','Doha':'do','Dublin':'db','Poland':'po','Madrid':'md','Milan':'ml','Turkey':'tu'].get(location);

}

 

To call it in your workflow you can simply use

(String)(regionMap($region)

 

volumeName

if ( $workflowMethod == 'Specified' ) { return ($INPUT_Volume) } else { return 'v' + (String)(regionMap($region)) + (String)(businessUnitMap($bu)) + (String)(useCaseMap($useCase)) }

 

vfilerName

if ( $workflowMethod == 'Specified' ) { return ($INPUT_VfilerName) } else { return 'vf' + (String)(regionMap($region)) + (String)(businessUnitMap($bu)) + (String)(useCaseMap($useCase)) + (String)(environmentMap($env)) }

 

 

trentino123
5,540 Views

In the workflow setup, I would add 2 CONSTANTS, 1 is the LOCATION and another is the CLUSTER. Both have a string separated by commas ( they are an array ).

 

LOCATION = "location1,location2,location3,location4"

CLUSTER = "cluster1,cluster4,cluster1,cluster1"

 

Then with a function we could get an index number of the location and place then place the cluster in a variable ( CLUSTER ) we could use to list the aggregates.

 

trentino123
5,528 Views

If working with a CSV file is not a problem ( to have a new datasource you could use in your SQL queries within the user inputs ), here is a 5min video that explains how to do it :

 

http://community.netapp.com/t5/OnCommand-Storage-Management-Software-Articles-and-Resources/Video-Building-your-first-script-based-custom-datasource-u...

Public