peteeckel / netbox-plugin-dns

NetBox DNS is a NetBox plugin for managing DNS data.
https://pypi.org/project/netbox-plugin-dns
MIT License
205 stars 17 forks source link

[QUESTION] Zone Exporter Script #451

Closed shakin89 closed 1 month ago

shakin89 commented 1 month ago

Versions NetBox Version: 4.1.4 NetBox DNS Version: 1.1.4 Python Version: 3.11.2

Describe the bug I was using the example script to export dns zones to a file and use these with ansible. The script has always functioned with netbox 3.x and netbox_dns up to 0.6.x

I've upgradet to netbox 4.1 and dns 1.1.4 In the export script there is a line calling

 for view in views:
            zones = Zone.objects.filter(view=view, status__in=Zone.ACTIVE_STATUS_LIST)

but searching through the code i saw that Zone.ACTIVE_STATUS_LIST has disappeared. I tried to replace it with Zone.ZONE_ACTIVE_STATUS_LIST but when i run the script i alwasy get the error

Traceback (most recent call last):
  File "/opt/netbox/releases/netbox-4.1.4/netbox/extras/jobs.py", line 45, in run_script
    script.output = script.run(data, commit)
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/shared/scripts/dns_zone_exporter.py", line 80, in run
    zones = Zone.objects.filter(view=view, status__in=Zone.ZONE_ACTIVE_STATUS_LIST)
                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'Zone' has no attribute 'ZONE_ACTIVE_STATUS_LIST'

It should not be necessary, but i configured two options "zone_active_status": [ZoneStatusChoices.STATUS_ACTIVE, ZoneStatusChoices.STATUS_DYNAMIC], "record_active_status": [RecordStatusChoices.STATUS_ACTIVE] without success. Any help would be very appreciated. Thanks in advance.

peteeckel commented 1 month ago

True, ACTIVE_STATUS_LIST has disappeared because the list of active zone (and record) statuses has become configurable.

You can simplify this code by using

            zones = Zone.objects.filter(view=view, active=True)

instead (edit: For records, it's just the same).

shakin89 commented 1 month ago

Wow, i really appreciate your work!!! many many thanks! now it works like a charm!!!