Skip to content

Commit

Permalink
Merge pull request #3 from NetTech2001/4.0.2-development
Browse files Browse the repository at this point in the history
4.0.3 Update
  • Loading branch information
NetTech2001 authored May 24, 2024
2 parents fd3b848 + f4632b2 commit 05d438c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# netbox-interface-synchronization
## Overview
This plugin allows you to compare and synchronize interfaces between devices and device types in NetBox. It can be useful for finding and correcting inconsistencies between interfaces.
This plugin allows you to compare and synchronize interface names and types between devices and device types in NetBox. It can be useful for finding and correcting inconsistencies between interfaces when changing the device type.
## Compatibility
Tested with NetBox versions 4.0.0, 4.0.1, 4.0.2. This plugin is not compatible with Netbox 2 or 3
Tested with NetBox versions 4.0.0 - 4.0.3. This plugin is not compatible with Netbox 2 or 3
## Installation
If your NetBox 4 installation uses virtualenv, activate it like this:
```
Expand All @@ -27,7 +27,7 @@ Don't forget to restart NetBox:
sudo systemctl restart netbox
```
## Usage
To sync the interfaces, edit the device and set the new device type and save the device. Then find the "Sync Interfaces" button:
To sync the interfaces, edit the device and set the new device type and save the device. Then find the "Sync Interfaces" button at the bottom of the page:
![Device page](docs/images/1_device_page.png)
Mark the required actions with the checkboxes and click "Apply".
![Interface comparison](docs/images/2_interface_comparison.png)
Expand Down
4 changes: 2 additions & 2 deletions netbox_interface_synchronization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
class Config(PluginConfig):
name = 'netbox_interface_synchronization'
verbose_name = 'NetBox Interface Synchronization'
description = 'Syncing existing interfaces with the interfaces from a new device type in NetBox'
version = '4.0.1'
description = 'Syncing existing interface names and types with those from a new device type in NetBox'
version = '4.0.3'
author = 'Keith Knowles'
author_email = '[email protected]'
default_settings = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

<p>
{% if templates_count == interfaces_count %}
The Device Type and Device have the same Interfaces.
The Device Type and Device have the same number of Interfaces.
{% else %}
The Device Type and Device have different Interfaces.<br>
The Device Type and Device have a different number of Interfaces.<br>
Device Type: {{ templates_count }}<br>
Device: {{ interfaces_count }}
{% endif %}
Expand Down Expand Up @@ -154,7 +154,7 @@
{% endfor %}
</table>
<div class="text-right">
<input type="submit" value="Apply" class="btn btn-primary">
<input type="submit" value="Apply Changes" class="btn btn-green">
</div>
</form>

Expand Down
1 change: 1 addition & 0 deletions netbox_interface_synchronization/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class UnifiedInterface:
name: str
type: str
type_display: str
mgmt_only: bool = False
is_template: bool = False

def __eq__(self, other):
Expand Down
8 changes: 4 additions & 4 deletions netbox_interface_synchronization/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get(self, request, device_id):

unified_interfaces = [UnifiedInterface(i.id, i.name, i.type, i.get_type_display()) for i in interfaces]
unified_interface_templates = [
UnifiedInterface(i.id, i.name, i.type, i.get_type_display(), is_template=True) for i in interface_templates]
UnifiedInterface(i.id, i.name, i.type, i.get_type_display(), i.mgmt_only, is_template=True) for i in interface_templates]

# List of interfaces and interface templates presented in the unified format
overall_interfaces = list(set(unified_interface_templates + unified_interfaces))
Expand Down Expand Up @@ -79,19 +79,19 @@ def post(self, request, device_id):
# Add selected interfaces to the device and count them
add_to_device_interfaces = InterfaceTemplate.objects.filter(id__in=add_to_device)
interfaces_created = len(Interface.objects.bulk_create([
Interface(device=device, name=i.name, type=i.type) for i in add_to_device_interfaces
Interface(device=device, name=i.name, type=i.type, mgmt_only=i.mgmt_only) for i in add_to_device_interfaces
]))

# Getting and validating a list of interfaces to rename
fix_name_interfaces = filter(lambda i: str(i.id) in request.POST.getlist("fix_name"), interfaces)
# Casting interface templates into UnifiedInterface objects for proper comparison with interfaces for renaming
unified_interface_templates = [
UnifiedInterface(i.id, i.name, i.type, i.get_type_display()) for i in interface_templates]
UnifiedInterface(i.id, i.name, i.type,i.mgmt_only, i.get_type_display()) for i in interface_templates]

# Rename selected interfaces
interfaces_fixed = 0
for interface in fix_name_interfaces:
unified_interface = UnifiedInterface(interface.id, interface.name, interface.type, interface.get_type_display())
unified_interface = UnifiedInterface(interface.id, interface.name, interface.type, interface.mgmt_only, interface.get_type_display())
try:
# Try to extract an interface template with the corresponding name
corresponding_template = unified_interface_templates[unified_interface_templates.index(unified_interface)]
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

setup(
name='netbox-interface-synchronization',
version='4.0.1',
description='Syncing existing interfaces with the interfaces from a new device type in NetBox',
version='4.0.3',
description='Syncing existing interfaces with the interfaces from a device type template in NetBox 4+',
long_description=long_description,
long_description_content_type='text/markdown',
author='Keith Knowles',
Expand Down

0 comments on commit 05d438c

Please sign in to comment.