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

Ability to specify related objects by attribute during CSV import #3147

Closed
jeremystretch opened this issue May 3, 2019 · 3 comments · Fixed by #4564
Closed

Ability to specify related objects by attribute during CSV import #3147

jeremystretch opened this issue May 3, 2019 · 3 comments · Fixed by #4564
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application

Comments

@jeremystretch
Copy link
Member

Environment

  • Python version: 3.5.2
  • NetBox version: 2.5.12

Proposed Functionality

Currently, specifying a related object when importing a new object as CSV data requires the related object to have a unique name. For example, importing an IP address assigned to an interface might look like this:

address,status,device,interface
192.0.2.1/24,Active,router3,et-0/0/1

The combination of device name and interface name forms a unique identifier for the interface to which the new IP address should be assigned.

This proposal would allow a related object to be specified by an arbitrary set of fields. For example:

address,status,device,interface
192.0.2.1/24,Active,{site.name: "Raleigh", name: "router3"},et-0/0/1

This would allow the user to have multiple devices named "router3" yet specify the one belonging to site "Raleigh."

The specific formatting is up for debate; the above is intended solely as an illustration of the concept. Special consideration must be given to the use of commas, since parsing of the related object field is being done within the context of processing CSV data.

As I write this, I have to admit it feels like we're trying to squeeze too much functionality out of the CSV format: Maybe a JSON-centric approach would be preferable, but we'd need a low-friction solution for converting spreadsheet data into JSON.

Use Case

This FR was prompted by #2669, which would relax the uniqueness constraint on device and virtual machine names. If a device name cannot be assumed unique, a more robust approach to referencing devices must be implemented. We've already taken a step toward this approach with FlexibleModelChoiceField, which allows referencing an unnamed object by numeric ID (e.g. {{123}}).

Database Changes

None

External Dependencies

Probably none. We may end up using some external parsing library, depending on the approach chosen.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application labels May 3, 2019
@jeremystretch jeremystretch added status: under review Further discussion is needed to determine this issue's scope and/or implementation and removed status: accepted This issue has been accepted for implementation labels May 3, 2019
@tb-killa
Copy link
Contributor

tb-killa commented May 6, 2019

Doesn´t we could use this as Base for the #822 and #451 ??

@jeremystretch
Copy link
Member Author

@tb-killa #822, yes. #451 is unrelated to CSV import.

@jeremystretch
Copy link
Member Author

I think it makes sense to do something like this:

address,status,device.site,device.name,interface
192.0.2.1/24,Active,Site D,router3,et-0/0/1

I'm just not sure how we'd get there. It likely means throwing out the existing CSV import forms and starting largely from scratch.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Dec 13, 2019
@jeremystretch jeremystretch self-assigned this May 1, 2020
jeremystretch added a commit that referenced this issue May 6, 2020
Closes #3147: Allow dynamic access to related objects during CSV import
jeremystretch added a commit that referenced this issue May 6, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants