nbshell plugin model support #3989

Closed
opened 2025-12-29 18:32:29 +01:00 by adam · 4 comments
Owner

Originally created by @minitriga on GitHub (Aug 17, 2020).

Environment

  • Python version: 3.6.9
  • NetBox version: 2.9.x

Proposed Functionality

When entering nbshell load plugin models like core models are.

Use Case

Loading plugin models would help with debugging plugin development. Changing code and exiting and entering nbshell can be a pain when having to manually import plugin models to test.

Database Changes

N/A

External Dependencies

N/A

Originally created by @minitriga on GitHub (Aug 17, 2020). ### Environment * Python version: 3.6.9 * NetBox version: 2.9.x <!-- Describe in detail the new functionality you are proposing. Include any specific changes to work flows, data models, or the user interface. --> ### Proposed Functionality When entering nbshell load plugin models like core models are. ### Use Case Loading plugin models would help with debugging plugin development. Changing code and exiting and entering nbshell can be a pain when having to manually import plugin models to test. ### Database Changes N/A ### External Dependencies N/A
adam added the type: feature label 2025-12-29 18:32:29 +01:00
adam closed this issue 2025-12-29 18:32:29 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 18, 2020):

Please provide more detail concerning the proposed enhancement. How do you propose plugin models are detected/specified? How would you modify the current approach?

@jeremystretch commented on GitHub (Aug 18, 2020): Please provide more detail concerning the proposed enhancement. How do you propose plugin models are detected/specified? How would you modify the current approach?
Author
Owner

@minitriga commented on GitHub (Aug 19, 2020):

When developing or needing to use NBShell Plugin models are not loaded forcing the user to manually import a module:

(venv) agitting@dev:~/python/netbox/netbox$ python manage.py nbshell
### NetBox interactive shell (dev)
### Python 3.6.9 | Django 3.0.9 | NetBox 2.8.9
### lsmodels() will show available models. Use help(<model>) for more info.
>>> from netbox_onboarding.models import *

Automatically including the modules would ease development and user experience when working with plugins.

I have been able to detect plugins in the same way Netbox detects a plugin view plugins = [apps.get_app_config(plugin) for plugin in settings.PLUGINS]. This allows us to be able to load the plugin and include the models.

I have implemented this on a fork.

(venv) agitting@dev:~/python/netbox/netbox$ python manage.py nbshell
### NetBox interactive shell (dev)
### Python 3.6.9 | Django 3.0.9 | NetBox 2.8.9
### lsmodels() will show available models. Use help(<model>) for more info.
>>> lsmodels()
Circuits:
  Provider
  CircuitType
  Circuit
  CircuitTermination
DCIM:
  ConsolePort
  ConsoleServerPort
  PowerPort
  PowerOutlet
  Interface
  FrontPort
  RearPort
  DeviceBay
  InventoryItem
  ConsolePortTemplate
  ConsoleServerPortTemplate
  PowerPortTemplate
  PowerOutletTemplate
  InterfaceTemplate
  FrontPortTemplate
  RearPortTemplate
  DeviceBayTemplate
  Region
  Site
  RackGroup
  RackRole
  Rack
  RackReservation
  Manufacturer
  DeviceType
  DeviceRole
  Platform
  Device
  VirtualChassis
  PowerPanel
  PowerFeed
  Cable
Extras:
  CustomField
  CustomFieldValue
  CustomFieldChoice
  Webhook
  CustomLink
  Graph
  ExportTemplate
  ImageAttachment
  ConfigContext
  Script
  ReportResult
  ObjectChange
  Tag
  TaggedItem
IPAM:
  VRF
  RIR
  Aggregate
  Role
  Prefix
  IPAddress
  VLANGroup
  VLAN
  Service
Secrets:
  UserKey
  SessionKey
  SecretRole
  Secret
Tenancy:
  TenantGroup
  Tenant
Users:
  UserConfig
  Token
Virtualization:
  ClusterType
  ClusterGroup
  Cluster
  VirtualMachine
Device Onboarding:
  OnboardingTask
PDU Status:
  PDUConfig
  PDUStatus

Check out my commit here.

@minitriga commented on GitHub (Aug 19, 2020): When developing or needing to use NBShell Plugin models are not loaded forcing the user to manually import a module: ```python (venv) agitting@dev:~/python/netbox/netbox$ python manage.py nbshell ### NetBox interactive shell (dev) ### Python 3.6.9 | Django 3.0.9 | NetBox 2.8.9 ### lsmodels() will show available models. Use help(<model>) for more info. >>> from netbox_onboarding.models import * ``` Automatically including the modules would ease development and user experience when working with plugins. I have been able to detect plugins in the same way Netbox detects a plugin view `plugins = [apps.get_app_config(plugin) for plugin in settings.PLUGINS]`. This allows us to be able to load the plugin and include the models. I have implemented this on a fork. ``` (venv) agitting@dev:~/python/netbox/netbox$ python manage.py nbshell ### NetBox interactive shell (dev) ### Python 3.6.9 | Django 3.0.9 | NetBox 2.8.9 ### lsmodels() will show available models. Use help(<model>) for more info. >>> lsmodels() Circuits: Provider CircuitType Circuit CircuitTermination DCIM: ConsolePort ConsoleServerPort PowerPort PowerOutlet Interface FrontPort RearPort DeviceBay InventoryItem ConsolePortTemplate ConsoleServerPortTemplate PowerPortTemplate PowerOutletTemplate InterfaceTemplate FrontPortTemplate RearPortTemplate DeviceBayTemplate Region Site RackGroup RackRole Rack RackReservation Manufacturer DeviceType DeviceRole Platform Device VirtualChassis PowerPanel PowerFeed Cable Extras: CustomField CustomFieldValue CustomFieldChoice Webhook CustomLink Graph ExportTemplate ImageAttachment ConfigContext Script ReportResult ObjectChange Tag TaggedItem IPAM: VRF RIR Aggregate Role Prefix IPAddress VLANGroup VLAN Service Secrets: UserKey SessionKey SecretRole Secret Tenancy: TenantGroup Tenant Users: UserConfig Token Virtualization: ClusterType ClusterGroup Cluster VirtualMachine Device Onboarding: OnboardingTask PDU Status: PDUConfig PDUStatus ``` **Check out my commit [here](https://github.com/minitriga/netbox/commit/731e3b3b8dc74b107b069af726a228bd3c9bf02b).**
Author
Owner

@jeremystretch commented on GitHub (Aug 20, 2020):

This doesn't address name collisions. We avoid them in NetBox core because every model has a unique name; this cannot be guaranteed for an unknown set of plugins. Suppose, for example, two plugins have a model named Record: only the first to be imported can be used (and that may not be the one the user expects). To avoid confusion and error, the models would need to be imported per their parent modules, at which point there's not much benefit left to automatically import them in the first place.

@jeremystretch commented on GitHub (Aug 20, 2020): This doesn't address name collisions. We avoid them in NetBox core because every model has a unique name; this cannot be guaranteed for an unknown set of plugins. Suppose, for example, two plugins have a model named `Record`: only the first to be imported can be used (and that may not be the one the user expects). To avoid confusion and error, the models would need to be imported per their parent modules, at which point there's not much benefit left to automatically import them in the first place.
Author
Owner

@jeremystretch commented on GitHub (Aug 31, 2020):

Closing this as there has been no further discussion.

@jeremystretch commented on GitHub (Aug 31, 2020): Closing this as there has been no further discussion.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3989