diff --git a/netbox_lifecycle/__init__.py b/netbox_lifecycle/__init__.py index 263a5a5..8d8b29d 100644 --- a/netbox_lifecycle/__init__.py +++ b/netbox_lifecycle/__init__.py @@ -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 = [] diff --git a/netbox_lifecycle/api/_serializers/__init__.py b/netbox_lifecycle/api/_serializers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/netbox_lifecycle/api/serializers/contract.py b/netbox_lifecycle/api/_serializers/contract.py similarity index 63% rename from netbox_lifecycle/api/serializers/contract.py rename to netbox_lifecycle/api/_serializers/contract.py index fe25ebd..2356b2f 100644 --- a/netbox_lifecycle/api/serializers/contract.py +++ b/netbox_lifecycle/api/_serializers/contract.py @@ -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 @@ -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() @@ -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 diff --git a/netbox_lifecycle/api/serializers/hardware.py b/netbox_lifecycle/api/_serializers/hardware.py similarity index 93% rename from netbox_lifecycle/api/serializers/hardware.py rename to netbox_lifecycle/api/_serializers/hardware.py index 95cb04c..98345ae 100644 --- a/netbox_lifecycle/api/serializers/hardware.py +++ b/netbox_lifecycle/api/_serializers/hardware.py @@ -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 @@ -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 diff --git a/netbox_lifecycle/api/serializers/license.py b/netbox_lifecycle/api/_serializers/license.py similarity index 65% rename from netbox_lifecycle/api/serializers/license.py rename to netbox_lifecycle/api/_serializers/license.py index 9484fe8..cd668bd 100644 --- a/netbox_lifecycle/api/serializers/license.py +++ b/netbox_lifecycle/api/_serializers/license.py @@ -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__ = ( @@ -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 @@ -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 diff --git a/netbox_lifecycle/api/_serializers/vendor.py b/netbox_lifecycle/api/_serializers/vendor.py new file mode 100644 index 0000000..f0193ec --- /dev/null +++ b/netbox_lifecycle/api/_serializers/vendor.py @@ -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') diff --git a/netbox_lifecycle/api/nested_serializers/__init__.py b/netbox_lifecycle/api/nested_serializers/__init__.py deleted file mode 100644 index edd31fe..0000000 --- a/netbox_lifecycle/api/nested_serializers/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .contract import * -from .hardware import * -from .license import * diff --git a/netbox_lifecycle/api/nested_serializers/contract.py b/netbox_lifecycle/api/nested_serializers/contract.py deleted file mode 100644 index 91fd771..0000000 --- a/netbox_lifecycle/api/nested_serializers/contract.py +++ /dev/null @@ -1,47 +0,0 @@ -from rest_framework import serializers - -from dcim.api.nested_serializers import NestedManufacturerSerializer -from netbox.api.serializers import WritableNestedSerializer -from netbox_lifecycle.models import Vendor, SupportContract, SupportContractAssignment, SupportSKU - -__all__ = ( - 'NestedVendorSerializer', - 'NestedSupportSKUSerializer', - 'NestedSupportContractSerializer', - 'NestedSupportContractAssignmentSerializer', -) - - -class NestedVendorSerializer(WritableNestedSerializer): - url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_lifecycle-api:hardwarelifecycle-detail') - - class Meta: - model = Vendor - fields = ('url', 'id', 'display', 'name') - - -class NestedSupportSKUSerializer(WritableNestedSerializer): - url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_lifecycle-api:hardwarelifecycle-detail') - manufacturer = NestedManufacturerSerializer() - - class Meta: - model = SupportSKU - fields = ('url', 'id', 'display', 'manufacturer', 'sku') - - -class NestedSupportContractSerializer(WritableNestedSerializer): - url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_lifecycle-api:hardwarelifecycle-detail') - vendor = NestedVendorSerializer() - - class Meta: - model = SupportContract - fields = ('url', 'id', 'display', 'contract_id', 'vendor') - - -class NestedSupportContractAssignmentSerializer(WritableNestedSerializer): - url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_lifecycle-api:licenseassignment-detail') - contract = NestedSupportContractSerializer() - - class Meta: - model = SupportContractAssignment - fields = ('url', 'id', 'display', 'contract', 'device', 'license') diff --git a/netbox_lifecycle/api/nested_serializers/hardware.py b/netbox_lifecycle/api/nested_serializers/hardware.py deleted file mode 100644 index c6bfca7..0000000 --- a/netbox_lifecycle/api/nested_serializers/hardware.py +++ /dev/null @@ -1,26 +0,0 @@ -from django.contrib.contenttypes.models import ContentType -from drf_spectacular.utils import extend_schema_field -from rest_framework import serializers - -from netbox.api.fields import ContentTypeField -from netbox.api.serializers import WritableNestedSerializer -from netbox_lifecycle.models import HardwareLifecycle -from utilities.api import get_serializer_for_model - - -class HardwareLifecycleNestedSerializer(WritableNestedSerializer): - url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_routing-api:hardwarelifecycle-detail') - assigned_object_type = ContentTypeField( - queryset=ContentType.objects.all() - ) - assigned_object = serializers.SerializerMethodField(read_only=True) - - class Meta: - model = HardwareLifecycle - fields = ('url', 'id', 'display', 'assigned_object_type', 'assigned_object_id', 'assigned_object', ) - - @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) - context = {'request': self.context['request']} - return serializer(instance.assigned_object, context=context).data diff --git a/netbox_lifecycle/api/nested_serializers/license.py b/netbox_lifecycle/api/nested_serializers/license.py deleted file mode 100644 index c105356..0000000 --- a/netbox_lifecycle/api/nested_serializers/license.py +++ /dev/null @@ -1,31 +0,0 @@ -from rest_framework import serializers - -from dcim.api.nested_serializers import NestedManufacturerSerializer, NestedDeviceSerializer -from netbox.api.serializers import WritableNestedSerializer -from netbox_lifecycle.api.nested_serializers import NestedVendorSerializer -from netbox_lifecycle.models import License, LicenseAssignment - -__all__ = ( - 'NestedLicenseSerializer', - 'NestedLicenseAssignmentSerializer', -) - - -class NestedLicenseSerializer(WritableNestedSerializer): - url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_lifecycle-api:license-detail') - manufacturer = NestedManufacturerSerializer() - - class Meta: - model = License - fields = ('url', 'id', 'display', 'name', 'manufacturer', ) - - -class NestedLicenseAssignmentSerializer(WritableNestedSerializer): - url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_lifecycle-api:licenseassignment-detail') - license = NestedLicenseSerializer() - vendor = NestedVendorSerializer() - device = NestedDeviceSerializer() - - class Meta: - model = LicenseAssignment - fields = ('url', 'id', 'display', 'vendor', 'license', 'device') diff --git a/netbox_lifecycle/api/serializers.py b/netbox_lifecycle/api/serializers.py new file mode 100644 index 0000000..b7686aa --- /dev/null +++ b/netbox_lifecycle/api/serializers.py @@ -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', +) diff --git a/netbox_lifecycle/api/serializers/__init__.py b/netbox_lifecycle/api/serializers/__init__.py deleted file mode 100644 index 2f71a90..0000000 --- a/netbox_lifecycle/api/serializers/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from .contract import * -from .hardware import * -from .license import * - -from netbox_lifecycle.api.nested_serializers import * diff --git a/setup.py b/setup.py index 9f2b5b8..665c6a2 100644 --- a/setup.py +++ b/setup.py @@ -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/',