F5 BIG-IP iControl REST API client

1.3.13 · abandoned · verified Thu Apr 16

The `f5-icontrol-rest` Python library simplifies interaction with the F5 BIG-IP iControl REST API. It manages HTTP sessions (leveraging `requests.Session`), handles URI validation, and provides integrated logging. This generic library is used by other F5 SDKs and projects for programmatic communication with BIG-IP and BIG-IQ devices via the REST API. [1, 4, 5, 7] As of version 1.3.13, the project's GitHub repository is archived and no longer maintained.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a session with an F5 BIG-IP device using `iControlRESTSession` and perform a basic GET request to retrieve LTM NAT objects. Ensure to replace placeholder credentials and host with actual values, preferably using environment variables for security. It disables SSL verification for simplicity, which should be avoided in production environments. [1, 5]

import os
from icontrol.session import iControlRESTSession

BIGIP_HOST = os.environ.get('F5_BIGIP_HOST', 'your_bigip_ip_or_hostname')
BIGIP_USER = os.environ.get('F5_BIGIP_USER', 'admin')
BIGIP_PASS = os.environ.get('F5_BIGIP_PASSWORD', 'password')


try:
    # Initialize the session
    icr_session = iControlRESTSession(BIGIP_USER, BIGIP_PASS, address=BIGIP_HOST)

    # Example: Get a list of all LTM NAT objects in Common partition
    # Note: For versions < 1.3.13, 'proxies' kwarg only works on method calls, not instantiation.
    response = icr_session.get(
        f'https://{BIGIP_HOST}/mgmt/tm/ltm/nat',
        name='*', 
        partition='Common',
        uri_as_parts=True,
        verify=False # Use with caution in production without proper certs
    )

    print(f"Successfully connected to {BIGIP_HOST}.")
    print("LTM NAT objects:")
    for item in response.json().get('items', []):
        print(f"  - Name: {item.get('name')}, Partition: {item.get('partition')}")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →