Forum Discussion
Chanan_Berler_3
Nimbostratus
Jan 28, 2017Create node fails
Hi All,
When running i get this error message - can anyone help?
{'apiError': 1,
'code': 400,
'errorStack': [],
'message': 'Found invalid JSON body in the request.'}
Thanks
Chanan
lo...
JRahm
Admin
Jan 30, 2017With the f5-common-python sdk:
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')
Without the sdk:
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'}
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))
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects