netbox-plugin-dns 1.1.0b7__py3-none-any.whl → 1.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of netbox-plugin-dns might be problematic. Click here for more details.
- netbox_dns/__init__.py +3 -2
- netbox_dns/api/nested_serializers.py +17 -16
- netbox_dns/api/serializers.py +1 -1
- netbox_dns/api/serializers_/record.py +1 -0
- netbox_dns/api/serializers_/{contact.py → registration_contact.py} +5 -5
- netbox_dns/api/serializers_/view.py +1 -0
- netbox_dns/api/serializers_/zone.py +5 -5
- netbox_dns/api/serializers_/zone_template.py +5 -5
- netbox_dns/api/urls.py +2 -2
- netbox_dns/api/views.py +7 -35
- netbox_dns/filtersets/__init__.py +1 -1
- netbox_dns/filtersets/nameserver.py +0 -0
- netbox_dns/filtersets/record.py +0 -0
- netbox_dns/filtersets/record_template.py +0 -0
- netbox_dns/filtersets/{contact.py → registration_contact.py} +4 -4
- netbox_dns/filtersets/zone.py +15 -15
- netbox_dns/filtersets/zone_template.py +15 -15
- netbox_dns/forms/__init__.py +1 -1
- netbox_dns/forms/nameserver.py +0 -0
- netbox_dns/forms/record.py +0 -0
- netbox_dns/forms/record_template.py +0 -0
- netbox_dns/forms/{contact.py → registration_contact.py} +16 -16
- netbox_dns/forms/view.py +29 -10
- netbox_dns/forms/zone.py +13 -13
- netbox_dns/forms/zone_template.py +13 -13
- netbox_dns/graphql/__init__.py +2 -2
- netbox_dns/graphql/filters.py +5 -5
- netbox_dns/graphql/schema.py +23 -53
- netbox_dns/graphql/types.py +39 -12
- netbox_dns/migrations/0007_alter_ordering_options.py +25 -0
- netbox_dns/migrations/{0007_view_prefixes.py → 0008_view_prefixes.py} +1 -1
- netbox_dns/migrations/0009_rename_contact_registrationcontact.py +36 -0
- netbox_dns/migrations/0010_view_ip_address_filter.py +18 -0
- netbox_dns/mixins/object_modification.py +30 -8
- netbox_dns/models/__init__.py +1 -1
- netbox_dns/models/nameserver.py +8 -3
- netbox_dns/models/record.py +47 -14
- netbox_dns/models/record_template.py +4 -1
- netbox_dns/models/registrar.py +7 -1
- netbox_dns/models/{contact.py → registration_contact.py} +15 -9
- netbox_dns/models/view.py +49 -2
- netbox_dns/models/zone.py +24 -18
- netbox_dns/models/zone_template.py +12 -9
- netbox_dns/navigation.py +7 -7
- netbox_dns/signals/ipam_dnssync.py +4 -4
- netbox_dns/tables/__init__.py +1 -1
- netbox_dns/tables/nameserver.py +1 -7
- netbox_dns/tables/record.py +10 -35
- netbox_dns/tables/record_template.py +0 -17
- netbox_dns/tables/registrar.py +0 -2
- netbox_dns/tables/{contact.py → registration_contact.py} +5 -6
- netbox_dns/tables/view.py +1 -8
- netbox_dns/tables/zone.py +0 -15
- netbox_dns/tables/zone_template.py +2 -16
- netbox_dns/templates/netbox_dns/{contact.html → registrationcontact.html} +1 -1
- netbox_dns/templates/netbox_dns/view.html +16 -0
- netbox_dns/urls/__init__.py +2 -2
- netbox_dns/urls/nameserver.py +14 -38
- netbox_dns/urls/record.py +7 -19
- netbox_dns/urls/record_template.py +18 -27
- netbox_dns/urls/registrar.py +11 -35
- netbox_dns/urls/registration_contact.py +60 -0
- netbox_dns/urls/view.py +8 -22
- netbox_dns/urls/zone.py +8 -46
- netbox_dns/urls/zone_template.py +16 -26
- netbox_dns/utilities/ipam_dnssync.py +58 -26
- netbox_dns/views/__init__.py +1 -1
- netbox_dns/views/nameserver.py +7 -3
- netbox_dns/views/record.py +12 -3
- netbox_dns/views/record_template.py +1 -1
- netbox_dns/views/registrar.py +0 -1
- netbox_dns/views/registration_contact.py +94 -0
- netbox_dns/views/view.py +6 -1
- netbox_dns/views/zone.py +7 -6
- netbox_dns/views/zone_template.py +2 -2
- {netbox_plugin_dns-1.1.0b7.dist-info → netbox_plugin_dns-1.1.2.dist-info}/METADATA +14 -14
- {netbox_plugin_dns-1.1.0b7.dist-info → netbox_plugin_dns-1.1.2.dist-info}/RECORD +80 -76
- {netbox_plugin_dns-1.1.0b7.dist-info → netbox_plugin_dns-1.1.2.dist-info}/WHEEL +2 -1
- netbox_plugin_dns-1.1.2.dist-info/top_level.txt +1 -0
- netbox_dns/urls/contact.py +0 -51
- netbox_dns/views/contact.py +0 -95
- {netbox_plugin_dns-1.1.0b7.dist-info → netbox_plugin_dns-1.1.2.dist-info}/LICENSE +0 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from django.urls import include, path
|
|
2
|
+
|
|
3
|
+
from utilities.urls import get_model_urls
|
|
4
|
+
|
|
5
|
+
from netbox_dns.views import (
|
|
6
|
+
RegistrationContactView,
|
|
7
|
+
RegistrationContactListView,
|
|
8
|
+
RegistrationContactEditView,
|
|
9
|
+
RegistrationContactDeleteView,
|
|
10
|
+
RegistrationContactBulkImportView,
|
|
11
|
+
RegistrationContactBulkEditView,
|
|
12
|
+
RegistrationContactBulkDeleteView,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
registrationcontact_urlpatterns = [
|
|
16
|
+
path(
|
|
17
|
+
"registrationcontacts/<int:pk>/",
|
|
18
|
+
RegistrationContactView.as_view(),
|
|
19
|
+
name="registrationcontact",
|
|
20
|
+
),
|
|
21
|
+
path(
|
|
22
|
+
"registrationcontacts/",
|
|
23
|
+
RegistrationContactListView.as_view(),
|
|
24
|
+
name="registrationcontact_list",
|
|
25
|
+
),
|
|
26
|
+
path(
|
|
27
|
+
"registrationcontacts/add/",
|
|
28
|
+
RegistrationContactEditView.as_view(),
|
|
29
|
+
name="registrationcontact_add",
|
|
30
|
+
),
|
|
31
|
+
path(
|
|
32
|
+
"registrationcontacts/<int:pk>/edit/",
|
|
33
|
+
RegistrationContactEditView.as_view(),
|
|
34
|
+
name="registrationcontact_edit",
|
|
35
|
+
),
|
|
36
|
+
path(
|
|
37
|
+
"registrationcontacts/<int:pk>/delete/",
|
|
38
|
+
RegistrationContactDeleteView.as_view(),
|
|
39
|
+
name="registrationcontact_delete",
|
|
40
|
+
),
|
|
41
|
+
path(
|
|
42
|
+
"registrationcontacts/import/",
|
|
43
|
+
RegistrationContactBulkImportView.as_view(),
|
|
44
|
+
name="registrationcontact_import",
|
|
45
|
+
),
|
|
46
|
+
path(
|
|
47
|
+
"registrationcontacts/edit/",
|
|
48
|
+
RegistrationContactBulkEditView.as_view(),
|
|
49
|
+
name="registrationcontact_bulk_edit",
|
|
50
|
+
),
|
|
51
|
+
path(
|
|
52
|
+
"registrationcontacts/delete/",
|
|
53
|
+
RegistrationContactBulkDeleteView.as_view(),
|
|
54
|
+
name="registrationcontact_bulk_delete",
|
|
55
|
+
),
|
|
56
|
+
path(
|
|
57
|
+
"registrationcontacts/<int:pk>/",
|
|
58
|
+
include(get_model_urls("netbox_dns", "registrationcontact")),
|
|
59
|
+
),
|
|
60
|
+
]
|
netbox_dns/urls/view.py
CHANGED
|
@@ -1,42 +1,28 @@
|
|
|
1
|
-
from django.urls import path
|
|
1
|
+
from django.urls import include, path
|
|
2
2
|
|
|
3
|
-
from
|
|
3
|
+
from utilities.urls import get_model_urls
|
|
4
4
|
|
|
5
|
-
from netbox_dns.models import View
|
|
6
5
|
from netbox_dns.views import (
|
|
7
|
-
ViewListView,
|
|
8
6
|
ViewView,
|
|
9
|
-
|
|
7
|
+
ViewListView,
|
|
10
8
|
ViewEditView,
|
|
9
|
+
ViewDeleteView,
|
|
11
10
|
ViewBulkImportView,
|
|
12
11
|
ViewBulkEditView,
|
|
13
12
|
ViewBulkDeleteView,
|
|
14
|
-
ViewZoneListView,
|
|
15
13
|
ViewPrefixEditView,
|
|
16
14
|
)
|
|
17
15
|
|
|
18
16
|
view_urlpatterns = [
|
|
17
|
+
path("views/<int:pk>/", ViewView.as_view(), name="view"),
|
|
19
18
|
path("views/", ViewListView.as_view(), name="view_list"),
|
|
20
19
|
path("views/add/", ViewEditView.as_view(), name="view_add"),
|
|
20
|
+
path("views/<int:pk>/edit/", ViewEditView.as_view(), name="view_edit"),
|
|
21
|
+
path("views/<int:pk>/delete/", ViewDeleteView.as_view(), name="view_delete"),
|
|
21
22
|
path("views/import/", ViewBulkImportView.as_view(), name="view_import"),
|
|
22
23
|
path("views/edit/", ViewBulkEditView.as_view(), name="view_bulk_edit"),
|
|
23
24
|
path("views/delete/", ViewBulkDeleteView.as_view(), name="view_bulk_delete"),
|
|
24
|
-
path("views/<int:pk>/",
|
|
25
|
-
path("views/<int:pk>/edit/", ViewEditView.as_view(), name="view_edit"),
|
|
26
|
-
path("views/<int:pk>/delete/", ViewDeleteView.as_view(), name="view_delete"),
|
|
27
|
-
path("views/<int:pk>/zones/", ViewZoneListView.as_view(), name="view_zones"),
|
|
28
|
-
path(
|
|
29
|
-
"views/<int:pk>/journal/",
|
|
30
|
-
ObjectJournalView.as_view(),
|
|
31
|
-
name="view_journal",
|
|
32
|
-
kwargs={"model": View},
|
|
33
|
-
),
|
|
34
|
-
path(
|
|
35
|
-
"views/<int:pk>/changelog/",
|
|
36
|
-
ObjectChangeLogView.as_view(),
|
|
37
|
-
name="view_changelog",
|
|
38
|
-
kwargs={"model": View},
|
|
39
|
-
),
|
|
25
|
+
path("views/<int:pk>/", include(get_model_urls("netbox_dns", "view"))),
|
|
40
26
|
path(
|
|
41
27
|
"prefixes/<int:pk>/assign-views/",
|
|
42
28
|
ViewPrefixEditView.as_view(),
|
netbox_dns/urls/zone.py
CHANGED
|
@@ -1,63 +1,25 @@
|
|
|
1
|
-
from django.urls import path
|
|
1
|
+
from django.urls import include, path
|
|
2
2
|
|
|
3
|
-
from
|
|
3
|
+
from utilities.urls import get_model_urls
|
|
4
4
|
|
|
5
|
-
from netbox_dns.models import Zone
|
|
6
5
|
from netbox_dns.views import (
|
|
7
|
-
ZoneListView,
|
|
8
6
|
ZoneView,
|
|
9
|
-
|
|
7
|
+
ZoneListView,
|
|
10
8
|
ZoneEditView,
|
|
9
|
+
ZoneDeleteView,
|
|
11
10
|
ZoneBulkImportView,
|
|
12
11
|
ZoneBulkEditView,
|
|
13
12
|
ZoneBulkDeleteView,
|
|
14
|
-
ZoneRecordListView,
|
|
15
|
-
ZoneManagedRecordListView,
|
|
16
|
-
ZoneRegistrationView,
|
|
17
|
-
ZoneRFC2317ChildZoneListView,
|
|
18
|
-
ZoneChildZoneListView,
|
|
19
13
|
)
|
|
20
14
|
|
|
21
15
|
zone_urlpatterns = [
|
|
16
|
+
path("zones/<int:pk>/", ZoneView.as_view(), name="zone"),
|
|
22
17
|
path("zones/", ZoneListView.as_view(), name="zone_list"),
|
|
23
18
|
path("zones/add/", ZoneEditView.as_view(), name="zone_add"),
|
|
19
|
+
path("zones/<int:pk>/edit/", ZoneEditView.as_view(), name="zone_edit"),
|
|
20
|
+
path("zones/<int:pk>/delete/", ZoneDeleteView.as_view(), name="zone_delete"),
|
|
24
21
|
path("zones/import/", ZoneBulkImportView.as_view(), name="zone_import"),
|
|
25
22
|
path("zones/edit/", ZoneBulkEditView.as_view(), name="zone_bulk_edit"),
|
|
26
23
|
path("zones/delete/", ZoneBulkDeleteView.as_view(), name="zone_bulk_delete"),
|
|
27
|
-
path("zones/<int:pk>/",
|
|
28
|
-
path("zones/<int:pk>/delete/", ZoneDeleteView.as_view(), name="zone_delete"),
|
|
29
|
-
path("zones/<int:pk>/edit/", ZoneEditView.as_view(), name="zone_edit"),
|
|
30
|
-
path("zones/<int:pk>/records/", ZoneRecordListView.as_view(), name="zone_records"),
|
|
31
|
-
path(
|
|
32
|
-
"zones/<int:pk>/managedrecords/",
|
|
33
|
-
ZoneManagedRecordListView.as_view(),
|
|
34
|
-
name="zone_managed_records",
|
|
35
|
-
),
|
|
36
|
-
path(
|
|
37
|
-
"zones/<int:pk>/rfc2317childzones/",
|
|
38
|
-
ZoneRFC2317ChildZoneListView.as_view(),
|
|
39
|
-
name="zone_rfc2317_child_zones",
|
|
40
|
-
),
|
|
41
|
-
path(
|
|
42
|
-
"zones/<int:pk>/childzones/",
|
|
43
|
-
ZoneChildZoneListView.as_view(),
|
|
44
|
-
name="zone_child_zones",
|
|
45
|
-
),
|
|
46
|
-
path(
|
|
47
|
-
"zones/<int:pk>/registration/",
|
|
48
|
-
ZoneRegistrationView.as_view(),
|
|
49
|
-
name="zone_registration",
|
|
50
|
-
),
|
|
51
|
-
path(
|
|
52
|
-
"zones/<int:pk>/journal/",
|
|
53
|
-
ObjectJournalView.as_view(),
|
|
54
|
-
name="zone_journal",
|
|
55
|
-
kwargs={"model": Zone},
|
|
56
|
-
),
|
|
57
|
-
path(
|
|
58
|
-
"zones/<int:pk>/changelog/",
|
|
59
|
-
ObjectChangeLogView.as_view(),
|
|
60
|
-
name="zone_changelog",
|
|
61
|
-
kwargs={"model": Zone},
|
|
62
|
-
),
|
|
24
|
+
path("zones/<int:pk>/", include(get_model_urls("netbox_dns", "zone"))),
|
|
63
25
|
]
|
netbox_dns/urls/zone_template.py
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
from django.urls import path
|
|
1
|
+
from django.urls import include, path
|
|
2
2
|
|
|
3
|
-
from
|
|
3
|
+
from utilities.urls import get_model_urls
|
|
4
4
|
|
|
5
|
-
from netbox_dns.models import ZoneTemplate
|
|
6
5
|
from netbox_dns.views import (
|
|
7
|
-
ZoneTemplateListView,
|
|
8
6
|
ZoneTemplateView,
|
|
9
|
-
|
|
7
|
+
ZoneTemplateListView,
|
|
10
8
|
ZoneTemplateEditView,
|
|
9
|
+
ZoneTemplateDeleteView,
|
|
11
10
|
ZoneTemplateBulkImportView,
|
|
12
11
|
ZoneTemplateBulkEditView,
|
|
13
12
|
ZoneTemplateBulkDeleteView,
|
|
14
13
|
)
|
|
15
14
|
|
|
16
15
|
zonetemplate_urlpatterns = [
|
|
16
|
+
path("zonetemplates/<int:pk>/", ZoneTemplateView.as_view(), name="zonetemplate"),
|
|
17
17
|
path("zonetemplates/", ZoneTemplateListView.as_view(), name="zonetemplate_list"),
|
|
18
18
|
path("zonetemplates/add/", ZoneTemplateEditView.as_view(), name="zonetemplate_add"),
|
|
19
|
+
path(
|
|
20
|
+
"zonetemplates/<int:pk>/edit/",
|
|
21
|
+
ZoneTemplateEditView.as_view(),
|
|
22
|
+
name="zonetemplate_edit",
|
|
23
|
+
),
|
|
24
|
+
path(
|
|
25
|
+
"zonetemplates/<int:pk>/delete/",
|
|
26
|
+
ZoneTemplateDeleteView.as_view(),
|
|
27
|
+
name="zonetemplate_delete",
|
|
28
|
+
),
|
|
19
29
|
path(
|
|
20
30
|
"zonetemplates/import/",
|
|
21
31
|
ZoneTemplateBulkImportView.as_view(),
|
|
@@ -31,27 +41,7 @@ zonetemplate_urlpatterns = [
|
|
|
31
41
|
ZoneTemplateBulkDeleteView.as_view(),
|
|
32
42
|
name="zonetemplate_bulk_delete",
|
|
33
43
|
),
|
|
34
|
-
path("zonetemplates/<int:pk>/", ZoneTemplateView.as_view(), name="zonetemplate"),
|
|
35
|
-
path(
|
|
36
|
-
"zonetemplates/<int:pk>/delete/",
|
|
37
|
-
ZoneTemplateDeleteView.as_view(),
|
|
38
|
-
name="zonetemplate_delete",
|
|
39
|
-
),
|
|
40
|
-
path(
|
|
41
|
-
"zonetemplates/<int:pk>/edit/",
|
|
42
|
-
ZoneTemplateEditView.as_view(),
|
|
43
|
-
name="zonetemplate_edit",
|
|
44
|
-
),
|
|
45
|
-
path(
|
|
46
|
-
"zonetemplates/<int:pk>/journal/",
|
|
47
|
-
ObjectJournalView.as_view(),
|
|
48
|
-
name="zonetemplate_journal",
|
|
49
|
-
kwargs={"model": ZoneTemplate},
|
|
50
|
-
),
|
|
51
44
|
path(
|
|
52
|
-
"zonetemplates/<int:pk>/
|
|
53
|
-
ObjectChangeLogView.as_view(),
|
|
54
|
-
name="zonetemplate_changelog",
|
|
55
|
-
kwargs={"model": ZoneTemplate},
|
|
45
|
+
"zonetemplates/<int:pk>/", include(get_model_urls("netbox_dns", "zonetemplate"))
|
|
56
46
|
),
|
|
57
47
|
]
|
|
@@ -10,9 +10,6 @@ from django.db.models import Q
|
|
|
10
10
|
from netbox.context import current_request
|
|
11
11
|
from ipam.models import IPAddress, Prefix
|
|
12
12
|
|
|
13
|
-
from netbox_dns.models import zone as _zone
|
|
14
|
-
from netbox_dns.models import record as _record
|
|
15
|
-
from netbox_dns.models import view as _view
|
|
16
13
|
from netbox_dns.choices import RecordStatusChoices
|
|
17
14
|
|
|
18
15
|
|
|
@@ -26,6 +23,7 @@ __all__ = (
|
|
|
26
23
|
"get_ip_addresses_by_view",
|
|
27
24
|
"get_ip_addresses_by_zone",
|
|
28
25
|
"check_record_permission",
|
|
26
|
+
"get_query_from_filter",
|
|
29
27
|
)
|
|
30
28
|
|
|
31
29
|
|
|
@@ -74,6 +72,8 @@ def _match_data(ip_address, record):
|
|
|
74
72
|
|
|
75
73
|
|
|
76
74
|
def get_zones(ip_address, view=None, old_zone=None):
|
|
75
|
+
from netbox_dns.models import Zone
|
|
76
|
+
|
|
77
77
|
if view is None:
|
|
78
78
|
views = _get_assigned_views(ip_address)
|
|
79
79
|
if not views:
|
|
@@ -88,10 +88,10 @@ def get_zones(ip_address, view=None, old_zone=None):
|
|
|
88
88
|
fqdn = dns_name.from_text(ip_address.dns_name)
|
|
89
89
|
zone_name_candidates = [
|
|
90
90
|
fqdn.split(i)[1].to_text().rstrip(".")
|
|
91
|
-
for i in range(min_labels + 1, len(fqdn.labels))
|
|
91
|
+
for i in range(min_labels + 1, len(fqdn.labels) + 1)
|
|
92
92
|
]
|
|
93
93
|
|
|
94
|
-
zones =
|
|
94
|
+
zones = Zone.objects.filter(
|
|
95
95
|
view__in=views,
|
|
96
96
|
name__in=zone_name_candidates,
|
|
97
97
|
active=True,
|
|
@@ -114,28 +114,28 @@ def get_zones(ip_address, view=None, old_zone=None):
|
|
|
114
114
|
|
|
115
115
|
|
|
116
116
|
def check_dns_records(ip_address, zone=None, view=None):
|
|
117
|
+
from netbox_dns.models import Zone, Record
|
|
118
|
+
|
|
117
119
|
if ip_address.dns_name == "":
|
|
118
120
|
return
|
|
119
121
|
|
|
120
122
|
if zone is None:
|
|
121
123
|
zones = get_zones(ip_address, view=view)
|
|
122
124
|
|
|
123
|
-
if ip_address.
|
|
125
|
+
if not ip_address._state.adding:
|
|
124
126
|
for record in ip_address.netbox_dns_records.filter(zone__in=zones):
|
|
125
127
|
if not _match_data(ip_address, record):
|
|
126
|
-
record.update_from_ip_address(ip_address)
|
|
128
|
+
updated = record.update_from_ip_address(ip_address)
|
|
127
129
|
|
|
128
|
-
if
|
|
130
|
+
if updated:
|
|
129
131
|
record.clean()
|
|
130
132
|
|
|
131
|
-
zones =
|
|
132
|
-
pk__in=[zone.pk for zone in zones]
|
|
133
|
-
).exclude(
|
|
133
|
+
zones = Zone.objects.filter(pk__in=[zone.pk for zone in zones]).exclude(
|
|
134
134
|
pk__in=set(ip_address.netbox_dns_records.values_list("zone", flat=True))
|
|
135
135
|
)
|
|
136
136
|
|
|
137
137
|
for zone in zones:
|
|
138
|
-
record =
|
|
138
|
+
record = Record.create_from_ip_address(
|
|
139
139
|
ip_address,
|
|
140
140
|
zone,
|
|
141
141
|
)
|
|
@@ -143,7 +143,7 @@ def check_dns_records(ip_address, zone=None, view=None):
|
|
|
143
143
|
if record is not None:
|
|
144
144
|
record.clean()
|
|
145
145
|
|
|
146
|
-
if ip_address.
|
|
146
|
+
if ip_address._state.adding:
|
|
147
147
|
return
|
|
148
148
|
|
|
149
149
|
try:
|
|
@@ -152,21 +152,28 @@ def check_dns_records(ip_address, zone=None, view=None):
|
|
|
152
152
|
return
|
|
153
153
|
|
|
154
154
|
for record in ip_address.netbox_dns_records.filter(zone=zone):
|
|
155
|
-
record.update_from_ip_address(ip_address, new_zone)
|
|
155
|
+
updated = record.update_from_ip_address(ip_address, new_zone)
|
|
156
156
|
|
|
157
|
-
if
|
|
157
|
+
if updated:
|
|
158
158
|
record.clean(new_zone=new_zone)
|
|
159
159
|
|
|
160
160
|
|
|
161
|
-
def update_dns_records(ip_address):
|
|
161
|
+
def update_dns_records(ip_address, view=None):
|
|
162
|
+
from netbox_dns.models import Zone, Record
|
|
163
|
+
|
|
162
164
|
if ip_address.dns_name == "":
|
|
163
165
|
delete_dns_records(ip_address)
|
|
164
166
|
return
|
|
165
167
|
|
|
166
|
-
zones = get_zones(ip_address)
|
|
168
|
+
zones = get_zones(ip_address, view=view)
|
|
167
169
|
|
|
168
|
-
if ip_address.
|
|
169
|
-
|
|
170
|
+
if not ip_address._state.adding:
|
|
171
|
+
if view is None:
|
|
172
|
+
address_records = ip_address.netbox_dns_records.all()
|
|
173
|
+
else:
|
|
174
|
+
address_records = ip_address.netbox_dns_records.filter(zone__view=view)
|
|
175
|
+
|
|
176
|
+
for record in address_records:
|
|
170
177
|
if record.zone not in zones or ip_address.custom_field_data.get(
|
|
171
178
|
"ipaddress_dns_disabled"
|
|
172
179
|
):
|
|
@@ -175,19 +182,21 @@ def update_dns_records(ip_address):
|
|
|
175
182
|
|
|
176
183
|
record.update_fqdn()
|
|
177
184
|
if not _match_data(ip_address, record):
|
|
178
|
-
record.update_from_ip_address(ip_address)
|
|
185
|
+
updated, deleted = record.update_from_ip_address(ip_address)
|
|
179
186
|
|
|
180
|
-
if
|
|
187
|
+
if deleted:
|
|
188
|
+
record.delete()
|
|
189
|
+
elif updated:
|
|
181
190
|
record.save()
|
|
182
191
|
|
|
183
|
-
zones =
|
|
192
|
+
zones = Zone.objects.filter(pk__in=[zone.pk for zone in zones]).exclude(
|
|
184
193
|
pk__in=set(
|
|
185
194
|
ip_address.netbox_dns_records.all().values_list("zone", flat=True)
|
|
186
195
|
)
|
|
187
196
|
)
|
|
188
197
|
|
|
189
198
|
for zone in zones:
|
|
190
|
-
record =
|
|
199
|
+
record = Record.create_from_ip_address(
|
|
191
200
|
ip_address,
|
|
192
201
|
zone,
|
|
193
202
|
)
|
|
@@ -196,19 +205,27 @@ def update_dns_records(ip_address):
|
|
|
196
205
|
record.save()
|
|
197
206
|
|
|
198
207
|
|
|
199
|
-
def delete_dns_records(ip_address):
|
|
200
|
-
|
|
208
|
+
def delete_dns_records(ip_address, view=None):
|
|
209
|
+
|
|
210
|
+
if view is None:
|
|
211
|
+
address_records = ip_address.netbox_dns_records.all()
|
|
212
|
+
else:
|
|
213
|
+
address_records = ip_address.netbox_dns_records.filter(zone__view=view)
|
|
214
|
+
|
|
215
|
+
for record in address_records:
|
|
201
216
|
record.delete()
|
|
202
217
|
|
|
203
218
|
|
|
204
219
|
def get_views_by_prefix(prefix):
|
|
220
|
+
from netbox_dns.models import View
|
|
221
|
+
|
|
205
222
|
if (views := prefix.netbox_dns_views.all()).exists():
|
|
206
223
|
return views
|
|
207
224
|
|
|
208
225
|
if (parent := prefix.get_parents().filter(netbox_dns_views__isnull=False)).exists():
|
|
209
226
|
return parent.last().netbox_dns_views.all()
|
|
210
227
|
|
|
211
|
-
return
|
|
228
|
+
return View.objects.none()
|
|
212
229
|
|
|
213
230
|
|
|
214
231
|
def get_ip_addresses_by_prefix(prefix, check_view=True):
|
|
@@ -293,3 +310,18 @@ def check_record_permission(add=True, change=True, delete=True):
|
|
|
293
310
|
if check
|
|
294
311
|
)
|
|
295
312
|
)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def get_query_from_filter(ip_address_filter):
|
|
316
|
+
query = Q()
|
|
317
|
+
|
|
318
|
+
if not isinstance(ip_address_filter, list):
|
|
319
|
+
ip_address_filter = [ip_address_filter]
|
|
320
|
+
|
|
321
|
+
for condition in ip_address_filter:
|
|
322
|
+
if condition:
|
|
323
|
+
query |= Q(**condition)
|
|
324
|
+
else:
|
|
325
|
+
return Q()
|
|
326
|
+
|
|
327
|
+
return query
|
netbox_dns/views/__init__.py
CHANGED
netbox_dns/views/nameserver.py
CHANGED
|
@@ -2,6 +2,7 @@ from dns import name as dns_name
|
|
|
2
2
|
|
|
3
3
|
from netbox.views import generic
|
|
4
4
|
from utilities.views import ViewTab, register_model_view
|
|
5
|
+
from tenancy.views import ObjectContactsView
|
|
5
6
|
|
|
6
7
|
from netbox_dns.filtersets import NameServerFilterSet, ZoneFilterSet
|
|
7
8
|
from netbox_dns.forms import (
|
|
@@ -15,15 +16,13 @@ from netbox_dns.tables import NameServerTable, ZoneTable
|
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
__all__ = (
|
|
18
|
-
"NameServerListView",
|
|
19
19
|
"NameServerView",
|
|
20
|
+
"NameServerListView",
|
|
20
21
|
"NameServerEditView",
|
|
21
22
|
"NameServerDeleteView",
|
|
22
23
|
"NameServerBulkEditView",
|
|
23
24
|
"NameServerBulkImportView",
|
|
24
25
|
"NameServerBulkDeleteView",
|
|
25
|
-
"NameServerZoneListView",
|
|
26
|
-
"NameServerSOAZoneListView",
|
|
27
26
|
)
|
|
28
27
|
|
|
29
28
|
|
|
@@ -77,6 +76,11 @@ class NameServerBulkDeleteView(generic.BulkDeleteView):
|
|
|
77
76
|
table = NameServerTable
|
|
78
77
|
|
|
79
78
|
|
|
79
|
+
@register_model_view(NameServer, "contacts")
|
|
80
|
+
class NameServerContactsView(ObjectContactsView):
|
|
81
|
+
queryset = NameServer.objects.all()
|
|
82
|
+
|
|
83
|
+
|
|
80
84
|
@register_model_view(NameServer, "zones")
|
|
81
85
|
class NameServerZoneListView(generic.ObjectChildrenView):
|
|
82
86
|
queryset = NameServer.objects.all().prefetch_related("zones")
|
netbox_dns/views/record.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
from dns import name as dns_name
|
|
2
2
|
|
|
3
3
|
from netbox.views import generic
|
|
4
|
+
from utilities.views import register_model_view
|
|
5
|
+
from tenancy.views import ObjectContactsView
|
|
4
6
|
|
|
5
7
|
from netbox_dns.filtersets import RecordFilterSet
|
|
6
8
|
from netbox_dns.forms import (
|
|
@@ -16,14 +18,14 @@ from netbox_dns.utilities import value_to_unicode
|
|
|
16
18
|
|
|
17
19
|
|
|
18
20
|
__all__ = (
|
|
19
|
-
"RecordListView",
|
|
20
|
-
"ManagedRecordListView",
|
|
21
21
|
"RecordView",
|
|
22
|
+
"RecordListView",
|
|
22
23
|
"RecordEditView",
|
|
23
24
|
"RecordDeleteView",
|
|
24
25
|
"RecordBulkImportView",
|
|
25
26
|
"RecordBulkEditView",
|
|
26
27
|
"RecordBulkDeleteView",
|
|
28
|
+
"ManagedRecordListView",
|
|
27
29
|
)
|
|
28
30
|
|
|
29
31
|
|
|
@@ -37,7 +39,9 @@ class RecordListView(generic.ObjectListView):
|
|
|
37
39
|
|
|
38
40
|
|
|
39
41
|
class ManagedRecordListView(generic.ObjectListView):
|
|
40
|
-
queryset = Record.objects.prefetch_related(
|
|
42
|
+
queryset = Record.objects.filter(managed=True).prefetch_related(
|
|
43
|
+
"ipam_ip_address", "address_record"
|
|
44
|
+
)
|
|
41
45
|
filterset = RecordFilterSet
|
|
42
46
|
filterset_form = RecordFilterForm
|
|
43
47
|
table = ManagedRecordTable
|
|
@@ -153,3 +157,8 @@ class RecordBulkEditView(generic.BulkEditView):
|
|
|
153
157
|
class RecordBulkDeleteView(generic.BulkDeleteView):
|
|
154
158
|
queryset = Record.objects.filter(managed=False)
|
|
155
159
|
table = RecordTable
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@register_model_view(Record, "contacts")
|
|
163
|
+
class RecordContactsView(ObjectContactsView):
|
|
164
|
+
queryset = Record.objects.all()
|
netbox_dns/views/registrar.py
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
from django.db.models import Q
|
|
2
|
+
|
|
3
|
+
from netbox.views import generic
|
|
4
|
+
|
|
5
|
+
from utilities.views import ViewTab, register_model_view
|
|
6
|
+
|
|
7
|
+
from netbox_dns.models import RegistrationContact, Zone
|
|
8
|
+
from netbox_dns.filtersets import RegistrationContactFilterSet, ZoneFilterSet
|
|
9
|
+
from netbox_dns.forms import (
|
|
10
|
+
RegistrationContactForm,
|
|
11
|
+
RegistrationContactFilterForm,
|
|
12
|
+
RegistrationContactImportForm,
|
|
13
|
+
RegistrationContactBulkEditForm,
|
|
14
|
+
)
|
|
15
|
+
from netbox_dns.tables import RegistrationContactTable, ZoneTable
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
__all__ = (
|
|
19
|
+
"RegistrationContactView",
|
|
20
|
+
"RegistrationContactEditView",
|
|
21
|
+
"RegistrationContactListView",
|
|
22
|
+
"RegistrationContactDeleteView",
|
|
23
|
+
"RegistrationContactBulkImportView",
|
|
24
|
+
"RegistrationContactBulkEditView",
|
|
25
|
+
"RegistrationContactBulkDeleteView",
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class RegistrationContactView(generic.ObjectView):
|
|
30
|
+
queryset = RegistrationContact.objects.all()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class RegistrationContactListView(generic.ObjectListView):
|
|
34
|
+
queryset = RegistrationContact.objects.all()
|
|
35
|
+
table = RegistrationContactTable
|
|
36
|
+
filterset = RegistrationContactFilterSet
|
|
37
|
+
filterset_form = RegistrationContactFilterForm
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class RegistrationContactEditView(generic.ObjectEditView):
|
|
41
|
+
queryset = RegistrationContact.objects.all()
|
|
42
|
+
form = RegistrationContactForm
|
|
43
|
+
default_return_url = "plugins:netbox_dns:registrationcontact_list"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class RegistrationContactDeleteView(generic.ObjectDeleteView):
|
|
47
|
+
queryset = RegistrationContact.objects.all()
|
|
48
|
+
default_return_url = "plugins:netbox_dns:registrationcontact_list"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class RegistrationContactBulkImportView(generic.BulkImportView):
|
|
52
|
+
queryset = RegistrationContact.objects.all()
|
|
53
|
+
model_form = RegistrationContactImportForm
|
|
54
|
+
table = RegistrationContactTable
|
|
55
|
+
default_return_url = "plugins:netbox_dns:registrationcontact_list"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class RegistrationContactBulkEditView(generic.BulkEditView):
|
|
59
|
+
queryset = RegistrationContact.objects.all()
|
|
60
|
+
filterset = RegistrationContactFilterSet
|
|
61
|
+
table = RegistrationContactTable
|
|
62
|
+
form = RegistrationContactBulkEditForm
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class RegistrationContactBulkDeleteView(generic.BulkDeleteView):
|
|
66
|
+
queryset = RegistrationContact.objects.all()
|
|
67
|
+
table = RegistrationContactTable
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@register_model_view(RegistrationContact, "zones")
|
|
71
|
+
class RegistrationContactZoneListView(generic.ObjectChildrenView):
|
|
72
|
+
queryset = RegistrationContact.objects.all().prefetch_related(
|
|
73
|
+
"zone_set", "admin_c_zones", "tech_c_zones", "billing_c_zones"
|
|
74
|
+
)
|
|
75
|
+
child_model = Zone
|
|
76
|
+
table = ZoneTable
|
|
77
|
+
filterset = ZoneFilterSet
|
|
78
|
+
template_name = "netbox_dns/zone/child.html"
|
|
79
|
+
hide_if_empty = True
|
|
80
|
+
|
|
81
|
+
tab = ViewTab(
|
|
82
|
+
label="Zones",
|
|
83
|
+
permission="netbox_dns.view_zone",
|
|
84
|
+
badge=lambda obj: len(obj.zones),
|
|
85
|
+
hide_if_empty=True,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
def get_children(self, request, parent):
|
|
89
|
+
return Zone.objects.filter(
|
|
90
|
+
Q(registrant=parent)
|
|
91
|
+
| Q(admin_c=parent)
|
|
92
|
+
| Q(tech_c=parent)
|
|
93
|
+
| Q(billing_c=parent)
|
|
94
|
+
)
|
netbox_dns/views/view.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from utilities.views import ViewTab, register_model_view
|
|
2
2
|
|
|
3
3
|
from netbox.views import generic
|
|
4
|
+
from tenancy.views import ObjectContactsView
|
|
4
5
|
from ipam.models import Prefix
|
|
5
6
|
|
|
6
7
|
from netbox_dns.models import View, Zone
|
|
@@ -24,7 +25,6 @@ __all__ = (
|
|
|
24
25
|
"ViewBulkImportView",
|
|
25
26
|
"ViewBulkEditView",
|
|
26
27
|
"ViewBulkDeleteView",
|
|
27
|
-
"ViewZoneListView",
|
|
28
28
|
"ViewPrefixEditView",
|
|
29
29
|
)
|
|
30
30
|
|
|
@@ -104,3 +104,8 @@ class ViewZoneListView(generic.ObjectChildrenView):
|
|
|
104
104
|
|
|
105
105
|
def get_children(self, request, parent):
|
|
106
106
|
return parent.zone_set
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@register_model_view(View, "contacts")
|
|
110
|
+
class ViewContactsView(ObjectContactsView):
|
|
111
|
+
queryset = View.objects.all()
|