1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Initial work on config contexts

This commit is contained in:
Jeremy Stretch
2018-06-27 16:02:34 -04:00
parent ffcbc54522
commit c13e4858d7
26 changed files with 565 additions and 16 deletions

View File

@@ -3,7 +3,6 @@ from __future__ import unicode_literals
from collections import OrderedDict
from django.conf import settings
from django.db import transaction
from django.http import HttpResponseBadRequest, HttpResponseForbidden
from django.shortcuts import get_object_or_404
from drf_yasg import openapi
@@ -233,6 +232,11 @@ class DeviceViewSet(CustomFieldModelViewSet):
serializer_class = serializers.DeviceSerializer
filter_class = filters.DeviceFilter
@detail_route(url_path='config-context')
def config_context(self, request, pk):
device = get_object_or_404(Device, pk=pk)
return Response(device.get_config_context())
@detail_route(url_path='napalm')
def napalm(self, request, pk):
"""

View File

@@ -19,7 +19,7 @@ from timezone_field import TimeZoneField
from circuits.models import Circuit
from extras.constants import OBJECTCHANGE_ACTION_DELETE, OBJECTCHANGE_ACTION_UPDATE
from extras.models import CustomFieldModel, ObjectChange
from extras.models import ConfigContextModel, CustomFieldModel, ObjectChange
from extras.rpc import RPC_CLIENTS
from utilities.fields import ColorField, NullableCharField
from utilities.managers import NaturalOrderByManager
@@ -1158,7 +1158,7 @@ class DeviceManager(NaturalOrderByManager):
@python_2_unicode_compatible
class Device(ChangeLoggedModel, CustomFieldModel):
class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
"""
A Device represents a piece of physical hardware mounted within a Rack. Each Device is assigned a DeviceType,
DeviceRole, and (optionally) a Platform. Device names are not required, however if one is set it must be unique.

View File

@@ -141,6 +141,7 @@ urlpatterns = [
url(r'^devices/(?P<pk>\d+)/$', views.DeviceView.as_view(), name='device'),
url(r'^devices/(?P<pk>\d+)/edit/$', views.DeviceEditView.as_view(), name='device_edit'),
url(r'^devices/(?P<pk>\d+)/delete/$', views.DeviceDeleteView.as_view(), name='device_delete'),
url(r'^devices/(?P<pk>\d+)/config-context/$', views.DeviceConfigContextView.as_view(), name='device_configcontext'),
url(r'^devices/(?P<pk>\d+)/changelog/$', ObjectChangeLogView.as_view(), name='device_changelog', kwargs={'model': Device}),
url(r'^devices/(?P<pk>\d+)/inventory/$', views.DeviceInventoryView.as_view(), name='device_inventory'),
url(r'^devices/(?P<pk>\d+)/status/$', views.DeviceStatusView.as_view(), name='device_status'),

View File

@@ -994,6 +994,18 @@ class DeviceConfigView(PermissionRequiredMixin, View):
})
class DeviceConfigContextView(View):
def get(self, request, pk):
device = get_object_or_404(Device, pk=pk)
return render(request, 'dcim/device_configcontext.html', {
'device': device,
'active_tab': 'config-context',
})
class DeviceCreateView(PermissionRequiredMixin, ObjectEditView):
permission_required = 'dcim.add_device'
model = Device