Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

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!

0
Rate this Question
Comments on this Question
Comment made 3 weeks ago by Stephane Viau 121
0
Comment made 3 weeks ago by Malware Mike 121

So if I go to : https://f5-sdk.readthedocs.io/en/latest/apidoc/f5.bigip.tm.util.html#module-f5.bigip.tm.util.qkview

It shows I can use bash with f5.bigip.tm.util.bash, but it says nothing about what options to use...but I just clicked on the source and it gives even more info.

Thank you

0

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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 <user>:<pass> https://<host>/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('<host>', '<user>', '<pass>')
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
1
Comments on this Answer
Comment made 3 weeks ago by Malware Mike 121

This was very helpful as well, thank you! I now have an idea of what I need to do.

0