- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
easy.broker('CustomFields') not working as expected- any thoughts?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-10-2018 10:38 AM
Hello,
I am trying to extract the real switch model from 'show inventory' using the sample API code from netmri_easy.
When running it, i am getting the following error:
*** Error / Traceback (most recent call last): File "", line 155, in File "/usr/lib/python3.4/site-packages/infoblox_netmri/api/broker/v3_2_0/custom_fields_broker.py", line 167, in create_field return self.api_request(self._get_method_fullname("create_field"), kwargs) File "/usr/lib/python3.4/site-packages/infoblox_netmri/api/broker/broker.py", line 24, in api_request params File "/usr/lib/python3.4/site-packages/infoblox_netmri/client.py", line 227, in api_request return self._make_request(url=url, method="post", data=data) File "/usr/lib/python3.4/site-packages/infoblox_netmri/client.py", line 103, in _make_request return self._send_request(url, method, data, extra_headers) File "/usr/lib/python3.4/site-packages/infoblox_netmri/client.py", line 129, in _send_request raise HTTPError(res.json(), response=res) requests.exceptions.HTTPError: {'message': 'The action failed because the request was not valid.', 'fields': {'model': ['is required'], 'name': ['is required'], 'type': ['is required']}, 'error': 'general/validation-failed'} *** swc1.4103# swc1.4103#terminal no monitor swc1.4103#terminal no editing swc1.4103#terminal length 0 swc1.4103#
The script i am trying is as follows:
# BEGIN-SCRIPT-BLOCK # # Script-Filter: # $vendor eq "Cisco" # # END-SCRIPT-BLOCK from infoblox_netmri.easy import NetMRIEasy import re # This values will be provided by NetMRI before execution defaults = { "api_url": api_url, "http_username": http_username, "http_password": http_password, "job_id": job_id, "device_id": device_id, "batch_id": batch_id } # Create NetMRI context manager. It will close session after execution with NetMRIEasy(**defaults) as easy: field_name = "RealModel" #custom field creation broker = easy.broker('CustomFields') broker.create_field( model='Device', name=field_name, type='string' ) # get device device = easy.get_device() inventory = easy.send_command('show inventory') rmodel = re.search('(?<=PID: ).*$', inventory).group() if rmodel: # Custom field creation # all custom fields should start with 'custom_' device_broker = easy.broker('Device') field_name = "custom_{}".format(field_name) params = { 'DeviceID': device.DeviceID, field_name: rmodel } result = device_broker.update(**params) print(result.custom_RealModel)
Anyone have any ideas where this is going wrong?
Thanks, Daniel
Re: easy.broker('CustomFields') not working as expected- any thoughts?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-10-2018 10:44 AM - edited 09-10-2018 10:45 AM
As an FYI- I get the same error running the sample as-is, with no modification of the regex search or field name.
Re: easy.broker('CustomFields') not working as expected- any thoughts?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-13-2018 06:18 AM
I'll look at it today
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: easy.broker('CustomFields') not working as expected- any thoughts?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-14-2018 08:47 AM
I got it to work by removing:
print(result)
I have looked into that yet
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: easy.broker('CustomFields') not working as expected- any thoughts?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-14-2018 10:28 AM
I commented out the print(result) line, but still got the error.
If i comment out the field creation portion, since the field is already in the system, i get the following error about deviceIds.
***
Re: easy.broker('CustomFields') not working as expected- any thoughts?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-14-2018 10:45 AM
It's funny, I ran it 3x now on the same box and no issue at all, I wonder if you need to reset your sandbox or something else going on
# BEGIN-SCRIPT-BLOCK # # Script-Filter: # $vendor eq "Cisco" # # END-SCRIPT-BLOCK from infoblox_netmri.easy import NetMRIEasy import re # This values will be provided by NetMRI before execution defaults = { "api_url": api_url, "http_username": http_username, "http_password": http_password, "job_id": job_id, "device_id": device_id, "batch_id": batch_id } # Create NetMRI context manager. It will close session after execution with NetMRIEasy(**defaults) as easy: field_name = "RealModel" #custom field creation broker = easy.broker('CustomFields') broker.create_field( model='Device', name=field_name, type='string' ) # get device device = easy.get_device() inventory = easy.send_command('show inventory') rmodel = re.search('(?<=PID: ).*$', inventory).group() if rmodel: # Custom field creation # all custom fields should start with 'custom_' device_broker = easy.broker('Device') field_name = "custom_{}".format(field_name) params = { 'DeviceID': device.DeviceID, field_name: rmodel } result = device_broker.update(**params) print(result)
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: easy.broker('CustomFields') not working as expected- any thoughts?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-14-2018 11:35 AM
Yea, this is strange. I reset the sandbox but am still getting the error.
I'm not seeing anything that could be missing, and if you are running the same code with no issues, something must be broken internally.
Re: easy.broker('CustomFields') not working as expected- any thoughts?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-14-2018 11:39 AM
I'm running "7.3.1.90807"
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: easy.broker('CustomFields') not working as expected- any thoughts?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-14-2018 11:58 AM
I am still on 7.2.1.87960.