diff --git a/netbox/dcim/api/views.py b/netbox/dcim/api/views.py index ce8b4c349..e1bce1abb 100644 --- a/netbox/dcim/api/views.py +++ b/netbox/dcim/api/views.py @@ -293,12 +293,24 @@ class DeviceViewSet(CustomFieldModelViewSet): # 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 593bef113..6cc99579b 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -723,7 +723,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 000000000..4a5234156 --- /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 14c9ef393..a4a22a8ba 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,