Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch IP Address Record Update #2480

Closed
branbot3000 opened this issue Oct 2, 2018 · 5 comments
Closed

Batch IP Address Record Update #2480

branbot3000 opened this issue Oct 2, 2018 · 5 comments

Comments

@branbot3000
Copy link

Environment

  • Python version: 3.7
  • NetBox version: 2.4.5

Proposed Functionality

Enable enhanced REST functionality -
specifically, add PATCH method for HTTP interactions.
image

Use Case

This specific use case proposes that a feature be added that would allow batch updates to IP address records. For example, in this instance I would be utilizing the REST API to edit several thousand of them at once - updating their description fields to contain their hostnames.

The benefit of this feature would be increased ease of use. I work for a company with thousands of end users and this would greatly increase efficiency when recording updates to our network environment. We recently switched to your IPAM system and are missing host names as a result of human error during our initial data migration. I have been working around this through scripting but it's been a chore, and it seems like this enhancement wouldn't necessarily be something too difficult to implement on your end, but I could be wrong. Let me know what you think!

@candlerb
Copy link
Contributor

candlerb commented Oct 4, 2018

Don't forget you can do INSERTs and UPDATEs directly on the underlying postgres database. It's well-structured and there is referential integrity. Obviously you need to be careful not to do silly things which the web interface or API would prevent.

There is a risk that creeping changes can turn a RESTI API into an unholy chimera. For a perfect example of this take a look at Salesforce:

That's not even scratching the surface - "a mess" doesn't even start to describe it. So be careful what you wish for :-)

@cimnine
Copy link
Contributor

cimnine commented Oct 5, 2018

That's one more spot where GraphQL would shine. But it's most probably never going to happen. See #2007

@candlerb
Copy link
Contributor

candlerb commented Oct 5, 2018

GraphQL looks cool. I guess you would create Mutations to allow the batch updates the OP was asking for.

Then all you have to do is rewrite the UI in Javascript to talk to GraphQL, and you have re-implemented the whole application :-)

@cimnine
Copy link
Contributor

cimnine commented Oct 5, 2018

Then all you have to do is rewrite the UI in Javascript to talk to GraphQL, and you have re-implemented the whole application :-)

It would indeed be useful for this: One request to fetch all information required to render the content.

(This gets OT.)

@jeremystretch
Copy link
Member

NetBox employs the Django REST Framework (a third-party extension to the Django framework) for its API. I don't believe this functionality is currently supported by DRF. There was some work done on an external package called django-rest-framework-bulk but it is no longer maintained and almost certainly incompatible with recent releases. We can revisit this if support is introduced in DRF, but it's probably not something we want to tackle directly.

Regarding your specific use case, it is inadvisable to record hostnames in the description field of IP addresses: The device name is already accessible at ipaddress.interface.device. But if you really want to, you can easily perform one-off bulk updates using the local Python console (./manage.py nbshell). Something like this should work:

for ip in IPAddress.objects.select_related('interface__device').filter(address__net_host_contained='10.0.0.0/8'):
    if ip.interface and ip.interface.device:
        ip.description = ip.interface.device.name[:100]
        ip.save()

@lock lock bot locked as resolved and limited conversation to collaborators Jan 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants