Utils

BIGREST has a Python module called utils that has multiple useful functions.
Use these functions to help you work with iControl REST API.

rest_format

Code

bigrest.utils.utils.rest_format(text: str) str

Converts a string to be compatible with iControl REST API.

Parameters:

text – String to be converted.

Example

path = (
    f"/mgmt/tm/ltm/pool/{rest_format('/bigrest/bigrest_pool')}"
    f"/members/{rest_format('/bigrest/172.17.0.1%1:80')}"
)
device.delete(path)

Explanation

iControl REST API requires “/” to be converted to “~”.
Also requires “%” (used for route domains) to be converted to “%25”.

token

Code

bigrest.utils.utils.token(device: str, username: str, password: str, login_provider: str = 'tmos', debug: str = None, verify: bool = True, timeout: int = 10) str

Gets a token from the device.

Parameters:
  • device – Name or IP of the device to send the REST requests.

  • username – Username used to login to the device.

  • password – Password used to login to the device.

  • login_provider – Login provider used to authenticate the user.

  • debug – Debug file name to be used to output the debug information.

  • verify – Disables SSL certificate validation if set to False

  • timeout – Specifies the number of seconds to wait when sending requests to the device.

Exceptions:

InvalidOptionError: Raised when invalid options are used as arguments.

Example

token_ = token("192.168.255.1", "admin", "password")

Explanation

This function is mainly used to test the BIGREST itself.
However, you can use to generate a token, that can be used in other tools.
If you are just working with BIGREST, either BIGIP or BIGIQ classes, it can use token internally if you enable token.
If you pass the debug keyword with filename, when iControl REST API returns an error, BIGREST will create the file with debug information.
The information will include the HTTP full request sent to the device, and the HTTP full response received from the device.

refresh_token

Code

bigrest.utils.utils.refresh_token(device: str, username: str, password: str, login_provider: str = 'tmos', debug: str = None, verify: bool = True, timeout: int = 10) str

Gets a refresh token from the device.

Parameters:
  • device – Name or IP of the device to send the REST requests.

  • username – Username used to login to the device.

  • password – Password used to login to the device.

  • login_provider – Login provider used to authenticate the user.

  • debug – Debug file name to be used to output the debug information.

  • verify – Disables SSL certificate validation if set to False

  • timeout – Specifies the number of seconds to wait when sending requests to the device.

Exceptions:

InvalidOptionError: Raised when invalid options are used as arguments.

Example

refresh_token_ = refresh_token("192.168.255.1", "admin", "password")

Explanation

This function is mainly used to test the BIGREST itself and only works with BIG-IQ (BIG-IP does not implement refresh token).
However, you can use to generate a refresh token, that can be used in other tools.
If you are just working with BIGREST, BIGIQ class only, it can use refresh token internally if you provide a refresh token.
If you pass the debug keyword with filename, when iControl REST API returns an error, BIGREST will create the file with debug information.
The information will include the HTTP full request sent to the device, and the full HTTP response received from the device.