|
| 1 | +Debugging API calls |
| 2 | +=================== |
| 3 | + |
| 4 | +New in version 3.0.10. |
| 5 | + |
| 6 | +.. toctree:: |
| 7 | + |
| 8 | +The F5 SDK provides an abstraction on top of the actual F5 REST API. We've discussed in |
| 9 | +other pages, however, that this is a rather loose abstraction. In reality, it follows the |
| 10 | +actual API design a lot more than would be typical of other SDKs. |
| 11 | + |
| 12 | +Despite this close adherence to the API, there may come a time where users of the SDK |
| 13 | +(or tools built on top of it) need a more familiar set of information than method calls |
| 14 | +to debug a problem. For this purpose we've made available the `cURL` command equivalents |
| 15 | +that the F5 SDK makes. |
| 16 | + |
| 17 | +When the F5 SDK is used to make an API call, it will keep track of these calls and make |
| 18 | +them available to the user in an attribute of the ``ManagementRoot`` called `_debug`. |
| 19 | + |
| 20 | +Let's look at an example of how to trigger this tracing. |
| 21 | + |
| 22 | +Tracing calls |
| 23 | +------------- |
| 24 | + |
| 25 | +API tracing **always** happens. The trace information is available to you regardless of |
| 26 | +whether you ask for it or not. It is discarded, however, if you destroy the ``ManagementRoot`` |
| 27 | +object. |
| 28 | + |
| 29 | +Consider the following SDK usage |
| 30 | + |
| 31 | +.. code-block:: python |
| 32 | +
|
| 33 | + from f5.bigip import ManagementRoot |
| 34 | + mgmt = ManagementRoot('localhost', 'admin', 'admin', port=10443, token=True) |
| 35 | + resource = mgmt.tm.ltm.pools.pool.create(name='foobar') |
| 36 | +
|
| 37 | +This SDK call communicates with a BIG-IP to create an LTM pool. What if you needed to recreate |
| 38 | +this API call in a more familiar tool like cURL? How would you know what exactly the API |
| 39 | +called so that you could re-create the exact cURL command. |
| 40 | + |
| 41 | +Tools like Postman have a handy "Code" link to give you your actual API calls. The F5 SDK |
| 42 | +has a very similar feature that happens automatically under the hood for you. |
| 43 | + |
| 44 | +You can view the commands generated by the code above by printing the ``._debug`` property |
| 45 | +of the ``mgmt`` object. This property contains a list of items. Therefore, for readability, |
| 46 | +let's print each of them. |
| 47 | + |
| 48 | +.. code-block:: python |
| 49 | +
|
| 50 | + for x in mgmt._debug: |
| 51 | + print(x) |
| 52 | +
|
| 53 | +When this is done, we will be presented with output that resembles the following (printed for readability). |
| 54 | + |
| 55 | +.. code-block:: python |
| 56 | +
|
| 57 | + curl -k -X GET \ |
| 58 | + https://localhost:10443/mgmt/tm/sys/ \ |
| 59 | + -H 'Connection: keep-alive' \ |
| 60 | + -H 'Accept-Encoding: gzip, deflate' \ |
| 61 | + -H 'Accept: */*' \ |
| 62 | + -H 'User-Agent: python-requests/2.18.4 f5-icontrol-rest-python/1.3.4' \ |
| 63 | + -H 'Content-Type: application/json' \ |
| 64 | + -H 'X-F5-Auth-Token: 2PXGGMT4QR3Y3PAQEEURAPB5DJ' |
| 65 | +
|
| 66 | + curl -k -X POST \ |
| 67 | + https://localhost:10443/mgmt/tm/ltm/pool/ \ |
| 68 | + -H 'Connection: keep-alive' \ |
| 69 | + -H 'Accept-Encoding: gzip, deflate' \ |
| 70 | + -H 'Accept: */*' \ |
| 71 | + -H 'User-Agent: python-requests/2.18.4 f5-icontrol-rest-python/1.3.4' \ |
| 72 | + -H 'Content-Type: application/json' \ |
| 73 | + -H 'Content-Length: 18' \ |
| 74 | + -H 'X-F5-Auth-Token: 2PXGGMT4QR3Y3PAQEEURAPB5DJ' \ |
| 75 | + -d '{"name": "foobar"}' |
| 76 | +
|
| 77 | +As you can see, there are a couple of commands there. In particular, the second command is the command that |
| 78 | +created the pool in the above SDK code. |
| 79 | + |
| 80 | +What about the first item in the list though. What is its relevance? This is an implementation detail of the |
| 81 | +SDK. To provide the functionality that it does, the SDK needs to know what version of the REST API is |
| 82 | +being used. This is accomplished by the first command there. From the response of that command, we get the |
| 83 | +version of the REST API. |
| 84 | + |
| 85 | +.. note:: |
| 86 | + |
| 87 | + The commands shown in the trace are only a convenient illustration of what the SDK is doing. The SDK |
| 88 | + is **not** using cURL for the work it does. |
| 89 | + |
| 90 | +These commands are useful in exploring how the SDK actually behaves. One area where they come in particularly |
| 91 | +handy is in the process of debugging errors, or, in implementing new functionality. |
| 92 | + |
| 93 | +You can copy and paste the commands as they are printed and use them to issue the same API calls the the |
| 94 | +equivalent SDK code does. |
0 commit comments