Forum Discussion

Malware_Mike_37's avatar
Malware_Mike_37
Icon for Altocumulus rankAltocumulus
Jan 28, 2019

Looking for guidance with the Python SDK

I've read the tutorial over a few times and I still find it very hard to figure out what syntax I need to use to do specific things.

 

For example: In the tutorial, it shows you can run commands via "mgmt.tm.util.bash.exec_cmd('run', utilCmdArgs='-c "tmsh show sys software"')"...so I go to the bigip.tm part of the "F5 SDK API docs" section and there's nothing there about what "bash.exec_cmd" or any other methods I can use with mgmt.tm.util. Is there something I am missing or what is the best way to figure out the complete power of this SDK?

 

Thank you advance!

 

  • F5 Python SDK is an assortment of convenient modules for Python users for accessing the iControl REST. And iControl REST is a wrapper for tmsh. So, for available options and usage, read the tmsh help.

    For example, tm.util.qkview is for the /mgmt/tm/util/qkview iControl REST endpoint, and it is for tmsh run util qkview. You can find the list of options from tmsh help util qkview.

    One of the options is -f for specifing the name of the qkview file. The following tmsh command creates a qkview file /var/tmp/sat1234

    tmsh run util qkview -f sat1234

    This iControl REST call (using curl) does the same:

     

     

    curl -sku : https:///mgmt/tm/util/qkview \
      -X POST -H "Content-type: application/json" \
      -d '{"command":"run", "utilCmdArgs":"-f sat1234"}' 
    

     

     

    And finally, the equivalent python sdk code.

     

     

    from f5.bigip import ManagementRoot
    mgmt = ManagementRoot('', '', '')
    bash = mgmt.tm.util.qkview.exec_cmd('run', utilCmdArgs='-f sat1234')
    

     

     

    See the Commands section of iControl REST User Guide Version 13.1, pp. 57-65, for the tmsh commands that do not directly correspond to the HTTP methods (such as run).

    To get a list of commands under tm.util (/mgmt/tm/util in iControl REST), type TAB in tmsh: e.g.,

     

    root@(ltm1311)(cfg-sync Standalone)(Active)(/Common)(tmos) run util [TAB]
    Components:
      admdb                  fips-card-sync         ping                   ssh-keyswap            unix-ls
      bash                   fips-util              ping6                  ssldump                unix-mv
      ccmode                 gencert                platform_check         sys-icheck             unix-rm
      clientssl-ciphers      get-ccn-dossier        platform_diag          tcpdump                updatecheck
      diadb                  get-dossier            qkview                 telnet                 vconsole
      dig                    ihealth                racoonctl              test-monitor           verify-encryption
      dnat                   imish                  scp                    tracepath              zebos
      domain-tool            ipsecalgdb             serverssl-ciphers      tracepath6
      establish-adfs-trust   lsndb                  sftp                   traceroute
      finalize-custom-ami    netstat                sipdb                  traceroute6