1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Expanded inventory function to support submodules

This commit is contained in:
Jeremy Stretch
2016-03-28 17:56:00 -04:00
parent 690ad29ab8
commit 07952babe8
4 changed files with 39 additions and 24 deletions

View File

@@ -24,6 +24,13 @@ class Command(BaseCommand):
def handle(self, *args, **options):
def create_modules(modules, parent=None):
for module in modules:
m = Module(device=device, parent=parent, name=module['name'], part_id=module['part_id'],
serial=module['serial'])
m.save()
create_modules(module.get('modules', []), parent=m)
# Credentials
if options['username']:
self.username = options['username']
@@ -106,12 +113,6 @@ class Command(BaseCommand):
device.serial = inventory['chassis']['serial']
device.save()
Module.objects.filter(device=device).delete()
modules = []
for module in inventory['modules']:
modules.append(Module(device=device,
name=module['name'],
part_id=module['part_id'],
serial=module['serial']))
Module.objects.bulk_create(modules)
create_modules(inventory.get('modules', []))
self.stdout.write("Finished!")