Creating FQDN Nodes via iControl REST
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!
- Bien_Nguyen_ThaHistoric F5 Account
Dear experts, Management port on my BIG-IP was changed to 8443 instead of the 443 as default. I've tried to set: mgmt = ManagementRoot("1.1.1.1:8443", "admin", "admin")
and got this error: requests.exceptions.InvalidURL: Failed to parse: 1.1.1.1:8443:443 how can i set the new management port to 8443?
Thank you!
- JRahmAdmin
supply it as kwarg:
mgmt = ManagementRoot('x.x.x.x', 'admin', 'admin', port=8443)
- Bien_Nguyen_ThaHistoric F5 Account
Thank Jason!