Network Change & Configuration Management

Reply
Highlighted

NetMRI: Create discovery setting with REST API and python

cshaad123
Techie
Posts: 9
3400     0

I am using the infoblox_netmri module, which has been working fine for a few other requests that I tried.  In order to get the module to work though I had to edit two lines:

 

41: for opt in reqd_opts + default_opts.keys():    -->   for opt in reqd_opts + list(default_opts.keys()):

102: return json.loads(r.content)  --> return json.loads(r.content.decode())

 

c = infoblox_netmri.InfobloxNetMRI({
'url': 'https://x.x.x.x/api/3',
'username': 'xxxx',
'password': 'xxxx',
'sslverify': False
})

devices = c.api_request('discovery_settings/create', {'range_value': '2.2.2.2', 'range_type': 'STATIC', 'discovery_status': 'INCLUDE'})

 I haven't had any issues when trying discovery_settings/index or discovery_settings/destroy, but when using discovery_settings/create I get:

 

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://x.x.x.x/api/3/discovery_settings/create

 

And here is the API page:

 

URI: /api/3/discovery_settings/create

Available Since: API v3

Privilege Required: sysadmin

Feature Required: None

Creates a new discovery setting.

Inputs

  • range_value Required String
    The discovery setting value.
  • range_type Required String
    The discovery setting range type (CIDR, RANGE, SEED, STATIC, WILDCARD).
  • discovery_status Required String
    The discovery mode of the discovery setting (INCLUDE, EXCLUDE, IGNORE).
  • UnitID Optional Integer, Default: 0
    The internal Network Automation identifier collector assigned to the discovery setting.
  • ping_sweep_ind Optional Boolean, Default: 0
    A flag indicating if ping sweeps are used on the discovery setting.
  • virtual_network_id Optional Integer, Default: 0
    A Virtual Network identifier assigned to the discovery setting.
  • start_blackout_schedule Optional String, Default:
    The blackout start time in cron format.
  • blackout_duration Optional Integer, Default: 0
    The blackout duration in minutes.
  • start_port_control_blackout_schedule Optional String, Default:
    Port Control Blackout schedule in CRON format
  • port_control_blackout_duration Optional Integer, Default: 0
    Port Control Blackout duration in minutes

 

Outputs

  • id Integer
    The id of the newly created discovery setting.
  • model String
    The class name of the newly created discovery setting.
  • uri String
    A URI that may be used to retrieve the newly created discovery setting.
  • discovery_setting DiscoverySetting
    The newly created discovery setting.

Thanks for any assistance!

 

Re: NetMRI: Create discovery setting with REST API and python

cshaad123
Techie
Posts: 9
3401     0

Disregard, it looks like at one point it had worked and the errors are because the 2.2.2.2 is already in the database -_-

Re: NetMRI: Create discovery setting with REST API and python

Adviser
Posts: 357
3401     0

I wonder why you needed those changes. What version of Python and requests module are you using?

 

Even with a 400 HTTP code, the response body will contain JSON, with (hopefully) a more detailed description of the error. Try decoding the response body even when there is an error, and printing it out.

 

Re: NetMRI: Create discovery setting with REST API and python

Adviser
Posts: 357
3401     0

Ok, good.

 

I would still like to understand why you needed to change those lines. BTW, you can fork it on GitHub and create a pull request if you want. 

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You