mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #2029: Added optional NAPALM arguments to Platform model
This commit is contained in:
@ -346,7 +346,7 @@ class PlatformSerializer(ValidatedModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Platform
|
model = Platform
|
||||||
fields = ['id', 'name', 'slug', 'manufacturer', 'napalm_driver', 'rpc_client']
|
fields = ['id', 'name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_args', 'rpc_client']
|
||||||
|
|
||||||
|
|
||||||
class NestedPlatformSerializer(WritableNestedSerializer):
|
class NestedPlatformSerializer(WritableNestedSerializer):
|
||||||
|
@ -283,12 +283,15 @@ class DeviceViewSet(CustomFieldModelViewSet):
|
|||||||
# TODO: Improve error handling
|
# TODO: Improve error handling
|
||||||
response = OrderedDict([(m, None) for m in napalm_methods])
|
response = OrderedDict([(m, None) for m in napalm_methods])
|
||||||
ip_address = str(device.primary_ip.address.ip)
|
ip_address = str(device.primary_ip.address.ip)
|
||||||
|
optional_args = settings.NAPALM_ARGS.copy()
|
||||||
|
if device.platform.napalm_args is not None:
|
||||||
|
optional_args.update(device.platform.napalm_args)
|
||||||
d = driver(
|
d = driver(
|
||||||
hostname=ip_address,
|
hostname=ip_address,
|
||||||
username=settings.NAPALM_USERNAME,
|
username=settings.NAPALM_USERNAME,
|
||||||
password=settings.NAPALM_PASSWORD,
|
password=settings.NAPALM_PASSWORD,
|
||||||
timeout=settings.NAPALM_TIMEOUT,
|
timeout=settings.NAPALM_TIMEOUT,
|
||||||
optional_args=settings.NAPALM_ARGS
|
optional_args=optional_args
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
d.open()
|
d.open()
|
||||||
|
@ -746,7 +746,10 @@ class PlatformForm(BootstrapMixin, forms.ModelForm):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Platform
|
model = Platform
|
||||||
fields = ['name', 'slug', 'manufacturer', 'napalm_driver', 'rpc_client']
|
fields = ['name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_args', 'rpc_client']
|
||||||
|
widgets = {
|
||||||
|
'napalm_args': SmallTextarea(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class PlatformCSVForm(forms.ModelForm):
|
class PlatformCSVForm(forms.ModelForm):
|
||||||
|
19
netbox/dcim/migrations/0061_platform_napalm_args.py
Normal file
19
netbox/dcim/migrations/0061_platform_napalm_args.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 2.0.6 on 2018-06-29 15:02
|
||||||
|
|
||||||
|
import django.contrib.postgres.fields.jsonb
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('dcim', '0060_change_logging'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='platform',
|
||||||
|
name='napalm_args',
|
||||||
|
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, help_text='Additional arguments to pass when initiating the NAPALM driver (JSON format)', null=True, verbose_name='NAPALM arguments'),
|
||||||
|
),
|
||||||
|
]
|
@ -6,7 +6,7 @@ from itertools import count, groupby
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.contenttypes.fields import GenericRelation
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
from django.contrib.postgres.fields import ArrayField
|
from django.contrib.postgres.fields import ArrayField, JSONField
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
@ -1125,6 +1125,12 @@ class Platform(ChangeLoggedModel):
|
|||||||
verbose_name='NAPALM driver',
|
verbose_name='NAPALM driver',
|
||||||
help_text='The name of the NAPALM driver to use when interacting with devices'
|
help_text='The name of the NAPALM driver to use when interacting with devices'
|
||||||
)
|
)
|
||||||
|
napalm_args = JSONField(
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
verbose_name='NAPALM arguments',
|
||||||
|
help_text='Additional arguments to pass when initiating the NAPALM driver (JSON format)'
|
||||||
|
)
|
||||||
rpc_client = models.CharField(
|
rpc_client = models.CharField(
|
||||||
max_length=30,
|
max_length=30,
|
||||||
choices=RPC_CLIENT_CHOICES,
|
choices=RPC_CLIENT_CHOICES,
|
||||||
@ -1133,7 +1139,7 @@ class Platform(ChangeLoggedModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
serializer = 'dcim.api.serializers.PlatformSerializer'
|
serializer = 'dcim.api.serializers.PlatformSerializer'
|
||||||
csv_headers = ['name', 'slug', 'manufacturer', 'napalm_driver']
|
csv_headers = ['name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_args']
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['name']
|
ordering = ['name']
|
||||||
@ -1150,6 +1156,7 @@ class Platform(ChangeLoggedModel):
|
|||||||
self.slug,
|
self.slug,
|
||||||
self.manufacturer.name if self.manufacturer else None,
|
self.manufacturer.name if self.manufacturer else None,
|
||||||
self.napalm_driver,
|
self.napalm_driver,
|
||||||
|
self.napalm_args,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user