Active IQ Unified Manager Discussions

Return LunId from Map LUN in WFA

tomekp
4,839 Views

Hi all,

 

I'm writing a WFA to create a new Volume/LUN and map it to existing igroup. User have an option to specify LunID.  I want to be able to verify if the LunID is available on the 'preview' level, to prevent wofklow execution fails if user specify the lunID that is already used.

 

I copied certified command "Map LUN" to "Map LUN_verify_lunID" to have an option to edit it a little bit.

 

Everything works fine, if user specify LunID that is already used, WFA returns error, because I have put verification in my command "Map LUN_verify_lunID":

 

Select
    lunmap.lun_id,
    lunmap.lun_map_value,
    lun.name
from
    cm_storage.lunmap,
    cm_storage.igroup,
    cm_storage.lun,
    cm_storage.vserver
where
    igroup.id = lunmap.igroup_id
    AND igroup.name = '${IgroupName}'
    AND lunmap.lun_map_value = '${LunId}'
    AND lunmap.lun_id = lun.id
    AND lun.vserver_id = vserver.id
    AND vserver.name = '${VserverName}'

 

(By the way, is there any option to modify the 'Planning failed' message to something more specific than 'element existance issue detected during validation of command...') ? 🙂

 

 

What I'm trying to achieve is to return host LUN id.  I kind of succeeded, by modyfying my powershell code for "Map LUN_verify_lunID" to:

 

 

[...]

Get-WFALogger -Info -message $("Mapping LUN : " +  $LunName)
if($LunId -ne "")
{
Add-NcLunMap -Path $LunPath -InitiatorGroup $IgroupName -VserverContext $VserverName -Id $LunId } else { Add-NcLunMap -Path $LunPath -InitiatorGroup $IgroupName -VserverContext $VserverName $Lundetails = Get-NcLunMap -Path $LunPath -VserverContext $VserverName | where-object InitiatorGroup -eq $IgroupName $LunId = $lundetails.LunId } Get-WFALogger -Info -message $("Lun ID : " + $LunId) #'------------------------------------------------------------------------------ #' return LunID to WFA #'------------------------------------------------------------------------------ Add-WfaWorkflowParameter -Name "LunId" -Value $LunId -AddAsReturnParameter $True

I'm assuming the scenario where User does not specify any LunID in the entry parameters.

 

LunID is successfuly returned after workflow execution. However is it possible to get the LunID during workflow preview ?

5 REPLIES 5

mbeattie
4,775 Views

Hi,

 

You can use some MVEL wizardy to invoke SQL queries within your command to map the LUN to next available LUN ID

Here is an example of how to create an MVEL function that returns the next LUN ID for a vserver.

 

function get_next_lun_id(svm_name){
   import java.sql.*;  
   //Connect to local WFA DB using the built-in credentials
   String query= 'select max (lunmap.lun_map_value) + 1 as lunmax from cm_storage.lunmap, cm_storage.igroup, cm_storage.vserver where lunmap.igroup_id = igroup.id and igroup.vserver_id = vserver.id and vserver.name = \'' + svm_name + '\'';
   Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/","wfa","Wfa123");
   Statement stmt=con.createStatement();  
   ResultSet rs=stmt.executeQuery(query);  
   //Query is executed, loop over every row and fetch the columns.
   String s=; 
   while(rs.next()){
      s = rs.getString('lunmax');
   }
   return s;
}

Setting the credentials within the function isn't ideal although it is a read-only user. Thought this might give you some ideas or options.

 

/Matt

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

tomekp
4,754 Views

Thanks Matt! I will try to play with that a little bit 🙂

Paul_Yu
4,697 Views

Hi tomekp,

 

Thank you for sharing this!  I am new to WFA.  How would I access this return value in the next function?  I am creating a workflow which will create the datastore with the new LUN and it requires LUN ID.

 

Thanks,

Paul

tomekp
4,612 Views

Hi Paul,

Apologies for delayed answer 🙂 Assuming You have 'exported' Your lunID with powershell:

 

Add-WfaWorkflowParameter -Name "LunId" -Value $LunId -AddAsReturnParameter $True



In your next powershell code, you can retrieve this parameter by command:


$YourVariableForLUNid = Get-WfaWorkflowParameter -Name LunId

best regards,

tomek

Paul_Yu
4,585 Views

Thank you!  That works.

Public