Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2029 add port and transport napalm fields in platform model #2031

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion netbox/dcim/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion netbox/dcim/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
25 changes: 25 additions & 0 deletions netbox/dcim/migrations/0056_auto_20180416_1309.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
15 changes: 15 additions & 0 deletions netbox/dcim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down