netbox-plugin-dns 1.0.6__py3-none-any.whl → 1.1.0__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 +23 -4
- netbox_dns/api/nested_serializers.py +17 -16
- netbox_dns/api/serializers.py +2 -1
- netbox_dns/api/serializers_/prefix.py +18 -0
- 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 +34 -2
- netbox_dns/api/serializers_/zone.py +5 -5
- netbox_dns/api/serializers_/zone_template.py +5 -5
- netbox_dns/api/urls.py +5 -2
- netbox_dns/api/views.py +17 -35
- netbox_dns/fields/__init__.py +1 -0
- netbox_dns/fields/ipam.py +15 -0
- netbox_dns/filtersets/__init__.py +1 -1
- netbox_dns/filtersets/record.py +1 -1
- netbox_dns/filtersets/{contact.py → registration_contact.py} +4 -4
- netbox_dns/filtersets/view.py +16 -0
- 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/{contact.py → registration_contact.py} +16 -16
- netbox_dns/forms/view.py +204 -4
- netbox_dns/forms/zone.py +15 -18
- 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 +24 -44
- netbox_dns/graphql/types.py +41 -12
- netbox_dns/management/commands/rebuild_dnssync.py +18 -0
- netbox_dns/management/commands/setup_dnssync.py +140 -0
- netbox_dns/migrations/0007_alter_ordering_options.py +25 -0
- netbox_dns/migrations/0008_view_prefixes.py +18 -0
- netbox_dns/migrations/0009_rename_contact_registrationcontact.py +27 -0
- netbox_dns/models/__init__.py +1 -3
- netbox_dns/models/nameserver.py +8 -3
- netbox_dns/models/record.py +154 -24
- 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 +14 -2
- netbox_dns/models/zone.py +76 -35
- netbox_dns/models/zone_template.py +12 -9
- netbox_dns/navigation.py +7 -7
- netbox_dns/signals/ipam_dnssync.py +224 -0
- netbox_dns/tables/__init__.py +1 -1
- netbox_dns/tables/ipam_dnssync.py +11 -0
- netbox_dns/tables/nameserver.py +1 -7
- netbox_dns/tables/record.py +43 -30
- 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 +19 -4
- netbox_dns/tables/zone.py +0 -15
- netbox_dns/tables/zone_template.py +2 -16
- netbox_dns/template_content.py +41 -40
- netbox_dns/templates/netbox_dns/record.html +6 -6
- netbox_dns/templates/netbox_dns/{contact.html → registrationcontact.html} +1 -1
- netbox_dns/templates/netbox_dns/view/button.html +9 -0
- netbox_dns/templates/netbox_dns/view/prefix.html +41 -0
- netbox_dns/templates/netbox_dns/view/related.html +17 -0
- netbox_dns/templates/netbox_dns/view.html +25 -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 +12 -20
- netbox_dns/urls/zone.py +8 -46
- netbox_dns/urls/zone_template.py +16 -26
- netbox_dns/utilities/__init__.py +2 -74
- netbox_dns/utilities/conversions.py +83 -0
- netbox_dns/utilities/ipam_dnssync.py +295 -0
- netbox_dns/validators/dns_name.py +9 -0
- netbox_dns/views/__init__.py +1 -1
- netbox_dns/views/nameserver.py +7 -3
- netbox_dns/views/record.py +12 -7
- 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 +32 -2
- netbox_dns/views/zone.py +7 -6
- netbox_dns/views/zone_template.py +2 -2
- {netbox_plugin_dns-1.0.6.dist-info → netbox_plugin_dns-1.1.0.dist-info}/METADATA +2 -1
- netbox_plugin_dns-1.1.0.dist-info/RECORD +146 -0
- netbox_dns/management/commands/setup_coupling.py +0 -109
- netbox_dns/signals/ipam_coupling.py +0 -168
- netbox_dns/templates/netbox_dns/related_dns_objects.html +0 -21
- netbox_dns/urls/contact.py +0 -51
- netbox_dns/utilities/ipam_coupling.py +0 -112
- netbox_dns/views/contact.py +0 -95
- netbox_plugin_dns-1.0.6.dist-info/RECORD +0 -136
- {netbox_plugin_dns-1.0.6.dist-info → netbox_plugin_dns-1.1.0.dist-info}/LICENSE +0 -0
- {netbox_plugin_dns-1.0.6.dist-info → netbox_plugin_dns-1.1.0.dist-info}/WHEEL +0 -0
|
@@ -47,7 +47,7 @@ class ZoneTemplate(NetBoxModel):
|
|
|
47
47
|
null=True,
|
|
48
48
|
)
|
|
49
49
|
registrant = models.ForeignKey(
|
|
50
|
-
to="
|
|
50
|
+
to="RegistrationContact",
|
|
51
51
|
on_delete=models.SET_NULL,
|
|
52
52
|
related_name="+",
|
|
53
53
|
help_text="The owner of the domain",
|
|
@@ -55,7 +55,7 @@ class ZoneTemplate(NetBoxModel):
|
|
|
55
55
|
null=True,
|
|
56
56
|
)
|
|
57
57
|
admin_c = models.ForeignKey(
|
|
58
|
-
to="
|
|
58
|
+
to="RegistrationContact",
|
|
59
59
|
on_delete=models.SET_NULL,
|
|
60
60
|
verbose_name="Admin contact",
|
|
61
61
|
related_name="+",
|
|
@@ -64,7 +64,7 @@ class ZoneTemplate(NetBoxModel):
|
|
|
64
64
|
null=True,
|
|
65
65
|
)
|
|
66
66
|
tech_c = models.ForeignKey(
|
|
67
|
-
to="
|
|
67
|
+
to="RegistrationContact",
|
|
68
68
|
on_delete=models.SET_NULL,
|
|
69
69
|
verbose_name="Tech contact",
|
|
70
70
|
related_name="+",
|
|
@@ -73,7 +73,7 @@ class ZoneTemplate(NetBoxModel):
|
|
|
73
73
|
null=True,
|
|
74
74
|
)
|
|
75
75
|
billing_c = models.ForeignKey(
|
|
76
|
-
to="
|
|
76
|
+
to="RegistrationContact",
|
|
77
77
|
on_delete=models.SET_NULL,
|
|
78
78
|
verbose_name="Billing contact",
|
|
79
79
|
related_name="+",
|
|
@@ -82,7 +82,7 @@ class ZoneTemplate(NetBoxModel):
|
|
|
82
82
|
null=True,
|
|
83
83
|
)
|
|
84
84
|
|
|
85
|
-
clone_fields =
|
|
85
|
+
clone_fields = (
|
|
86
86
|
"description",
|
|
87
87
|
"nameservers",
|
|
88
88
|
"record_templates",
|
|
@@ -92,19 +92,22 @@ class ZoneTemplate(NetBoxModel):
|
|
|
92
92
|
"admin_c",
|
|
93
93
|
"tech_c",
|
|
94
94
|
"billing_c",
|
|
95
|
-
|
|
95
|
+
)
|
|
96
96
|
|
|
97
|
-
template_fields =
|
|
97
|
+
template_fields = (
|
|
98
98
|
"tenant",
|
|
99
99
|
"registrar",
|
|
100
100
|
"registrant",
|
|
101
101
|
"admin_c",
|
|
102
102
|
"tech_c",
|
|
103
103
|
"billing_c",
|
|
104
|
-
|
|
104
|
+
)
|
|
105
105
|
|
|
106
106
|
class Meta:
|
|
107
|
-
|
|
107
|
+
verbose_name = "Zone Template"
|
|
108
|
+
verbose_name_plural = "Zone Templates"
|
|
109
|
+
|
|
110
|
+
ordering = ("name",)
|
|
108
111
|
|
|
109
112
|
def __str__(self):
|
|
110
113
|
return str(self.name)
|
netbox_dns/navigation.py
CHANGED
|
@@ -151,21 +151,21 @@ registrar_menu_item = PluginMenuItem(
|
|
|
151
151
|
)
|
|
152
152
|
|
|
153
153
|
contact_menu_item = PluginMenuItem(
|
|
154
|
-
link="plugins:netbox_dns:
|
|
155
|
-
link_text="Contacts",
|
|
156
|
-
permissions=["netbox_dns.
|
|
154
|
+
link="plugins:netbox_dns:registrationcontact_list",
|
|
155
|
+
link_text="Registration Contacts",
|
|
156
|
+
permissions=["netbox_dns.view_registrationcontact"],
|
|
157
157
|
buttons=(
|
|
158
158
|
PluginMenuButton(
|
|
159
|
-
"plugins:netbox_dns:
|
|
159
|
+
"plugins:netbox_dns:registrationcontact_add",
|
|
160
160
|
"Add",
|
|
161
161
|
"mdi mdi-plus-thick",
|
|
162
|
-
permissions=["netbox_dns.
|
|
162
|
+
permissions=["netbox_dns.add_registrationcontact"],
|
|
163
163
|
),
|
|
164
164
|
PluginMenuButton(
|
|
165
|
-
"plugins:netbox_dns:
|
|
165
|
+
"plugins:netbox_dns:registrationcontact_import",
|
|
166
166
|
"Import",
|
|
167
167
|
"mdi mdi-upload",
|
|
168
|
-
permissions=["netbox_dns.
|
|
168
|
+
permissions=["netbox_dns.add_registrationcontact"],
|
|
169
169
|
),
|
|
170
170
|
),
|
|
171
171
|
)
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
from netaddr import IPNetwork
|
|
2
|
+
|
|
3
|
+
from django.conf import settings
|
|
4
|
+
from django.dispatch import receiver
|
|
5
|
+
from django.db.models.signals import pre_delete, pre_save, post_save, m2m_changed
|
|
6
|
+
from django.core.exceptions import ValidationError
|
|
7
|
+
|
|
8
|
+
from netbox.context import current_request
|
|
9
|
+
from netbox.signals import post_clean
|
|
10
|
+
from ipam.models import IPAddress, Prefix
|
|
11
|
+
from utilities.exceptions import AbortRequest
|
|
12
|
+
|
|
13
|
+
from netbox_dns.models import view as _view
|
|
14
|
+
from netbox_dns.utilities import (
|
|
15
|
+
check_dns_records,
|
|
16
|
+
check_record_permission,
|
|
17
|
+
update_dns_records,
|
|
18
|
+
delete_dns_records,
|
|
19
|
+
get_views_by_prefix,
|
|
20
|
+
get_ip_addresses_by_prefix,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
DNSSYNC_CUSTOM_FIELDS = {
|
|
24
|
+
"ipaddress_dns_disabled": False,
|
|
25
|
+
"ipaddress_dns_record_ttl": None,
|
|
26
|
+
"ipaddress_dns_record_disable_ptr": False,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
IPADDRESS_ACTIVE_STATUS = settings.PLUGINS_CONFIG["netbox_dns"][
|
|
30
|
+
"dnssync_ipaddress_active_status"
|
|
31
|
+
]
|
|
32
|
+
ENFORCE_UNIQUE_RECORDS = settings.PLUGINS_CONFIG["netbox_dns"]["enforce_unique_records"]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@receiver(post_clean, sender=IPAddress)
|
|
36
|
+
def ipam_dnssync_ipaddress_post_clean(instance, **kwargs):
|
|
37
|
+
if not isinstance(instance.address, IPNetwork):
|
|
38
|
+
return
|
|
39
|
+
|
|
40
|
+
if instance.custom_field_data.get("ipaddress_dns_disabled"):
|
|
41
|
+
return
|
|
42
|
+
|
|
43
|
+
# +
|
|
44
|
+
# Check for uniqueness of IP address and dns_name. If unique records are
|
|
45
|
+
# enforced, report an error when trying to create the same IP address with
|
|
46
|
+
# the same dns_name. Ignore existing IP addresses that have their CF
|
|
47
|
+
# "ipaddress_dns_disabled" set to "True".
|
|
48
|
+
# -
|
|
49
|
+
duplicate_addresses = IPAddress.objects.filter(
|
|
50
|
+
address=instance.address,
|
|
51
|
+
vrf=instance.vrf,
|
|
52
|
+
dns_name=instance.dns_name,
|
|
53
|
+
status__in=IPADDRESS_ACTIVE_STATUS,
|
|
54
|
+
)
|
|
55
|
+
if instance.pk is not None:
|
|
56
|
+
duplicate_addresses = duplicate_addresses.exclude(pk=instance.pk)
|
|
57
|
+
|
|
58
|
+
if ENFORCE_UNIQUE_RECORDS and instance.status in IPADDRESS_ACTIVE_STATUS:
|
|
59
|
+
for ip_address in duplicate_addresses.only("custom_field_data"):
|
|
60
|
+
if not ip_address.custom_field_data.get("ipaddress_dns_disabled"):
|
|
61
|
+
raise ValidationError(
|
|
62
|
+
{
|
|
63
|
+
"dns_name": "Unique DNS records are enforced and there is already "
|
|
64
|
+
f"an active IP address {instance.address} with DNS name {instance.dns_name}. "
|
|
65
|
+
"Plesase choose a different name or disable record creation for this "
|
|
66
|
+
"IP address."
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# +
|
|
71
|
+
# Check NetBox DNS record permission for changes to IPAddress custom fields
|
|
72
|
+
#
|
|
73
|
+
# Normally, as the modfication of DNS fields
|
|
74
|
+
if (request := current_request.get()) is not None:
|
|
75
|
+
cf_data = instance.custom_field_data
|
|
76
|
+
if (
|
|
77
|
+
instance.pk is not None
|
|
78
|
+
and any(
|
|
79
|
+
(
|
|
80
|
+
cf_data.get(cf, cf_default)
|
|
81
|
+
!= IPAddress.objects.get(pk=instance.pk).custom_field_data.get(
|
|
82
|
+
cf, cf_default
|
|
83
|
+
)
|
|
84
|
+
for cf, cf_default in DNSSYNC_CUSTOM_FIELDS.items()
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
and not check_record_permission()
|
|
88
|
+
) or (
|
|
89
|
+
instance.pk is None
|
|
90
|
+
and any(
|
|
91
|
+
(
|
|
92
|
+
cf_data.get(cf, cf_default) != cf_default
|
|
93
|
+
for cf, cf_default in DNSSYNC_CUSTOM_FIELDS.items()
|
|
94
|
+
)
|
|
95
|
+
)
|
|
96
|
+
and not check_record_permission(change=False, delete=False)
|
|
97
|
+
):
|
|
98
|
+
raise ValidationError(
|
|
99
|
+
f"User '{request.user}' is not allowed to alter DNSsync custom fields"
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
try:
|
|
103
|
+
check_dns_records(instance)
|
|
104
|
+
except ValidationError as exc:
|
|
105
|
+
raise ValidationError({"dns_name": exc.messages})
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@receiver(pre_delete, sender=IPAddress)
|
|
109
|
+
def ipam_dnssync_ipaddress_pre_delete(instance, **kwargs):
|
|
110
|
+
delete_dns_records(instance)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@receiver(pre_save, sender=IPAddress)
|
|
114
|
+
def ipam_dnssync_ipaddress_pre_save(instance, **kwargs):
|
|
115
|
+
check_dns_records(instance)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@receiver(post_save, sender=IPAddress)
|
|
119
|
+
def ipam_dnssync_ipaddress_post_save(instance, **kwargs):
|
|
120
|
+
update_dns_records(instance)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@receiver(pre_save, sender=Prefix)
|
|
124
|
+
def ipam_dnssync_prefix_pre_save(instance, **kwargs):
|
|
125
|
+
"""
|
|
126
|
+
Changes that modify the prefix hierarchy cannot be validated properly before
|
|
127
|
+
commiting them. So the solution in this case is to ask the user to deassign
|
|
128
|
+
the prefix from any views it is assigned to and retry.
|
|
129
|
+
"""
|
|
130
|
+
request = current_request.get()
|
|
131
|
+
|
|
132
|
+
if instance.pk is None or not instance.netbox_dns_views.exists():
|
|
133
|
+
return
|
|
134
|
+
|
|
135
|
+
saved_prefix = Prefix.objects.prefetch_related("netbox_dns_views").get(
|
|
136
|
+
pk=instance.pk
|
|
137
|
+
)
|
|
138
|
+
if saved_prefix.prefix != instance.prefix or saved_prefix.vrf != instance.vrf:
|
|
139
|
+
dns_views = ", ".join([view.name for view in instance.netbox_dns_views.all()])
|
|
140
|
+
if request is not None:
|
|
141
|
+
raise AbortRequest(
|
|
142
|
+
f"This prefix is currently assigned to the following DNS views: {dns_views}"
|
|
143
|
+
f"Please deassign it from these views before making changes to the prefix "
|
|
144
|
+
f"or VRF."
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
raise ValidationError(
|
|
148
|
+
f"Prefix is assigned to DNS views {dns_views}. Prefix and VRF must not be changed"
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@receiver(pre_delete, sender=Prefix)
|
|
153
|
+
def ipam_dnssync_prefix_pre_delete(instance, **kwargs):
|
|
154
|
+
parent = instance.get_parents().last()
|
|
155
|
+
request = current_request.get()
|
|
156
|
+
|
|
157
|
+
if parent is not None and get_views_by_prefix(instance) != get_views_by_prefix(
|
|
158
|
+
parent
|
|
159
|
+
):
|
|
160
|
+
try:
|
|
161
|
+
for prefix in instance.get_children().filter(
|
|
162
|
+
_depth=instance.depth + 1, netbox_dns_views__isnull=True
|
|
163
|
+
):
|
|
164
|
+
for ip_address in get_ip_addresses_by_prefix(prefix):
|
|
165
|
+
check_dns_records(ip_address)
|
|
166
|
+
except ValidationError as exc:
|
|
167
|
+
if request is not None:
|
|
168
|
+
raise AbortRequest(
|
|
169
|
+
f"Prefix deletion would cause DNS errors: {exc.messages[0]} "
|
|
170
|
+
"Please review DNS View assignments for this and the parent prefix"
|
|
171
|
+
)
|
|
172
|
+
else:
|
|
173
|
+
raise exc
|
|
174
|
+
|
|
175
|
+
# +
|
|
176
|
+
# CAUTION: This only works because the NetBox workaround for an ancient
|
|
177
|
+
# Django bug (see https://code.djangoproject.com/ticket/17688) has already
|
|
178
|
+
# removed the relations between the prefix and the views when this signal
|
|
179
|
+
# handler runs.
|
|
180
|
+
#
|
|
181
|
+
# Should anything be fixed, this code will stop working and need to be
|
|
182
|
+
# revisited.
|
|
183
|
+
#
|
|
184
|
+
# The NetBox workaround only works for requests, not for model level
|
|
185
|
+
# operations. The following code replicates it for non-requests.
|
|
186
|
+
# -
|
|
187
|
+
if request is None:
|
|
188
|
+
for view in instance.netbox_dns_views.all():
|
|
189
|
+
view.snapshot()
|
|
190
|
+
view.prefixes.remove(instance)
|
|
191
|
+
|
|
192
|
+
for ip_address in get_ip_addresses_by_prefix(instance):
|
|
193
|
+
update_dns_records(ip_address)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
@receiver(m2m_changed, sender=_view.View.prefixes.through)
|
|
197
|
+
def ipam_dnssync_view_prefix_changed(**kwargs):
|
|
198
|
+
action = kwargs.get("action")
|
|
199
|
+
request = current_request.get()
|
|
200
|
+
|
|
201
|
+
# +
|
|
202
|
+
# Handle all post_add and post_remove signals except the ones directly
|
|
203
|
+
# handled by the pre_delete handler for the Prefix model.
|
|
204
|
+
#
|
|
205
|
+
# Yes. This IS ugly.
|
|
206
|
+
# -
|
|
207
|
+
if action not in ("post_add", "post_remove") or (
|
|
208
|
+
request is not None
|
|
209
|
+
and action == "post_remove"
|
|
210
|
+
and (
|
|
211
|
+
request.path.startswith("/ipam/prefixes/")
|
|
212
|
+
or request.path.startswith("/api/ipam/prefixes/")
|
|
213
|
+
)
|
|
214
|
+
):
|
|
215
|
+
return
|
|
216
|
+
|
|
217
|
+
check_view = action != "post_remove"
|
|
218
|
+
|
|
219
|
+
ip_addresses = IPAddress.objects.none()
|
|
220
|
+
for prefix in Prefix.objects.filter(pk__in=kwargs.get("pk_set")):
|
|
221
|
+
ip_addresses |= get_ip_addresses_by_prefix(prefix, check_view=check_view)
|
|
222
|
+
|
|
223
|
+
for ip_address in ip_addresses.distinct():
|
|
224
|
+
update_dns_records(ip_address)
|
netbox_dns/tables/__init__.py
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import django_tables2 as tables
|
|
2
|
+
|
|
3
|
+
from ipam.tables import PrefixTable
|
|
4
|
+
from utilities.tables import register_table_column
|
|
5
|
+
|
|
6
|
+
views = tables.ManyToManyColumn(
|
|
7
|
+
verbose_name="DNS Views",
|
|
8
|
+
linkify_item=True,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
register_table_column(views, "netbox_dns_views", PrefixTable)
|
netbox_dns/tables/nameserver.py
CHANGED
|
@@ -22,13 +22,7 @@ class NameServerTable(TenancyColumnsMixin, NetBoxTable):
|
|
|
22
22
|
|
|
23
23
|
class Meta(NetBoxTable.Meta):
|
|
24
24
|
model = NameServer
|
|
25
|
-
fields = (
|
|
26
|
-
"name",
|
|
27
|
-
"description",
|
|
28
|
-
"tags",
|
|
29
|
-
"tenant",
|
|
30
|
-
"tenant_group",
|
|
31
|
-
)
|
|
25
|
+
fields = ("description",)
|
|
32
26
|
default_columns = (
|
|
33
27
|
"name",
|
|
34
28
|
"tags",
|
netbox_dns/tables/record.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import django_tables2 as tables
|
|
2
|
+
from django.utils.html import format_html
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
from netbox.tables import (
|
|
4
6
|
NetBoxTable,
|
|
@@ -11,6 +13,10 @@ from tenancy.tables import TenancyColumnsMixin
|
|
|
11
13
|
from netbox_dns.models import Record
|
|
12
14
|
from netbox_dns.utilities import value_to_unicode
|
|
13
15
|
|
|
16
|
+
import logging
|
|
17
|
+
|
|
18
|
+
logger = logging.getLogger("netbox_dns")
|
|
19
|
+
|
|
14
20
|
|
|
15
21
|
__all__ = (
|
|
16
22
|
"RecordTable",
|
|
@@ -23,10 +29,18 @@ class RecordBaseTable(TenancyColumnsMixin, NetBoxTable):
|
|
|
23
29
|
zone = tables.Column(
|
|
24
30
|
linkify=True,
|
|
25
31
|
)
|
|
32
|
+
view = tables.Column(
|
|
33
|
+
accessor="zone__view",
|
|
34
|
+
linkify=True,
|
|
35
|
+
)
|
|
26
36
|
type = tables.Column()
|
|
27
37
|
name = tables.Column(
|
|
28
38
|
linkify=True,
|
|
29
39
|
)
|
|
40
|
+
fqdn = tables.Column(
|
|
41
|
+
verbose_name="FQDN",
|
|
42
|
+
linkify=True,
|
|
43
|
+
)
|
|
30
44
|
value = tables.TemplateColumn(
|
|
31
45
|
template_code="{{ value|truncatechars:64 }}",
|
|
32
46
|
)
|
|
@@ -65,20 +79,8 @@ class RecordTable(RecordBaseTable):
|
|
|
65
79
|
class Meta(NetBoxTable.Meta):
|
|
66
80
|
model = Record
|
|
67
81
|
fields = (
|
|
68
|
-
"name",
|
|
69
|
-
"zone",
|
|
70
|
-
"ttl",
|
|
71
|
-
"type",
|
|
72
|
-
"value",
|
|
73
|
-
"unicode_value",
|
|
74
82
|
"status",
|
|
75
|
-
"disable_ptr",
|
|
76
|
-
"ptr_record",
|
|
77
|
-
"tags",
|
|
78
|
-
"active",
|
|
79
83
|
"description",
|
|
80
|
-
"tenant",
|
|
81
|
-
"tenant_group",
|
|
82
84
|
)
|
|
83
85
|
default_columns = (
|
|
84
86
|
"name",
|
|
@@ -100,21 +102,16 @@ class ManagedRecordTable(RecordBaseTable):
|
|
|
100
102
|
verbose_name="IPAM IP Address",
|
|
101
103
|
linkify=True,
|
|
102
104
|
)
|
|
105
|
+
related_ip_address = tables.Column(
|
|
106
|
+
verbose_name="Related IP Address",
|
|
107
|
+
empty_values=(),
|
|
108
|
+
orderable=False,
|
|
109
|
+
)
|
|
103
110
|
actions = ActionsColumn(actions=("changelog",))
|
|
104
111
|
|
|
105
112
|
class Meta(NetBoxTable.Meta):
|
|
106
113
|
model = Record
|
|
107
|
-
fields = (
|
|
108
|
-
"name",
|
|
109
|
-
"zone",
|
|
110
|
-
"ttl",
|
|
111
|
-
"type",
|
|
112
|
-
"value",
|
|
113
|
-
"unicode_value",
|
|
114
|
-
"address_record",
|
|
115
|
-
"ipam_ip_address",
|
|
116
|
-
"active",
|
|
117
|
-
)
|
|
114
|
+
fields = ()
|
|
118
115
|
default_columns = (
|
|
119
116
|
"name",
|
|
120
117
|
"zone",
|
|
@@ -124,19 +121,35 @@ class ManagedRecordTable(RecordBaseTable):
|
|
|
124
121
|
"active",
|
|
125
122
|
)
|
|
126
123
|
|
|
124
|
+
def render_related_ip_address(self, record):
|
|
125
|
+
if record.ipam_ip_address is not None:
|
|
126
|
+
address = record.ipam_ip_address
|
|
127
|
+
elif (
|
|
128
|
+
hasattr(record, "address_record")
|
|
129
|
+
and record.address_record.ipam_ip_address is not None
|
|
130
|
+
):
|
|
131
|
+
address = record.address_record.ipam_ip_address
|
|
132
|
+
else:
|
|
133
|
+
return format_html("—")
|
|
134
|
+
|
|
135
|
+
return format_html(f"<a href='{address.get_absolute_url()}'>{address}</a>")
|
|
136
|
+
|
|
137
|
+
def value_related_ip_address(self, record):
|
|
138
|
+
if record.ipam_ip_address is not None:
|
|
139
|
+
return record.ipam_ip_address
|
|
140
|
+
elif (
|
|
141
|
+
hasattr(record, "address_record")
|
|
142
|
+
and record.address_record.ipam_ip_address is not None
|
|
143
|
+
):
|
|
144
|
+
return record.address_record.ipam_ip_address
|
|
145
|
+
|
|
127
146
|
|
|
128
147
|
class RelatedRecordTable(RecordBaseTable):
|
|
129
148
|
actions = ActionsColumn(actions=())
|
|
130
149
|
|
|
131
150
|
class Meta(NetBoxTable.Meta):
|
|
132
151
|
model = Record
|
|
133
|
-
fields = (
|
|
134
|
-
"name",
|
|
135
|
-
"zone",
|
|
136
|
-
"type",
|
|
137
|
-
"value",
|
|
138
|
-
"unicode_value",
|
|
139
|
-
)
|
|
152
|
+
fields = ()
|
|
140
153
|
default_columns = (
|
|
141
154
|
"name",
|
|
142
155
|
"zone",
|
|
@@ -43,18 +43,8 @@ class RecordTemplateTable(TenancyColumnsMixin, NetBoxTable):
|
|
|
43
43
|
class Meta(NetBoxTable.Meta):
|
|
44
44
|
model = RecordTemplate
|
|
45
45
|
fields = (
|
|
46
|
-
"name",
|
|
47
|
-
"record_name",
|
|
48
|
-
"ttl",
|
|
49
|
-
"type",
|
|
50
|
-
"value",
|
|
51
|
-
"unicode_value",
|
|
52
46
|
"status",
|
|
53
|
-
"disable_ptr",
|
|
54
|
-
"tags",
|
|
55
47
|
"description",
|
|
56
|
-
"tenant",
|
|
57
|
-
"tenant_group",
|
|
58
48
|
)
|
|
59
49
|
default_columns = (
|
|
60
50
|
"name",
|
|
@@ -72,14 +62,7 @@ class RecordTemplateDisplayTable(RecordTemplateTable):
|
|
|
72
62
|
class Meta(NetBoxTable.Meta):
|
|
73
63
|
model = RecordTemplate
|
|
74
64
|
fields = (
|
|
75
|
-
"name",
|
|
76
|
-
"record_name",
|
|
77
|
-
"ttl",
|
|
78
|
-
"type",
|
|
79
|
-
"value",
|
|
80
|
-
"unicode_value",
|
|
81
65
|
"status",
|
|
82
|
-
"disable_ptr",
|
|
83
66
|
"description",
|
|
84
67
|
)
|
|
85
68
|
default_columns = (
|
netbox_dns/tables/registrar.py
CHANGED
|
@@ -19,13 +19,11 @@ class RegistrarTable(NetBoxTable):
|
|
|
19
19
|
class Meta(NetBoxTable.Meta):
|
|
20
20
|
model = Registrar
|
|
21
21
|
fields = (
|
|
22
|
-
"name",
|
|
23
22
|
"description",
|
|
24
23
|
"iana_id",
|
|
25
24
|
"referral_url",
|
|
26
25
|
"whois_server",
|
|
27
26
|
"abuse_email",
|
|
28
27
|
"abuse_phone",
|
|
29
|
-
"tags",
|
|
30
28
|
)
|
|
31
29
|
default_columns = ("name", "iana_id", "referral_url")
|
|
@@ -2,24 +2,23 @@ import django_tables2 as tables
|
|
|
2
2
|
|
|
3
3
|
from netbox.tables import NetBoxTable, TagColumn
|
|
4
4
|
|
|
5
|
-
from netbox_dns.models import
|
|
5
|
+
from netbox_dns.models import RegistrationContact
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
__all__ = ("
|
|
8
|
+
__all__ = ("RegistrationContactTable",)
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
class
|
|
11
|
+
class RegistrationContactTable(NetBoxTable):
|
|
12
12
|
contact_id = tables.Column(
|
|
13
13
|
linkify=True,
|
|
14
14
|
)
|
|
15
15
|
tags = TagColumn(
|
|
16
|
-
url_name="plugins:netbox_dns:
|
|
16
|
+
url_name="plugins:netbox_dns:registrationcontact_list",
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
class Meta(NetBoxTable.Meta):
|
|
20
|
-
model =
|
|
20
|
+
model = RegistrationContact
|
|
21
21
|
fields = (
|
|
22
|
-
"contact_id",
|
|
23
22
|
"name",
|
|
24
23
|
"description",
|
|
25
24
|
"organization",
|
netbox_dns/tables/view.py
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import django_tables2 as tables
|
|
2
2
|
|
|
3
|
-
from netbox.tables import NetBoxTable, TagColumn
|
|
3
|
+
from netbox.tables import NetBoxTable, TagColumn, ActionsColumn
|
|
4
4
|
from tenancy.tables import TenancyColumnsMixin
|
|
5
5
|
|
|
6
6
|
from netbox_dns.models import View
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
__all__ = (
|
|
9
|
+
__all__ = (
|
|
10
|
+
"ViewTable",
|
|
11
|
+
"RelatedViewTable",
|
|
12
|
+
)
|
|
10
13
|
|
|
11
14
|
|
|
12
15
|
class ViewTable(TenancyColumnsMixin, NetBoxTable):
|
|
@@ -18,14 +21,26 @@ class ViewTable(TenancyColumnsMixin, NetBoxTable):
|
|
|
18
21
|
)
|
|
19
22
|
tags = TagColumn(url_name="plugins:netbox_dns:view_list")
|
|
20
23
|
|
|
24
|
+
class Meta(NetBoxTable.Meta):
|
|
25
|
+
model = View
|
|
26
|
+
fields = ("description",)
|
|
27
|
+
default_columns = ("name", "default_view")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class RelatedViewTable(TenancyColumnsMixin, NetBoxTable):
|
|
31
|
+
actions = ActionsColumn(actions=())
|
|
32
|
+
|
|
33
|
+
name = tables.Column(
|
|
34
|
+
linkify=True,
|
|
35
|
+
)
|
|
36
|
+
|
|
21
37
|
class Meta(NetBoxTable.Meta):
|
|
22
38
|
model = View
|
|
23
39
|
fields = (
|
|
24
40
|
"name",
|
|
25
|
-
"default_view",
|
|
26
41
|
"description",
|
|
27
42
|
"tenant",
|
|
28
43
|
"tenant_group",
|
|
29
44
|
"tags",
|
|
30
45
|
)
|
|
31
|
-
default_columns = ("name", "
|
|
46
|
+
default_columns = ("name", "description")
|
netbox_dns/tables/zone.py
CHANGED
|
@@ -58,26 +58,11 @@ class ZoneTable(TenancyColumnsMixin, NetBoxTable):
|
|
|
58
58
|
class Meta(NetBoxTable.Meta):
|
|
59
59
|
model = Zone
|
|
60
60
|
fields = (
|
|
61
|
-
"name",
|
|
62
|
-
"view",
|
|
63
|
-
"status",
|
|
64
61
|
"description",
|
|
65
|
-
"tags",
|
|
66
|
-
"default_ttl",
|
|
67
|
-
"soa_mname",
|
|
68
62
|
"soa_rname",
|
|
69
63
|
"soa_serial",
|
|
70
|
-
"rfc2317_prefix",
|
|
71
64
|
"rfc2317_parent_managed",
|
|
72
|
-
"rfc2317_parent_zone",
|
|
73
|
-
"registrar",
|
|
74
65
|
"registry_domain_id",
|
|
75
|
-
"registrant",
|
|
76
|
-
"admin_c",
|
|
77
|
-
"tech_c",
|
|
78
|
-
"billing_c",
|
|
79
|
-
"tenant",
|
|
80
|
-
"tenant_group",
|
|
81
66
|
)
|
|
82
67
|
default_columns = (
|
|
83
68
|
"name",
|
|
@@ -37,18 +37,7 @@ class ZoneTemplateTable(TenancyColumnsMixin, NetBoxTable):
|
|
|
37
37
|
|
|
38
38
|
class Meta(NetBoxTable.Meta):
|
|
39
39
|
model = ZoneTemplate
|
|
40
|
-
fields = (
|
|
41
|
-
"name",
|
|
42
|
-
"description",
|
|
43
|
-
"tags",
|
|
44
|
-
"registrar",
|
|
45
|
-
"registrant",
|
|
46
|
-
"admin_c",
|
|
47
|
-
"tech_c",
|
|
48
|
-
"billing_c",
|
|
49
|
-
"tenant",
|
|
50
|
-
"tenant_group",
|
|
51
|
-
)
|
|
40
|
+
fields = ("description",)
|
|
52
41
|
default_columns = (
|
|
53
42
|
"name",
|
|
54
43
|
"tags",
|
|
@@ -60,10 +49,7 @@ class ZoneTemplateDisplayTable(ZoneTemplateTable):
|
|
|
60
49
|
|
|
61
50
|
class Meta(NetBoxTable.Meta):
|
|
62
51
|
model = ZoneTemplate
|
|
63
|
-
fields = (
|
|
64
|
-
"name",
|
|
65
|
-
"description",
|
|
66
|
-
)
|
|
52
|
+
fields = ("description",)
|
|
67
53
|
default_columns = (
|
|
68
54
|
"name",
|
|
69
55
|
"description",
|