diff --git a/netbox_slm/forms/__init__.py b/netbox_slm/forms/__init__.py index f8d7033..15ffff5 100644 --- a/netbox_slm/forms/__init__.py +++ b/netbox_slm/forms/__init__.py @@ -1,4 +1,4 @@ -from .software_license import SoftwareLicenseForm, SoftwareLicenseFilterForm -from .software_product import SoftwareProductForm, SoftwareProductFilterForm -from .software_product_installation import SoftwareProductInstallationForm, SoftwareProductInstallationFilterForm -from .software_product_version import SoftwareProductVersionForm, SoftwareProductVersionFilterForm +from .software_license import SoftwareLicenseForm, SoftwareLicenseFilterForm, SoftwareLicenseBulkImportForm +from .software_product import SoftwareProductForm, SoftwareProductFilterForm, SoftwareProductBulkImportForm +from .software_product_installation import SoftwareProductInstallationForm, SoftwareProductInstallationFilterForm, SoftwareProductInstallationBulkImportForm +from .software_product_version import SoftwareProductVersionForm, SoftwareProductVersionFilterForm, SoftwareProductVersionBulkImportForm diff --git a/netbox_slm/forms/software_license.py b/netbox_slm/forms/software_license.py index c0dbc67..8273665 100644 --- a/netbox_slm/forms/software_license.py +++ b/netbox_slm/forms/software_license.py @@ -1,7 +1,7 @@ from django.forms import DateField from django.urls import reverse_lazy -from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm +from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelImportForm from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField, LaxURLField from utilities.forms.rendering import FieldSet @@ -46,6 +46,7 @@ class Meta: fields = ( "name", "description", + "software_product", "type", "stored_location", "stored_location_url", @@ -53,7 +54,6 @@ class Meta: "expiration_date", "support", "license_amount", - "software_product", "version", "installation", "tags", @@ -65,3 +65,24 @@ class SoftwareLicenseFilterForm(NetBoxModelFilterSetForm): model = SoftwareLicense fieldsets = (FieldSet(None, ("q", "tag")),) tag = TagFilterField(model) + + +class SoftwareLicenseBulkImportForm(NetBoxModelImportForm): + class Meta: + model = SoftwareLicense + fields = ( + "name", + "description", + "software_product", + "type", + "stored_location", + "stored_location_url", + "start_date", + "expiration_date", + "support", + "license_amount", + "version", + "installation", + "tags", + "comments", + ) \ No newline at end of file diff --git a/netbox_slm/forms/software_product.py b/netbox_slm/forms/software_product.py index 5e920d5..cc2e38d 100644 --- a/netbox_slm/forms/software_product.py +++ b/netbox_slm/forms/software_product.py @@ -1,5 +1,5 @@ from dcim.models import Manufacturer -from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm +from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelImportForm from netbox_slm.models import SoftwareProduct from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField from utilities.forms.rendering import FieldSet @@ -30,3 +30,14 @@ class SoftwareProductFilterForm(NetBoxModelFilterSetForm): model = SoftwareProduct fieldsets = (FieldSet(None, ("q", "tag")),) tag = TagFilterField(model) + +class SoftwareProductBulkImportForm(NetBoxModelImportForm): + class Meta: + model = SoftwareProduct + fields = ( + "name", + "description", + "manufacturer", + "tags", + "comments", + ) diff --git a/netbox_slm/forms/software_product_installation.py b/netbox_slm/forms/software_product_installation.py index f3d036e..7e848ae 100644 --- a/netbox_slm/forms/software_product_installation.py +++ b/netbox_slm/forms/software_product_installation.py @@ -2,7 +2,7 @@ from django.urls import reverse_lazy from dcim.models import Device -from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm +from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelImportForm from netbox_slm.models import SoftwareProductInstallation, SoftwareProduct, SoftwareProductVersion from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField from utilities.forms.rendering import FieldSet @@ -59,3 +59,17 @@ class SoftwareProductInstallationFilterForm(NetBoxModelFilterSetForm): model = SoftwareProductInstallation fieldsets = (FieldSet(None, ("q", "tag")),) tag = TagFilterField(model) + +class SoftwareProductInstallationBulkImportForm(NetBoxModelImportForm): + class Meta: + model = SoftwareProductInstallation + fields = ( + "device", + "virtualmachine", + "cluster", + "software_product", + "version", + "tags", + "comments", + ) + \ No newline at end of file diff --git a/netbox_slm/forms/software_product_version.py b/netbox_slm/forms/software_product_version.py index fd2c74f..f4004e1 100644 --- a/netbox_slm/forms/software_product_version.py +++ b/netbox_slm/forms/software_product_version.py @@ -1,7 +1,7 @@ from django.forms import DateField from django.urls import reverse_lazy -from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm +from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelImportForm from netbox_slm.models import SoftwareProduct, SoftwareProductVersion from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField from utilities.forms.rendering import FieldSet @@ -25,6 +25,7 @@ class Meta: model = SoftwareProductVersion fields = ( "name", + "software_product", "release_date", "documentation_url", "end_of_support", @@ -32,7 +33,6 @@ class Meta: "file_checksum", "file_link", "release_type", - "software_product", "tags", "comments", ) @@ -42,3 +42,20 @@ class SoftwareProductVersionFilterForm(NetBoxModelFilterSetForm): model = SoftwareProductVersion fieldsets = (FieldSet(None, ("q", "tag")),) tag = TagFilterField(model) + +class SoftwareProductVersionBulkImportForm(NetBoxModelImportForm): + class Meta: + model = SoftwareProductVersion + fields = ( + "name", + "software_product", + "release_date", + "documentation_url", + "end_of_support", + "filename", + "file_checksum", + "file_link", + "release_type", + "tags", + "comments", + ) \ No newline at end of file diff --git a/netbox_slm/navigation.py b/netbox_slm/navigation.py index ae53bec..2e7767c 100644 --- a/netbox_slm/navigation.py +++ b/netbox_slm/navigation.py @@ -1,6 +1,9 @@ -from netbox.plugins import PluginMenuButton, PluginMenuItem +from netbox.plugins import PluginMenuButton, PluginMenuItem, PluginMenu +from django.conf import settings -menu_items = ( +plugin_settings = settings.PLUGINS_CONFIG["netbox_slm"] + +items = ( PluginMenuItem( link="plugins:netbox_slm:softwareproduct_list", link_text="Software Products", @@ -12,6 +15,12 @@ "mdi mdi-plus-thick", permissions=["netbox_slm.add_softwareproduct"], ), + PluginMenuButton( + "plugins:netbox_slm:softwareproduct_import", + "Import", + "mdi mdi-upload", + permissions=["netbox_slm.import_softwareproduct"], + ), ), ), PluginMenuItem( @@ -25,6 +34,12 @@ "mdi mdi-plus-thick", permissions=["netbox_slm.add_softwareproductversion"], ), + PluginMenuButton( + "plugins:netbox_slm:softwareproductversion_import", + "Import", + "mdi mdi-upload", + permissions=["netbox_slm.import_softwareproductversion"], + ), ), ), PluginMenuItem( @@ -38,6 +53,12 @@ "mdi mdi-plus-thick", permissions=["netbox_slm.add_softwareproductinstallation"], ), + PluginMenuButton( + "plugins:netbox_slm:softwareproductinstallation_import", + "Import", + "mdi mdi-upload", + permissions=["netbox_slm.import_softwareproductinstallation"], + ), ), ), PluginMenuItem( @@ -51,6 +72,23 @@ "mdi mdi-plus-thick", permissions=["netbox_slm.add_softwarelicense"], ), + PluginMenuButton( + "plugins:netbox_slm:softwarelicense_import", + "Import", + "mdi mdi-upload", + permissions=["netbox_slm.import_softwarelicense"], + ), ), ), ) + + + +if plugin_settings.get("top_level_menu"): + menu = PluginMenu( + label="Software Lifecycle", + groups=(("SOFTWARE Lifecycle", items),), + icon_class="mdi mdi-content-save", + ) +else: + menu_items = items diff --git a/netbox_slm/urls.py b/netbox_slm/urls.py index 4856d47..7cbb2bf 100644 --- a/netbox_slm/urls.py +++ b/netbox_slm/urls.py @@ -93,4 +93,9 @@ name="softwarelicense_changelog", kwargs={"model": SoftwareLicense}, ), + path('software-products/import/', views.SoftwareProductBulkImportView.as_view(), name='softwareproduct_import'), + path('installations/import/', views.SoftwareProductInstallationBulkImportView.as_view(), name='softwareproductinstallation_import'), + path('versions/import/', views.SoftwareProductVersionBulkImportView.as_view(), name='softwareproductversion_import'), + path('licenses/import/', views.SoftwareLicenseBulkImportView.as_view(), name='softwarelicense_import'), + ] diff --git a/netbox_slm/views/__init__.py b/netbox_slm/views/__init__.py index 6a54180..37196f2 100644 --- a/netbox_slm/views/__init__.py +++ b/netbox_slm/views/__init__.py @@ -4,6 +4,8 @@ SoftwareLicenseEditView, SoftwareLicenseDeleteView, SoftwareLicenseBulkDeleteView, + SoftwareLicenseBulkImportView, + ) from .software_product import ( SoftwareProductListView, @@ -11,6 +13,8 @@ SoftwareProductEditView, SoftwareProductDeleteView, SoftwareProductBulkDeleteView, + SoftwareProductBulkImportView, + ) from .software_product_installation import ( SoftwareProductInstallationListView, @@ -18,6 +22,8 @@ SoftwareProductInstallationEditView, SoftwareProductInstallationDeleteView, SoftwareProductInstallationBulkDeleteView, + SoftwareProductInstallationBulkImportView, + ) from .software_product_version import ( SoftwareProductVersionListView, @@ -25,4 +31,6 @@ SoftwareProductVersionEditView, SoftwareProductVersionDeleteView, SoftwareProductVersionBulkDeleteView, + SoftwareProductVersionBulkImportView, + ) diff --git a/netbox_slm/views/software_license.py b/netbox_slm/views/software_license.py index b57e754..8f8b6d4 100644 --- a/netbox_slm/views/software_license.py +++ b/netbox_slm/views/software_license.py @@ -32,5 +32,13 @@ class SoftwareLicenseDeleteView(generic.ObjectDeleteView): class SoftwareLicenseBulkDeleteView(generic.BulkDeleteView): + queryset = SoftwareLicense.objects.all() table = tables.SoftwareLicenseTable + + +class SoftwareLicenseBulkImportView(generic.BulkImportView): + + queryset = SoftwareLicense.objects.all() + table = tables.SoftwareLicenseTable + model_form = forms.SoftwareLicenseBulkImportForm diff --git a/netbox_slm/views/software_product.py b/netbox_slm/views/software_product.py index 2d8e6a8..74d9a53 100644 --- a/netbox_slm/views/software_product.py +++ b/netbox_slm/views/software_product.py @@ -1,5 +1,5 @@ from netbox.views import generic -from netbox_slm import filtersets, forms, tables +from netbox_slm import filtersets, forms, tables, models from netbox_slm.models import SoftwareProduct @@ -31,10 +31,17 @@ class SoftwareProductEditView(generic.ObjectEditView): class SoftwareProductDeleteView(generic.ObjectDeleteView): """View for deleting a SoftwareProduct instance""" - queryset = SoftwareProduct.objects.all() class SoftwareProductBulkDeleteView(generic.BulkDeleteView): + + queryset = SoftwareProduct.objects.all() + table = tables.SoftwareProductTable + + +class SoftwareProductBulkImportView(generic.BulkImportView): + queryset = SoftwareProduct.objects.all() table = tables.SoftwareProductTable + model_form = forms.SoftwareProductBulkImportForm diff --git a/netbox_slm/views/software_product_installation.py b/netbox_slm/views/software_product_installation.py index f0cf444..2c6a915 100644 --- a/netbox_slm/views/software_product_installation.py +++ b/netbox_slm/views/software_product_installation.py @@ -1,5 +1,5 @@ from netbox.views import generic -from netbox_slm import filtersets, forms, tables +from netbox_slm import filtersets, forms, tables, models from netbox_slm.models import SoftwareProductInstallation @@ -32,5 +32,12 @@ class SoftwareProductInstallationDeleteView(generic.ObjectDeleteView): class SoftwareProductInstallationBulkDeleteView(generic.BulkDeleteView): + queryset = SoftwareProductInstallation.objects.all() table = tables.SoftwareProductInstallationTable + +class SoftwareProductInstallationBulkImportView(generic.BulkImportView): + + queryset = SoftwareProductInstallation.objects.all() + table = tables.SoftwareProductInstallationTable + model_form = forms.SoftwareProductInstallationBulkImportForm diff --git a/netbox_slm/views/software_product_version.py b/netbox_slm/views/software_product_version.py index 7f89fca..974b76a 100644 --- a/netbox_slm/views/software_product_version.py +++ b/netbox_slm/views/software_product_version.py @@ -1,5 +1,5 @@ from netbox.views import generic -from netbox_slm import filtersets, forms, tables +from netbox_slm import filtersets, forms, tables, models from netbox_slm.models import SoftwareProductVersion @@ -36,5 +36,13 @@ class SoftwareProductVersionDeleteView(generic.ObjectDeleteView): class SoftwareProductVersionBulkDeleteView(generic.BulkDeleteView): + queryset = SoftwareProductVersion.objects.all() table = tables.SoftwareProductVersionTable + + +class SoftwareProductVersionBulkImportView(generic.BulkImportView): + + queryset = SoftwareProductVersion.objects.all() + table = tables.SoftwareProductVersionTable + model_form = forms.SoftwareProductVersionBulkImportForm