Network Change & Configuration Management

Reply
Highlighted

External Python - How to retrieve/update custom field value

Authority
Posts: 29
2764     0

Anyone have equiviant external python statements for:

 

Retrieve device custom field in perl:

 $device->get_custom_field("role")

 

Update device custom field (named "role") in perl:

 $device->update_custom_field({DeviceID=>$device->DeviceID,custom_role=> "Route Reflector"});

 

 Thanks!

Re: External Python - How to retrieve/update custom field value

Authority
Posts: 29
2765     0

Based on the documentation, I tried this:

 

#!/bin/env/python

 

import requests

import json

from infoblox_netmri.client import InfobloxNetMRI

 

 

defaults = {

 "host": "x.x.x.x",

 "username": "zzzzzzzzz",

 "password": "yyyyyyyy",

}

 

 

client = InfobloxNetMRI(

 defaults.get("host"),

 defaults.get("username"),

 defaults.get("password"),

)

 

 

broker = client.get_broker('Device')

devices = broker.index(DeviceType=['Router', 'Switch-Router'], DeviceID='2925323')

 

for device in devices:

   print("{} {} {} ".format(device.DeviceID, device.DeviceName.upper(), device.custom_test))

 

   field_name = "custom_{}".format('test')

   params = {

      'DeviceID':device.DeviceID,

      field_name:'test123'

   }

 

   result = broker.update(**params)

 

   print(result)

 

Which returned:

 

2925323 I9894 Hello
Traceback (most recent call last):
File "./netmri6.py", line 34, in <module>
result = broker.update(**params)
File "/usr/lib/python2.7/site-packages/infoblox_netmri-3.2.0.0-py2.7.egg/infoblox_netmri/api/broker/v3_2_0/device_broker.py", line 2181, in update
return self.api_request(self._get_method_fullname("update"), kwargs)
File "/usr/lib/python2.7/site-packages/infoblox_netmri-3.2.0.0-py2.7.egg/infoblox_netmri/api/broker/broker.py", line 27, in api_request
if class_name in data:
TypeError: argument of type 'NoneType' is not iterable

 

I got back the value of the custom field 'test' which was 'Hello'.  But, I wasn't able to update the value to "test123".

 

 

Re: External Python - How to retrieve/update custom field value

Adviser
Posts: 401
2765     0

I don't use that client but I will test it out via REST and that client later in the week and let you know

 

Sif

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

Re: External Python - How to retrieve/update custom field value

[ Edited ]
mshamilcm
Techie
Posts: 1
2765     0

This seems to modify the value and print the before and after values for a custom field named test. 

 

for device in devices:

 

   print("{} {} {}".format(device.DeviceID, device.DeviceName.upper(),device.custom_test))

   params = {

 

      'DeviceID':device.DeviceID,'custom_test':'newvalue'

   }

   result = broker.update_custom_field(**params)

 

 

broker2 = client.get_broker('Device')

 

devicess = broker.index(DeviceType=['Switch'], DeviceID='330')

for d in devicess:

 

   print("{}".format(d.custom_test))

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You