- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
External Python - How to retrieve/update custom field value
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2019 08:43 PM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2019 09:42 AM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2019 12:56 PM
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
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: External Python - How to retrieve/update custom field value
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 11:08 AM - edited 01-22-2019 11:09 AM
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))