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

KeyError: 'slug' if you specify an argument in '--slugs' #117

Open
ShadowSZ72 opened this issue Oct 17, 2023 · 2 comments · May be fixed by #130
Open

KeyError: 'slug' if you specify an argument in '--slugs' #117

ShadowSZ72 opened this issue Oct 17, 2023 · 2 comments · May be fixed by #130

Comments

@ShadowSZ72
Copy link

If you run the script with the argument model-type
./nb-dt-import.py --slugs cisco-ws-c2960-24tc-l

Then I will get an error:

Traceback (most recent call last):
  File "/home/username/reps/Device-Type-Library-Import/./nb-dt-import.py", line 54, in <module>
    main()
  File "/home/username/reps/Device-Type-Library-Import/./nb-dt-import.py", line 32, in main
    module_types = sdr.parse_files(files, slugs=args.slugs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/username/reps/Device-Type-Library-Import/repo.py", line 101, in parse_files
    if slugs and True not in [True if s.casefold() in data['slug'].casefold() else False for s in slugs]:
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/username/reps/Device-Type-Library-Import/repo.py", line 101, in <listcomp>
    if slugs and True not in [True if s.casefold() in data['slug'].casefold() else False for s in slugs]:
                                                      ~~~~^^^^^^^^
KeyError: 'slug'

I think it's because of "module-types".
The files in it do not have the "slug" attribute.

@Torstein-Eide
Copy link

A temporary fix is:

diff --git a/nb-dt-import.py b/nb-dt-import.py
index 8255528..5b32d4a 100755
--- a/nb-dt-import.py
+++ b/nb-dt-import.py
@@ -29,7 +29,7 @@ def main():
         files, vendors = settings.dtl_repo.get_devices(
             f'{settings.dtl_repo.repo_path}/module-types/', args.vendors)
         settings.handle.log(f'{len(vendors)} Module Vendors Found')
-        module_types = settings.dtl_repo.parse_files(files, slugs=args.slugs)
+        module_types = settings.dtl_repo.parse_files(files, slugs='')
         settings.handle.log(f'{len(module_types)} Module-Types Found')
         netbox.create_manufacturers(vendors)
         netbox.create_module_types(module_types)`

@zeridon
Copy link

zeridon commented Mar 5, 2024

The interesting thing is that if you give only vendor modules are imported without complaints. The issue ocurs only on slugs.

jgroom33 added a commit to jgroom33/Device-Type-Library-Import that referenced this issue Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants