Closed nkallergis closed 4 months ago
Extending Nautobot's CSV import capabilities to all models, not just the supported core models.
Can you elaborate on what's missing from core in this regard?
Extending Nautobot's CSV import capabilities to all models, not just the supported core models.
Can you elaborate on what's missing from core in this regard?
@glennmatthews apparently what's actually missing is some better understanding on my side as I was under the impression that Nautobot didn't support CSV imports for non-core models. Just realized that this is not true at all 😕
Nevertheless, due to this being based on Design Builder, there are a couple of other advantages such as:
{"!get:name": "ABC123"}
Very open to discussing this PR further if you feel it duplicates core team efforts and should be handled differently!
We definitely want to add the ability to do updates via CSV in core, it just hasn't bubbled up to the top of the to-do list yet. Same for being able to clearly/conveniently describe M2Ms on the related model CSV (for now at least, our guidance at this point is use a separate CSV file to populate the through table). I haven't looked at your code here but if there's any chance it'd make sense to port any of it into core we'd definitely be interested in taking a look. :-)
This PR is tricky because it solves a different problem than what Design Builder is for (i.e., using design to create/update data). In this case, you are providing the data in a specific format to transform data into the source of truth, using the interfaces that Design Builder offers (smart one, BTW).
Being a lonely job, it may be hosted in this project (or an extension of it), but I think that the problem that you are trying to solve should be solved in Core eventually. Actually, there is a similar case with the data protection features I developed in this project, that I hope can be offloaded to Core at some point.
I'm a bit concerned about confusing the users of design builder with this new Job. Maybe we could leave it as a side App (depending on this) with this job, while we sync with Core to make it a killing new feature?
@chadell agreed on all points made. For the moment I'll leave it as is and we can sync on possible paths to porting this into core. As for your question @glennmatthews, the parts that can be salvaged are mostly around "reading" the Excel sheets but, depending on how we'll approach updates and M2Ms, could easily prove to be the weakest parts too.
Closing the PR based on the discussion above. Tomorrow I will "move" it to https://github.com/nautobot/demo-designs as per the recommendation from @abates.
Add a Nautobot Job that enables users to import data from an Excel file using Design Builder as the backend mechanism (
Environment.implement_design
). The advantages of this approach include:Job description
The Job itself is pretty self-explanatory and just has the following two fields:
How to use the Excel file
Index sheet
The Index sheet is what "drives" the whole thing.
Index contains the following columns:
sheet_name
which is the name of the Excel sheet to import data from.model
which is the model that we're creating a design for (e.g.devices:
).keys
which is a list of columns that will be prepended with!create_or_update:
.json_fields
which is a list of columns that contain JSON-like content which should be JSON-loaded in the code.Data sheets
Sheets containing data should be split per-model i.e. one sheet for Devices, one for Interfaces and so on. The column naming rules follow the same convention as Design Builder and Nautobot's CSV import functionality.
name
).status__name
).content_type
orcontent_types
are handled in the Job code so that the generated design has the correct syntax.Special cases
Currently there are a couple of "special cases" handled explicitly in the code. These are mostly around M2M relationships and under investigation on how these could be handled in a more generalizable manner.
_handle_primary_ip_addresses
doing the necessary transformations._handle_cables
does the dirty work of transforming the structure to a Design Builder friendly format that leverages theLookupExtension
for creating the cables. Note that this is one of the most problematic pieces of the code as it is not idempotent.Todo
content_type(s)
(unique entry or list).pretty_json
function toutils
orhelpers
.A sample Excel file is also included in the PR and may be found in examples_v2/excel_files/coolkitt_data_import.xlsx.
The PR comes with the following extra dependencies for reading and processing Excel files:
openpyxl
for reading the Excel file.pandas
for processing it.numpy
as a Pandas dependency.