Skip to content

Update jobs.py to support Dynamic Groups#378

Open
jdpfda wants to merge 1 commit intonautobot:developfrom
jdpfda:Issue-375
Open

Update jobs.py to support Dynamic Groups#378
jdpfda wants to merge 1 commit intonautobot:developfrom
jdpfda:Issue-375

Conversation

@jdpfda
Copy link
Copy Markdown

@jdpfda jdpfda commented Jun 4, 2025

Added support for Dynamic Groups into the Sync Data from Network Job.

Closes: #375

What's Changed

Added the ability to use a dynamic group for the Sync Data from Network job.
Changes:
32 + DynamicGroup,
...
646 + dynamic_group = ObjectVar(
647 + model=DynamicGroup,
648 + required=False,
649 + description="Only update devices that belong to this Dynamic Group.",
650 + )
...
677 + dynamic_group,
...
697 + self.dynamic_group = dynamic_group
...
738 + if self.dynamic_group:
739 + # Get all Device IDs in that DynamicGroup
740 + group_device_ids = self.dynamic_group.members.values_list("id", flat=True)
741 + # Overwrite (or set) the id__in filter so we only get devices in that group
742 + device_filter["id__in"] = list(group_device_ids)

To Do

N/A

Added support for Dynamic Groups into the Sync Data from Network Job.
@scetron
Copy link
Copy Markdown
Contributor

scetron commented Aug 1, 2025

Thank you for your contribution! We plan to review and merge this shortly.

As an alternative to Dynamic Groups that you have added, we are also considering a change of default behavior: to sync devices from all the child locations of a location, which may also address your requirement.

@jdpfda
Copy link
Copy Markdown
Author

jdpfda commented Aug 1, 2025

Thanks scetron, Hold this for a day or so. I found an issue I need to address last night and haven't had time to fix it. The Child Locations would help as well. I can see a reason to support both. I could see where you might have dynamic groups of locations w/ specific types of devices or other criteria than just location.

@scetron
Copy link
Copy Markdown
Contributor

scetron commented Sep 5, 2025

Hello @jdpfda ! Were you able to get a fix in for the issue you found? If not, you can provide the issue and we can also take a look.

device_filter["platform"] = platform
if device_filter: # prevent all devices from being returned by an empty filter
self.filtered_devices = Device.objects.filter(**device_filter)
if self.dynamic_group:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scetron I think this needs to set self.filtered_devices instead of device_filter

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually maybe it should be moved up 2 lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sync Data from Network - Dynamic Group

3 participants