Skip to content

Commit

Permalink
Update for 4.1 (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSheps authored Sep 5, 2024
2 parents 38d6b09 + 1186ae4 commit 1ccbf8f
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 144 deletions.
4 changes: 2 additions & 2 deletions netbox_lifecycle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class NetBoxLifeCycle(PluginConfig):
author = metadata.get('Author')
author_email = metadata.get('Author-email')
base_url = 'lifecycle'
min_version = '3.5.0'
max_version = '4.0.99'
min_version = '4.1.0'
max_version = '4.1.99'
required_settings = []
default_settings = {}
queues = []
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
from rest_framework import serializers

from dcim.api.nested_serializers import NestedManufacturerSerializer, NestedDeviceSerializer
from dcim.api.serializers_.devices import DeviceSerializer
from dcim.api.serializers_.manufacturers import ManufacturerSerializer
from netbox.api.serializers import NetBoxModelSerializer
from netbox_lifecycle.api.nested_serializers import NestedVendorSerializer, NestedSupportContractSerializer, \
NestedLicenseAssignmentSerializer
from netbox_lifecycle.api._serializers.license import LicenseAssignmentSerializer
from netbox_lifecycle.api._serializers.vendor import VendorSerializer
from netbox_lifecycle.models import Vendor, SupportContract, SupportContractAssignment, SupportSKU

__all__ = (
'VendorSerializer',
'SupportSKUSerializer',
'SupportContractSerializer',
'SupportContractAssignmentSerializer',
)

from utilities.api import get_serializer_for_model


class VendorSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_lifecycle-api:hardwarelifecycle-detail')

class Meta:
model = Vendor
fields = ('url', 'id', 'display', 'name')


class SupportSKUSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_lifecycle-api:hardwarelifecycle-detail')
manufacturer = NestedManufacturerSerializer()
manufacturer = ManufacturerSerializer(nested=True)

class Meta:
model = SupportSKU
Expand All @@ -35,7 +25,7 @@ class Meta:

class SupportContractSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_lifecycle-api:hardwarelifecycle-detail')
vendor = NestedVendorSerializer()
vendor = VendorSerializer(nested=True)
start = serializers.DateField()
renewal = serializers.DateField()
end = serializers.DateField()
Expand All @@ -47,10 +37,10 @@ class Meta:

class SupportContractAssignmentSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_lifecycle-api:licenseassignment-detail')
contract = NestedSupportContractSerializer()
contract = SupportContractSerializer(nested=True)

device = NestedDeviceSerializer()
license = NestedLicenseAssignmentSerializer()
device = DeviceSerializer(nested=True)
license = LicenseAssignmentSerializer(nested=True)

class Meta:
model = SupportContractAssignment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from netbox.api.fields import ContentTypeField
from netbox.api.serializers import NetBoxModelSerializer
from netbox.constants import NESTED_SERIALIZER_PREFIX
from netbox_lifecycle.models import HardwareLifecycle
from utilities.api import get_serializer_for_model

Expand Down Expand Up @@ -36,6 +35,6 @@ class Meta:

@extend_schema_field(serializers.JSONField(allow_null=True))
def get_assigned_object(self, instance):
serializer = get_serializer_for_model(instance.assigned_object, prefix=NESTED_SERIALIZER_PREFIX)
serializer = get_serializer_for_model(instance.assigned_object)
context = {'request': self.context['request']}
return serializer(instance.assigned_object, context=context).data
return serializer(instance.assigned_object, context=context, nested=True).data
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from rest_framework import serializers

from dcim.api.nested_serializers import NestedManufacturerSerializer, NestedDeviceSerializer
from dcim.api.serializers_.devices import DeviceSerializer
from dcim.api.serializers_.manufacturers import ManufacturerSerializer
from netbox.api.serializers import NetBoxModelSerializer
from netbox_lifecycle.api.nested_serializers import NestedVendorSerializer
from netbox_lifecycle.api.nested_serializers.license import NestedLicenseSerializer
from netbox_lifecycle.api._serializers.vendor import VendorSerializer
from netbox_lifecycle.models import License, LicenseAssignment

__all__ = (
Expand All @@ -14,7 +14,7 @@

class LicenseSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_lifecycle-api:license-detail')
manufacturer = NestedManufacturerSerializer()
manufacturer = ManufacturerSerializer(nested=True)

class Meta:
model = License
Expand All @@ -23,9 +23,9 @@ class Meta:

class LicenseAssignmentSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_lifecycle-api:licenseassignment-detail')
license = NestedLicenseSerializer()
vendor = NestedVendorSerializer()
device = NestedDeviceSerializer()
license = LicenseSerializer(nested=True)
vendor = VendorSerializer(nested=True)
device = DeviceSerializer(nested=True)

class Meta:
model = LicenseAssignment
Expand Down
16 changes: 16 additions & 0 deletions netbox_lifecycle/api/_serializers/vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from rest_framework import serializers

from netbox.api.serializers import NetBoxModelSerializer
from netbox_lifecycle.models import Vendor

__all__ = (
'VendorSerializer',
)


class VendorSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_lifecycle-api:hardwarelifecycle-detail')

class Meta:
model = Vendor
fields = ('url', 'id', 'display', 'name')
3 changes: 0 additions & 3 deletions netbox_lifecycle/api/nested_serializers/__init__.py

This file was deleted.

47 changes: 0 additions & 47 deletions netbox_lifecycle/api/nested_serializers/contract.py

This file was deleted.

26 changes: 0 additions & 26 deletions netbox_lifecycle/api/nested_serializers/hardware.py

This file was deleted.

31 changes: 0 additions & 31 deletions netbox_lifecycle/api/nested_serializers/license.py

This file was deleted.

14 changes: 14 additions & 0 deletions netbox_lifecycle/api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from _serializers.contract import *
from _serializers.hardware import *
from _serializers.license import *
from _serializers.vendor import *

__all__ = (
'VendorSerializer',
'SupportSKUSerializer',
'SupportContractSerializer',
'SupportContractAssignmentSerializer',
'HardwareLifecycleSerializer',
'LicenseSerializer',
'LicenseAssignmentSerializer',
)
5 changes: 0 additions & 5 deletions netbox_lifecycle/api/serializers/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='netbox-lifecycle',
version='1.0.4',
version='1.1.0',
description='NetBox Lifecycle',
long_description='NetBox Support Contract and EOL/EOS management',
url='https://github.com/dansheps/netbox-lifecycle/',
Expand Down

0 comments on commit 1ccbf8f

Please sign in to comment.