Skip to content

Commit

Permalink
Merge branch 'next3.0' into app-nist-cve-sync3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bminnix authored Aug 12, 2024
2 parents d543611 + 2aed02c commit 3dfb613
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 38 deletions.
1 change: 1 addition & 0 deletions changes/346.documentation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated documentation pages to be populated.
2 changes: 2 additions & 0 deletions changes/353.added
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added Tag column to Contract list view
Added the ability to filter Contracts based on Tags
1 change: 1 addition & 0 deletions changes/353.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed exporting of Contracts to include Tags.
15 changes: 8 additions & 7 deletions docs/admin/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ sudo systemctl restart nautobot nautobot-worker nautobot-scheduler
## App Configuration

The app behavior can be controlled with the following list of settings:
| Key | Example | Default | Description |
| -------------------- | ------------------------------------------------------------------- | ------------------ | -------------------------------------------------------------------- |
| `expired_field` | `end_of_support` | `end_of_support` | The field name representing the expiry date. |
| `barchart_bar_width` | `0.1` | `0.15` | The width of the table bar within the overview report. |
| `barchart_width` | `12` | `12` | The width of the barchart within the overview report. |
| `barchart_height` | `5` | `5` | The height of the barchart within the overview report. |
| `enabled_metrics` | `["metrics_lcm_hw_end_of_support_location"]` | `[]` | Enables metrics corresponding to the provided entries. |

| Key | ENV VAR | Example | Default | Description |
| -------------------- | ------- | ------------------------- | ------- | -------------------------------------------------------------------- |
| `expired_field` | `NAUTOBOT_DLM_EXPIRED_FIELD` | `end_of_support` | `end_of_support` | The field name representing the expiry date. |
| `barchart_bar_width` | `BARCHART_BAR_WIDTH` | `0.1` | `0.15` | The width of the table bar within the overview report. |
| `barchart_width` | `BARCHART_WIDTH` | `12` | `12` | The width of the barchart within the overview report. |
| `barchart_height` | `BARCHART_HEIGHT` | `5` | `5` | The height of the barchart within the overview report. |
| `enabled_metrics` | `NAUTOBOT_DLM_ENABLED_METRICS` | `["nautobot_lcm_hw_end_of_support_per_location"]` | `[]` | Enables metrics corresponding to the provided, comma separated, entries. |

### Available Metric Names

Expand Down
1 change: 1 addition & 0 deletions nautobot_device_lifecycle_mgmt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class NautobotDeviceLifecycleManagementConfig(NautobotAppConfig):
"enabled_metrics": [],
}
caching_config = {}
docs_view_name = "plugins:nautobot_device_lifecycle_mgmt:docs"

def ready(self):
"""Register custom signals."""
Expand Down
7 changes: 4 additions & 3 deletions nautobot_device_lifecycle_mgmt/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""API serializers implementation for the LifeCycle Management app."""

from nautobot.apps.api import NautobotModelSerializer
from nautobot.apps.api import NautobotModelSerializer, TaggedModelSerializerMixin

from nautobot_device_lifecycle_mgmt.models import (
CVELCM,
Expand Down Expand Up @@ -34,7 +33,9 @@ class Meta:
fields = "__all__"


class ContractLCMSerializer(NautobotModelSerializer): # pylint: disable=R0901,too-few-public-methods
class ContractLCMSerializer(
NautobotModelSerializer, TaggedModelSerializerMixin
): # pylint: disable=R0901,too-few-public-methods
"""API serializer."""

class Meta:
Expand Down
1 change: 1 addition & 0 deletions nautobot_device_lifecycle_mgmt/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ class Meta:
"contract_type",
"expired",
"currency",
"tags",
]

def search(self, queryset, name, value): # pylint: disable=unused-argument, no-self-use
Expand Down
2 changes: 2 additions & 0 deletions nautobot_device_lifecycle_mgmt/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ class ContractLCMFilterForm(NautobotFilterForm):
required=False, widget=StaticSelect2, choices=add_blank_choice(ContractTypeChoices.CHOICES)
)
name = forms.CharField(required=False)
tags = TagFilterField(model)

class Meta:
"""Meta attributes for the ContractLCMFilterForm class."""
Expand All @@ -516,6 +517,7 @@ class Meta:
"support_level",
"contract_type",
"devices",
"tags",
]

widgets = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by Django 4.2.14 on 2024-08-05 22:28

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("nautobot_device_lifecycle_mgmt", "0021_update_max_char_length"),
]

operations = [
migrations.AlterField(
model_name="softwareimagelcm",
name="inventory_items",
field=models.ManyToManyField(blank=True, related_name="+", to="dcim.inventoryitem"),
),
migrations.AlterField(
model_name="softwareimagelcm",
name="object_tags",
field=models.ManyToManyField(blank=True, related_name="+", to="extras.tag"),
),
migrations.AlterField(
model_name="validatedsoftwarelcm",
name="device_roles",
field=models.ManyToManyField(blank=True, related_name="+", to="extras.role"),
),
migrations.AlterField(
model_name="validatedsoftwarelcm",
name="device_types",
field=models.ManyToManyField(blank=True, related_name="+", to="dcim.devicetype"),
),
migrations.AlterField(
model_name="validatedsoftwarelcm",
name="devices",
field=models.ManyToManyField(blank=True, related_name="+", to="dcim.device"),
),
migrations.AlterField(
model_name="validatedsoftwarelcm",
name="inventory_items",
field=models.ManyToManyField(blank=True, related_name="+", to="dcim.inventoryitem"),
),
migrations.AlterField(
model_name="validatedsoftwarelcm",
name="object_tags",
field=models.ManyToManyField(blank=True, related_name="+", to="extras.tag"),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class Migration(migrations.Migration):
("dcim", "0055_softwareimage_softwareversion_data_migration"),
("contenttypes", "0002_remove_content_type_name"),
("extras", "0057_jobbutton"),
("nautobot_device_lifecycle_mgmt", "0021_update_max_char_length"),
("nautobot_device_lifecycle_mgmt", "0022_alter_softwareimagelcm_inventory_items_and_more"),
("users", "0001_initial"),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Migration(migrations.Migration):
("extras", "0104_contact_contactassociation_team"),
("contenttypes", "0002_remove_content_type_name"),
("extras", "0057_jobbutton"),
("nautobot_device_lifecycle_mgmt", "0022_migrate_to_core_software_models"),
("nautobot_device_lifecycle_mgmt", "0023_migrate_to_core_software_models"),
("users", "0001_initial"),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Migration(migrations.Migration):
dependencies = [
("nautobot_device_lifecycle_mgmt", "0023_migrate_contact_to_core_model"),
("nautobot_device_lifecycle_mgmt", "0024_migrate_contact_to_core_model"),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def save_existing_softwarelcm_references(apps, schema_editor):

class Migration(migrations.Migration):
dependencies = [
("nautobot_device_lifecycle_mgmt", "0024_migrate_soft_references_p1"),
("nautobot_device_lifecycle_mgmt", "0025_migrate_soft_references_p1"),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Migration(migrations.Migration):
dependencies = [
("nautobot_device_lifecycle_mgmt", "0025_migrate_soft_references_p2"),
("nautobot_device_lifecycle_mgmt", "0026_migrate_soft_references_p2"),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def migrate_softwarelcm_references(apps, schema_editor):

class Migration(migrations.Migration):
dependencies = [
("nautobot_device_lifecycle_mgmt", "0026_migrate_soft_references_p3"),
("nautobot_device_lifecycle_mgmt", "0027_migrate_soft_references_p3"),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Migration(migrations.Migration):
dependencies = [
("nautobot_device_lifecycle_mgmt", "0027_migrate_soft_references_p4"),
("nautobot_device_lifecycle_mgmt", "0028_migrate_soft_references_p4"),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Migration(migrations.Migration):
dependencies = [
("dcim", "0058_controller_data_migration"),
("nautobot_device_lifecycle_mgmt", "0028_migrate_soft_references_p5"),
("nautobot_device_lifecycle_mgmt", "0029_migrate_soft_references_p5"),
]

operations = [
Expand Down
21 changes: 2 additions & 19 deletions nautobot_device_lifecycle_mgmt/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,6 @@
)


class M2MLinkedCountColumn(LinkedCountColumn):
"""Linked count column supporting many-to-many fields."""

def render(self, record, value):
"""Render the resulting URL."""
if value:
url = reverse(self.viewname, kwargs=self.view_kwargs)
if self.url_params:
url += "?"
for key, kval in self.url_params.items():
if isinstance(kval, tuple):
values = getattr(record, kval[0]).values(kval[1])
url += "&".join([f"{key}={val[key]}" for val in values])
else:
url += f"&{key}={getattr(record, kval)}"
return mark_safe(f'<a href="{url}">{value}</a>') # nosec
return value


class PercentageColumn(tables.Column):
"""Column used to display percentage."""

Expand Down Expand Up @@ -347,6 +328,7 @@ class ContractLCMTable(BaseTable):
template_code="""{{ record.cost }}{% if record.currency %} {{ record.currency }}{% endif %}"""
)
actions = ButtonsColumn(ContractLCM, buttons=("changelog", "edit", "delete"))
tags = TagColumn(url_name="plugins:nautobot_device_lifecycle_mgmt:contractlcm_list")

class Meta(BaseTable.Meta):
"""Meta attributes."""
Expand All @@ -362,6 +344,7 @@ class Meta(BaseTable.Meta):
"contract_type",
"devices",
"provider",
"tags",
"actions",
)

Expand Down
2 changes: 1 addition & 1 deletion nautobot_device_lifecycle_mgmt/tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_metrics_lcm_validation_report_inventory_item(self):
self.assertEqual(expected_ts_samples[sample_labels], sample.value)

def test_metrics_lcm_hw_end_of_support_location_does_not_error(self):
"""Query providing data to metrics_lcm_hw_end_of_support_part_number metric should not error out.
"""Query providing data to hw_end_of_support_location_gauge metric should not error out.
Guards against https://github.com/nautobot/nautobot-app-device-lifecycle-mgmt/issues/309
"""
metric_gen = metrics_lcm_hw_end_of_support_location()
Expand Down
7 changes: 7 additions & 0 deletions nautobot_device_lifecycle_mgmt/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Django urlpatterns declaration for the Lifecycle Management app."""

from django.urls import path
from django.templatetags.static import static
from django.views.generic import RedirectView

from nautobot.apps.urls import NautobotUIViewSetRouter

from nautobot_device_lifecycle_mgmt import views
Expand Down Expand Up @@ -43,5 +46,9 @@
"software-versions/<uuid:pk>/related-cves/",
views.SoftwareVersionRelatedCveView.as_view(),
name="softwareversion_related_cves",
path(
"docs/",
RedirectView.as_view(url=static("nautobot_device_lifecycle_mgmt/docs/index.html")),
name="docs",
),
]

0 comments on commit 3dfb613

Please sign in to comment.