Forum Discussion

Archie_128388's avatar
Archie_128388
Icon for Nimbostratus rankNimbostratus
May 26, 2016
Solved

Passing variables directly from iApps to TMSH.

Try as I might I just can't seem to work out how to get an iApp to pass a command to TMSH.

I am trying to automate (via an iApp) the setup of around 300 GRE tunnels. I've created the iApp at the presentation section and made sure my variables have the correct information by writing them to scriptd.out via "puts"

For Example, once a user fills in the fields presented to them via presentation, the resulting command set of variables is:

Presentation Form:

This would then translate into:

puts [format "Example GRE Loopback command: %s" $::NONFLOAT$::GRESourceLoopback__lb-$::GRESourceLoopback__diocese-$::GRESourceLoopback__orgid$::IPADDRESS$::GRESourceLoopback__loopback/32$::TRAFFICGROUP$::VLANLOOPBACK]

When I send it to the Log file the actual command reads:

create /net self zscaler-wcf-gre-source-nonfloat-lb01-dbb-12345 address 10.4.200.200/32 traffic-group traffic-group-local-only vlan zscaler-wcf-gre-loopback

How do I pass that command straight to TMSH from the Implementation part of the iApp?

I've tried to get my head around iapp::conf but I don't understand what may need to "escaped" or not in the variables.

Thanks....

  • This is useful for when scripting tmsh: Documentation for tmsh scripting Commands.

     

    Looks like tmsh create is the syntax you are looking to use here.

     

    app::config procedure is nice as it returns the object name of the object created and handles the appropriate tmsh scripting command based on input (create/modify/delete). Although, you will need to escape brackets and a few other characters such as backslashes.

     

5 Replies

  • Greg_Crosby_319's avatar
    Greg_Crosby_319
    Historic F5 Account

    This is useful for when scripting tmsh: Documentation for tmsh scripting Commands.

     

    Looks like tmsh create is the syntax you are looking to use here.

     

    app::config procedure is nice as it returns the object name of the object created and handles the appropriate tmsh scripting command based on input (create/modify/delete). Although, you will need to escape brackets and a few other characters such as backslashes.

     

    • Fred_Slater_856's avatar
      Fred_Slater_856
      Historic F5 Account

      iapp::conf is a wrapper for tmsh::create/modify/delete that automatically logs the command in /var/tmp/scriptd.out to cut down on the need for debugging "puts" statements like the one you used. iapp::conf also prevents command duplication, which you may or may not be interested in. In order for iapp::conf to return the object name, however, it depends on the convention that the object name contains an underscore character ("_"). Since zscaler-wcf-gre-source-nonfloat-lb01-dbb-12345 contains no underscores, the proc runs but returns a null string. I do not see anything in your example that would require escaping. The use of [format] is harmless but probably unnecessary. Either of the following should work in implementation:

      tmsh::create $::NONFLOAT$::GRESourceLoopback__lb-$::GRESourceLoopback__diocese-$::GRESourceLoopback__orgid$::IPADDRESS$::GRESourceLoopback__loopback/32$::TRAFFICGROUP$::VLANLOOPBACK
      or
      iapp::conf create $::NONFLOAT$::GRESourceLoopback__lb-$::GRESourceLoopback__diocese-$::GRESourceLoopback__orgid$::IPADDRESS$::GRESourceLoopback__loopback/32$::TRAFFICGROUP$::VLANLOOPBACK
      
    • Fred_Slater_856's avatar
      Fred_Slater_856
      Historic F5 Account

      BTW, if you want to be more explicit with the boundaries of your variable names, use curlies, like this:

      tmsh::create 
      ${::NONFLOAT}${::GRESourceLoopback__lb}-${::GRESourceLoopback__diocese}- \
      ${::GRESourceLoopback__orgid}${::IPADDRESS}${::GRESourceLoopback__loopback}/32 \
      ${::TRAFFICGROUP}${::VLANLOOPBACK}
      
    • Archie_128388's avatar
      Archie_128388
      Icon for Nimbostratus rankNimbostratus
      Excellent. Thank you Gentlemen. I will try these suggestion and report back.