nautobot / nautobot-app-design-builder

https://docs.nautobot.com/projects/design-builder/en/latest/
Other
8 stars 2 forks source link

feat: Add Job "Data population from Excel file" #138

Closed nkallergis closed 4 months ago

nkallergis commented 4 months ago

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.

sheet_name model keys json_fields
VRFs vrfs name,namespace__name
Manufacturers manufacturers name
Device Types device_types model,manufacturer__name
Location Types location_types name
Locations locations name,location_type__name
Devices devices name,location__name local_config_context_data
Interfaces interfaces name,devicename,devicelocation__name
IP Addresses ip_addresses address,parentnamespacename
Primary IP Addresses devices name
Cables cables
Dynamic Groups dynamic_groups name filter
Dynamic Group Memberships dynamic_group_memberships group__name,parent_group__name

Index contains the following columns:

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 location_type__name description status__name
dublin-dc Datacenter Dublin datacenter Active
dublin-pop POP Dublin Point of Presence Active
orlando-dc Datacenter Orlando datacenter Active
orlando-pop POP Orlando Point of Presence Active
bangkok-dc Datacenter Bangkok datacenter Active
bangkok-pop POP Bangkok Point of Presence Active

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.

Todo

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:

glennmatthews commented 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?

nkallergis commented 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?

@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:

Very open to discussing this PR further if you feel it duplicates core team efforts and should be handled differently!

glennmatthews commented 4 months ago

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. :-)

chadell commented 4 months ago

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?

nkallergis commented 4 months ago

@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.

nkallergis commented 4 months ago

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.