Feat: Closes #44 - Cisco EoX API integration#159
Conversation
DanSheps
left a comment
There was a problem hiding this comment.
Some stuff may be missing, but this should get you close enough to at least start moving forward on it.
| Returns ``None`` if no valid, enabled configuration is found. | ||
| """ | ||
| # --- 1. Try database --- | ||
| try: |
There was a problem hiding this comment.
| try: |
Should not need this, for the reason stated as this appears to not be used anywhere where the DB will be in a non-initialized state
| except Exception as exc: | ||
| # DB may not be available during migrations or tests | ||
| logger.debug('Could not load CiscoEoXSettings from database: %s', exc) |
There was a problem hiding this comment.
| except Exception as exc: | |
| # DB may not be available during migrations or tests | |
| logger.debug('Could not load CiscoEoXSettings from database: %s', exc) |
See related comment
| return '' | ||
| try: | ||
| return _get_fernet().decrypt(self._client_secret.encode()).decode() | ||
| except Exception: |
There was a problem hiding this comment.
| except Exception: | |
| except cryptography.fernet.InvalidToken: |
There was a problem hiding this comment.
You should use NetBox views where possible
| # Cisco EoX API — fallback to PLUGINS_CONFIG when no DB settings exist | ||
| 'cisco_eox_enabled': False, | ||
| 'cisco_eox_client_id': '', | ||
| 'cisco_eox_client_secret': '', | ||
| 'cisco_eox_sync_interval': 10080, # weekly, in minutes | ||
| 'cisco_eox_manufacturer_names': 'Cisco', |
There was a problem hiding this comment.
I would maybe just straight up dump these. Require a setting to be configured
| # Cisco EoX API — fallback to PLUGINS_CONFIG when no DB settings exist | |
| 'cisco_eox_enabled': False, | |
| 'cisco_eox_client_id': '', | |
| 'cisco_eox_client_secret': '', | |
| 'cisco_eox_sync_interval': 10080, # weekly, in minutes | |
| 'cisco_eox_manufacturer_names': 'Cisco', |
|
|
||
| super().ready() | ||
|
|
||
| from netbox_lifecycle.jobs import CiscoEoXSyncJob # noqa: F401 — registers job |
There was a problem hiding this comment.
Will need to loop here and queue jobs that are not queued.
| path( | ||
| 'cisco-eox/settings/', | ||
| views.CiscoEoXSettingsView.as_view(), | ||
| name='cisco_eox_settings', | ||
| ), | ||
| path( | ||
| 'cisco-eox/settings/edit/', | ||
| views.CiscoEoXSettingsEditView.as_view(), | ||
| name='cisco_eox_settings_edit', | ||
| ), | ||
| path( | ||
| 'cisco-eox/run-now/', | ||
| views.CiscoEoXRunNowView.as_view(), | ||
| name='cisco_eox_run_now', | ||
| ), |
There was a problem hiding this comment.
| path( | |
| 'cisco-eox/settings/', | |
| views.CiscoEoXSettingsView.as_view(), | |
| name='cisco_eox_settings', | |
| ), | |
| path( | |
| 'cisco-eox/settings/edit/', | |
| views.CiscoEoXSettingsEditView.as_view(), | |
| name='cisco_eox_settings_edit', | |
| ), | |
| path( | |
| 'cisco-eox/run-now/', | |
| views.CiscoEoXRunNowView.as_view(), | |
| name='cisco_eox_run_now', | |
| ), | |
| path( | |
| 'cisco-eox/', | |
| include(get_model_urls(app_name, 'eoxapisetting', detail=False)), | |
| ), | |
| path( | |
| 'cisco-eox/<int:pk>/', | |
| include(get_model_urls(app_name, 'eoxapisetting')), | |
| ), |
| link='plugins:netbox_lifecycle:cisco_eox_settings', | ||
| link_text='Cisco EoX Settings', | ||
| permissions=['netbox_lifecycle.view_ciscoeoxsettings'], | ||
| ) |
There was a problem hiding this comment.
| ) | |
| buttons=( | |
| PluginMenuButton( | |
| link='plugins:netbox_lifecycle:eoxapisetting_add', | |
| title='Add', | |
| icon_class=COL_ADD, | |
| permissions=['netbox_lifecycle.add_eoxapisetting'], | |
| ), | |
| ), | |
| ) |
There was a problem hiding this comment.
No comment yet, but will need to be modified
This pull request introduces a major new feature: integration with the Cisco EoX (End-of-Life) API to automatically synchronize hardware lifecycle information for Cisco devices and modules. It includes database schema changes, background job automation, secure credential management, new forms and navigation, and comprehensive documentation for the new functionality.
The most important changes are:
Cisco EoX API Integration
CiscoEoXSyncJob) that periodically queries the Cisco EoX API for end-of-life data based on DeviceType and ModuleType, updating or creatingHardwareLifecyclerecords accordingly. The job supports both serial number and part number lookups and reschedules itself according to the configured interval.CiscoEoXSettingsto securely store API credentials (with Fernet encryption for the client secret), sync interval, and manufacturer names. Includes migration to create this model. [1] [2] [3]CiscoEoXSettingsForm) for editing Cisco EoX settings via the Web UI, ensuring the client secret is never echoed back and is only updated when a new value is provided.Configuration and Settings
PLUGINS_CONFIG) and documentation to support Cisco EoX settings as a fallback when no database settings exist, and documents the precedence and security recommendations for credential storage. [1] [2]README.mdexplaining the Cisco EoX integration, configuration options, lookup order, and mapping of Cisco API fields to the plugin's model fields.User Interface and Navigation
These changes together provide automated, secure, and user-friendly synchronization of Cisco hardware lifecycle data, significantly enhancing the plugin's capabilities for NetBox users managing Cisco equipment.