From 7e8bad4a5af45417fa2e8edd15acaef931d1d17a Mon Sep 17 00:00:00 2001 From: Christian d'Autume Date: Mon, 16 Apr 2018 17:29:16 +0200 Subject: [PATCH] #2029 add port and transport napalm fields in platform model --- netbox/dcim/api/views.py | 14 ++++++++++- netbox/dcim/forms.py | 2 +- .../migrations/0056_auto_20180416_1309.py | 25 +++++++++++++++++++ netbox/dcim/models.py | 15 +++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 netbox/dcim/migrations/0056_auto_20180416_1309.py diff --git a/netbox/dcim/api/views.py b/netbox/dcim/api/views.py index 13f68639fb..aad3ae2b0d 100644 --- a/netbox/dcim/api/views.py +++ b/netbox/dcim/api/views.py @@ -293,12 +293,24 @@ def napalm(self, request, pk): # TODO: Improve error handling response = OrderedDict([(m, None) for m in napalm_methods]) ip_address = str(device.primary_ip.address.ip) + + # Merge NAPALM_ARGS settings and form data + optional_args = {} + if settings.NAPALM_ARGS: + optional_args.update(settings.NAPALM_ARGS) + + if device.platform.napalm_port: + optional_args.update({'port': device.platform.napalm_port}) + + if device.platform.napalm_transport: + optional_args.update({'transport': device.platform.napalm_transport}) + d = driver( hostname=ip_address, username=settings.NAPALM_USERNAME, password=settings.NAPALM_PASSWORD, timeout=settings.NAPALM_TIMEOUT, - optional_args=settings.NAPALM_ARGS + optional_args=optional_args ) try: d.open() diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index 05dc0ea6f8..4010637318 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -699,7 +699,7 @@ class PlatformForm(BootstrapMixin, forms.ModelForm): class Meta: model = Platform - fields = ['name', 'slug', 'manufacturer', 'napalm_driver', 'rpc_client'] + fields = ['name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_port', 'napalm_transport', 'rpc_client'] class PlatformCSVForm(forms.ModelForm): diff --git a/netbox/dcim/migrations/0056_auto_20180416_1309.py b/netbox/dcim/migrations/0056_auto_20180416_1309.py new file mode 100644 index 0000000000..4a5234156f --- /dev/null +++ b/netbox/dcim/migrations/0056_auto_20180416_1309.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.12 on 2018-04-16 13:09 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dcim', '0055_virtualchassis_ordering'), + ] + + operations = [ + migrations.AddField( + model_name='platform', + name='napalm_port', + field=models.PositiveIntegerField(blank=True, help_text='The port to be used by NAPALM driver when interacting with devices', null=True, verbose_name='NAPALM port'), + ), + migrations.AddField( + model_name='platform', + name='napalm_transport', + field=models.CharField(blank=True, help_text='The transport protocol to be used by NAPALM driver when interacting with devices', max_length=50, verbose_name='NAPALM transport type'), + ), + ] diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index ac1affdefe..406ba2b896 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -815,6 +815,21 @@ class Platform(models.Model): verbose_name='NAPALM driver', help_text="The name of the NAPALM driver to use when interacting with devices" ) + + napalm_port = models.PositiveIntegerField( + blank=True, + null=True, + verbose_name='NAPALM port', + help_text="The port to be used by NAPALM driver when interacting with devices" + ) + + napalm_transport = models.CharField( + max_length=50, + blank=True, + verbose_name='NAPALM transport type', + help_text="The transport protocol to be used by NAPALM driver when interacting with devices" + ) + rpc_client = models.CharField( max_length=30, choices=RPC_CLIENT_CHOICES,