Skip to content

Commit

Permalink
Updated to be a bit easier to expand using itertools product
Browse files Browse the repository at this point in the history
  • Loading branch information
bminnix committed Dec 12, 2024
1 parent 3edd175 commit 892e2e6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions nautobot_device_lifecycle_mgmt/jobs/lifecycle_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Jobs for the Lifecycle Management app."""

from datetime import datetime
from itertools import product

from nautobot.dcim.models import Device, InventoryItem, Platform
from nautobot.extras.jobs import Job, MultiObjectVar
Expand Down Expand Up @@ -122,18 +123,17 @@ def run(self, **filters) -> None: # pylint: disable=arguments-differ
# If no platforms or tenants are provided, use all platforms and tenants
if not platforms:
platforms = Platform.objects.all()

if not tenants:
tenants = Tenant.objects.all()

# Get versioned and non-versioned devices for each platform
for platform in platforms:
versioned_devices.extend(Device.objects.filter(platform=platform, software_version__isnull=False))
non_versioned_devices.extend(Device.objects.filter(platform=platform, software_version__isnull=True))
# Get all combinations of platforms and tenants
filtered_products = product(platforms, tenants)

# Get versioned and non-versioned devices for each tenant
for tenant in tenants:
versioned_devices.extend(Device.objects.filter(tenant=tenant, software_version__isnull=False))
non_versioned_devices.extend(Device.objects.filter(tenant=tenant, software_version__isnull=True))
# Get versioned and non-versioned devices
for platform, tenant in filtered_products:
versioned_devices.extend(Device.objects.filter(platform=platform, tenant=tenant, software_version__isnull=False))
non_versioned_devices.extend(Device.objects.filter(platform=platform, tenant=tenant, software_version__isnull=True))

# Validate devices without software version
for device in non_versioned_devices:
Expand Down

0 comments on commit 892e2e6

Please sign in to comment.