A question came up in Q&A concerning the iControl REST interface. When the requestor is using python, I try to point them to the f5-common-python sdk that has been available for nearly a year now. It is under constant development and we try to remove obstacles and make things consistent for the user. Take this request on creating nodes from community member Chanan. In looking at the return data, he is trying rewrite as a payload and submit as a post, using token auth to do so. Without the sdk, this can be accomplished like so:

import requests, json

# Ignore SSL Errors
requests.packages.urllib3.disable_warnings()

# Get Token Function
def get_token(bigip, url, creds):
    payload = {}
    payload['username'] = creds[0]
    payload['password'] = creds[1]
    payload['loginProviderName'] = 'tmos'

    token = bigip.post(url, json.dumps(payload)).json()

    return token['token']['token']

# Set up request session
b = requests.session()
b.headers.update({'Content-Type': 'application/json'})
b.auth = ('admin', 'admin')
b.verify = False
# Call token function to get token
token = get_token(b, 'https://192.168.102.5/mgmt/shared/authn/login',
                  ('admin', 'admin'))
# Update auth from basic to token
b.auth = None
b.headers.update({'X-F5-Auth-Token': token})

# Create a node with IP address
payload = {}
payload['name'] = 'node3'
payload['partition'] = 'Common'
payload['address'] = '192.168.102.101'
node3 = b.post('https://192.168.102.5/mgmt/tm/ltm/node', data=json.dumps(payload))

# Create a node with FQDN
payload = {}
fqdn = {'tmName': 'node4.test.local', 'autopopulate': 'disabled'}
payload['fqdn'] = fqdn
payload['name'] = 'node4'
payload['address'] = 'any6'
payload['partition'] = 'Common'
node4 = b.post('https://192.168.102.5/mgmt/tm/ltm/node', data=json.dumps(payload))

However, if you use the sdk, almost all this leg work is taken care of for you, leaving you to just create nodes:

import requests
from f5.bigip import ManagementRoot

# Ignore SSL Errors
requests.packages.urllib3.disable_warnings()

# Instantiate the BIG-IP
b = ManagementRoot('192.168.102.5', 'admin', 'admin', token=True)

# Create a node with IP address
node1 = b.tm.ltm.nodes.node.create(name='node1', address='192.168.102.100', partition='Common')

# Create a node with FQDN
node2 = b.tm.ltm.nodes.node.create(name='node2', address='any6', fqdn={'tmName': 'node2.test.local'}, partition='Common')

You don’t need to set those calls to variables for the nodes to be created, but if you want to do validation on the clientside it’s helpful to have those objects to interrogate.

Look for more sdk tips in the near future!