netbox-plugin-dns 0.22.5__py3-none-any.whl → 0.22.6__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 CHANGED
@@ -10,7 +10,7 @@ except ImportError:
10
10
  # NetBox 3.5.8
11
11
  from extras.plugins.utils import get_plugin_config
12
12
 
13
- __version__ = "0.22.5"
13
+ __version__ = "0.22.6"
14
14
 
15
15
 
16
16
  class DNSConfig(PluginConfig):
@@ -43,43 +43,6 @@ class DNSConfig(PluginConfig):
43
43
  }
44
44
  base_url = "netbox-dns"
45
45
 
46
- def ready(self):
47
- #
48
- # Check if required custom fields exist for IPAM coupling
49
- #
50
- if get_plugin_config("netbox_dns", "feature_ipam_coupling"):
51
- from extras.models import CustomField
52
- from ipam.models import IPAddress
53
- from django.contrib.contenttypes.models import ContentType
54
-
55
- try:
56
- objtype = ContentType.objects.get_for_model(IPAddress)
57
- required_cf = (
58
- "ipaddress_dns_record_name",
59
- "ipaddress_dns_record_ttl",
60
- "ipaddress_dns_record_disable_ptr",
61
- "ipaddress_dns_zone_id",
62
- )
63
-
64
- if CustomField.objects.filter(
65
- name__in=required_cf, content_types=objtype
66
- ).count() < len(required_cf):
67
- print(
68
- "WARNING: 'feature_ipam_coupling' is enabled, but the required"
69
- " custom fields for IPAM DNS coupling are missing. Please run"
70
- " the Django management command 'setup_coupling' to create the"
71
- " missing custom fields.",
72
- file=sys.stderr,
73
- )
74
- except OperationalError as exc:
75
- print(
76
- "WARNING: Unable to connect to PostgreSQL, cannot check custom fields"
77
- " for feature_ipam_coupling",
78
- file=sys.stderr,
79
- )
80
-
81
- super().ready()
82
-
83
46
 
84
47
  #
85
48
  # Initialize plugin config
@@ -241,6 +241,16 @@ class Record(NetBoxModel):
241
241
 
242
242
  return name.to_text()
243
243
 
244
+ @property
245
+ def value_fqdn(self):
246
+ if self.type != RecordTypeChoices.CNAME:
247
+ return None
248
+
249
+ zone = dns_name.from_text(self.zone.name)
250
+ value_fqdn = dns_name.from_text(self.value, origin=zone)
251
+
252
+ return value_fqdn.to_text()
253
+
244
254
  @property
245
255
  def address_from_name(self):
246
256
  prefix = arpa_to_prefix(self.fqdn)
@@ -112,12 +112,6 @@
112
112
  <td><a href="{% url 'ipam:ipaddress' pk=object.ipam_ip_address.pk %}">{{ object.ipam_ip_address }}</td>
113
113
  </tr>
114
114
  {% endif %}
115
- {% if object.rfc2317_cname_record %}
116
- <tr>
117
- <th scope="row">RFC2317 CNAME Record</th>
118
- <td><a href="{% url 'plugins:netbox_dns:record' pk=object.rfc2317_cname_record.pk %}">{{ object.rfc2317_cname_record }}</td>
119
- </tr>
120
- {% endif %}
121
115
  <tr>
122
116
  <th scope="row">Status</th>
123
117
  <td>{% badge object.get_status_display bg_color=object.get_status_color %}</td>
@@ -131,23 +125,13 @@
131
125
  </table>
132
126
  </div>
133
127
  </div>
134
- {% if object.rfc2317_ptr_records.all|length %}
128
+ {% if cname_target_table and cname_target_table.rows|length > 0 %}
135
129
  <div class="card">
136
- <h5 class="card-header">RFC2317 Targets</h5>
137
- <div class="card-body">
138
- <table class="table table-hover attr-table">
139
- <tr>
140
- <th>Address Record</th>
141
- <th>PTR Record</th>
142
- </tr>
143
- {% for record in object.rfc2317_ptr_records.all %}
144
- <tr>
145
- <td><a href="{% url 'plugins:netbox_dns:record' pk=record.address_record.pk %}">{{ record.address_record }}</td>
146
- <td><a href="{% url 'plugins:netbox_dns:record' pk=record.pk %}">{{ record }}</td>
147
- </td>
148
- {% endfor %}
149
- </table>
150
- </div>
130
+ {% include 'inc/panel_table.html' with table=cname_target_table heading='CNAME Targets' %}
131
+ </div>
132
+ {% elif cname_table and cname_table.rows|length > 0 %}
133
+ <div class="card">
134
+ {% include 'inc/panel_table.html' with table=cname_table heading='CNAMEs' %}
151
135
  </div>
152
136
  {% endif %}
153
137
  {% if not object.managed %}
@@ -1,5 +1,8 @@
1
1
  from dns import name as dns_name
2
2
 
3
+ from django.db.models import Q
4
+ from django.db.models.functions import Length
5
+
3
6
  from netbox.views import generic
4
7
 
5
8
  from netbox_dns.filters import RecordFilter
@@ -9,8 +12,8 @@ from netbox_dns.forms import (
9
12
  RecordForm,
10
13
  RecordBulkEditForm,
11
14
  )
12
- from netbox_dns.models import Record
13
- from netbox_dns.tables import RecordTable, ManagedRecordTable
15
+ from netbox_dns.models import Record, RecordTypeChoices, Zone
16
+ from netbox_dns.tables import RecordTable, ManagedRecordTable, RelatedRecordTable
14
17
  from netbox_dns.utilities import value_to_unicode
15
18
 
16
19
 
@@ -37,6 +40,72 @@ class ManagedRecordListView(generic.ObjectListView):
37
40
  class RecordView(generic.ObjectView):
38
41
  queryset = Record.objects.all().prefetch_related("zone", "ptr_record")
39
42
 
43
+ def get_value_records(self, instance):
44
+ value_fqdn = dns_name.from_text(instance.value_fqdn)
45
+ value_zone_names = [
46
+ value_fqdn.split(length)[1].to_text().rstrip(".")
47
+ for length in range(2, len(value_fqdn))
48
+ ]
49
+
50
+ value_zone = (
51
+ Zone.objects.filter(instance.zone.view_filter, name__in=value_zone_names)
52
+ .order_by(Length("name").desc())
53
+ .first()
54
+ )
55
+ if not value_zone:
56
+ return None
57
+
58
+ value_name = value_fqdn.relativize(dns_name.from_text(value_zone.name))
59
+ cname_targets = Record.objects.filter(zone=value_zone, name=value_name)
60
+
61
+ if cname_targets:
62
+ return RelatedRecordTable(
63
+ data=cname_targets,
64
+ )
65
+
66
+ return None
67
+
68
+ def get_cname_records(self, instance):
69
+ view_filter = (
70
+ Q(zone__view__isnull=True)
71
+ if instance.zone.view is None
72
+ else Q(zone__view=instance.zone.view)
73
+ )
74
+ cname_records = set(
75
+ Record.objects.filter(
76
+ view_filter, value=instance.fqdn, type=RecordTypeChoices.CNAME
77
+ )
78
+ )
79
+
80
+ fqdn = dns_name.from_text(instance.fqdn)
81
+ parent_zone_names = [
82
+ fqdn.split(length)[1].to_text().rstrip(".")
83
+ for length in range(1, len(fqdn))
84
+ ]
85
+
86
+ parent_zones = Zone.objects.filter(
87
+ instance.zone.view_filter, name__in=parent_zone_names
88
+ )
89
+
90
+ for parent_zone in parent_zones:
91
+ parent_cname_records = Record.objects.filter(
92
+ view_filter, type=RecordTypeChoices.CNAME, zone=parent_zone
93
+ )
94
+ cname_records = cname_records.union(
95
+ set(
96
+ record
97
+ for record in parent_cname_records
98
+ if record.value_fqdn == instance.fqdn
99
+ )
100
+ )
101
+
102
+ if cname_records:
103
+ return RelatedRecordTable(
104
+ data=cname_records,
105
+ )
106
+
107
+ return None
108
+
40
109
  def get_extra_context(self, request, instance):
41
110
  context = {}
42
111
 
@@ -48,6 +117,11 @@ class RecordView(generic.ObjectView):
48
117
  if instance.value != unicode_value:
49
118
  context["unicode_value"] = unicode_value
50
119
 
120
+ if instance.type == RecordTypeChoices.CNAME:
121
+ context["cname_target_table"] = self.get_value_records(instance)
122
+ else:
123
+ context["cname_table"] = self.get_cname_records(instance)
124
+
51
125
  return context
52
126
 
53
127
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: netbox-plugin-dns
3
- Version: 0.22.5
3
+ Version: 0.22.6
4
4
  Summary: NetBox DNS is a NetBox plugin for managing DNS data.
5
5
  Home-page: https://github.com/peteeckel/netbox-plugin-dns
6
6
  License: MIT
@@ -1,4 +1,4 @@
1
- netbox_dns/__init__.py,sha256=Wnz89UxRISvgUOkm-cZI50tMo6taJh14iZnSb1Wx0L4,2818
1
+ netbox_dns/__init__.py,sha256=_MWBhj_SFYmwsvZRS4rBlGcGT5kgLacAUhdzHZ1gZ5I,1287
2
2
  netbox_dns/api/nested_serializers.py,sha256=XB7bcCjVMPYrumJWgRicj06PukQ2UCBjdr84AIUJuVQ,3291
3
3
  netbox_dns/api/serializers.py,sha256=H5Vm1O6C4SsxHVzdooYiu5ak3ykxXo-L1mT6ISWVRV8,8183
4
4
  netbox_dns/api/urls.py,sha256=R9VmmWtdrjvr35i5d_SfZK2lGn6JzmPuWEKTQlZ8MJo,575
@@ -67,7 +67,7 @@ netbox_dns/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3h
67
67
  netbox_dns/models/__init__.py,sha256=Q7UIEe2vGh18AZN4er6CykciwXPQGgUq0L-9718wZqU,182
68
68
  netbox_dns/models/contact.py,sha256=Mzj4SR3fczOE96etWjObJElk0RVQetNuXZVtm8sS1h8,2849
69
69
  netbox_dns/models/nameserver.py,sha256=SjKUbMRNE3TSDzmxbKFR9b4AfYPS0UPj0QeO7XpwNRk,2941
70
- netbox_dns/models/record.py,sha256=nOKjaoVuyMVIfwNw_V4hYYd71fcE4UyXThU983KrXaY,23629
70
+ netbox_dns/models/record.py,sha256=KbfSl9Np2kV_qozUB9zgoir3cwutYLvlxPa2q9X-9Jk,23896
71
71
  netbox_dns/models/registrar.py,sha256=ByKHeqH5KfswqOLjya8DZExJ1omSKFHMfCjIIYfnwTo,1416
72
72
  netbox_dns/models/view.py,sha256=ljs3Q2xQR63ZOSyja5H7DEdFbm7MX2ZjlR6uNVrAsVo,920
73
73
  netbox_dns/models/zone.py,sha256=Ek7Jui3AldNHVAHowbQhC47QoXv0IgkhLzFziN14UUI,26333
@@ -86,7 +86,7 @@ netbox_dns/templates/netbox_dns/contact.html,sha256=3qHGChgLYfqUgO3_z9jQ-lFIGS0Z
86
86
  netbox_dns/templates/netbox_dns/nameserver.html,sha256=3AJVbsuhKg4Jy74rlvwrGSHd_IoDRdLT_XuK4EH3Djg,1623
87
87
  netbox_dns/templates/netbox_dns/record/managed.html,sha256=G6LPG1koUGuzUiwYdv1okdVa4sKaofiQegDBnsFL0kA,89
88
88
  netbox_dns/templates/netbox_dns/record/related.html,sha256=Aqor8uGcuHQTHjlX-Xmni2Yp4N7lOBrMOqQiszrQOC0,742
89
- netbox_dns/templates/netbox_dns/record.html,sha256=1XOp9Rf7KiV736RKGh7A8LAYkrfI7veG5SsEhaeMghw,6613
89
+ netbox_dns/templates/netbox_dns/record.html,sha256=jq1kueOd5EN1myZt8RbXl4rjoTuxWezBnVv36i74QC8,5835
90
90
  netbox_dns/templates/netbox_dns/registrar.html,sha256=rSShbH68nP0r8EUHn0-TZOsUj6pg7hmfvM7h2tqouUA,2130
91
91
  netbox_dns/templates/netbox_dns/related_dns_objects.html,sha256=KSzlnw1cStrJa3poKkwrt_ycIH0oH0STWIHRNy3ks4g,806
92
92
  netbox_dns/templates/netbox_dns/view.html,sha256=_lDjd2xY3upfGpNpemXXMzgsaKZlX3-PzPPAdYkIjvs,1350
@@ -106,11 +106,11 @@ netbox_dns/validators/rfc2317.py,sha256=bgqDwdqwpf5d1mt24Wrr8z8t2IYbt5RovNr6l2nv
106
106
  netbox_dns/views/__init__.py,sha256=Aw8HrCTjaJfu5JSwJsQRHfOUz4zKwAmZNByT9q6BrFU,136
107
107
  netbox_dns/views/contact.py,sha256=6-oCfK98-submcUTmi0ejw7QBscNn3S9bnS0oUTXOaY,2235
108
108
  netbox_dns/views/nameserver.py,sha256=Wa8CQ19P5uPNLMIYkj_U82wmwdp5gZoBWZnOR4ZExa0,2990
109
- netbox_dns/views/record.py,sha256=2xzZnCWmCZIyEVjQfYo0rByhBNItPxNFiehOwDl8U6w,2507
109
+ netbox_dns/views/record.py,sha256=p6TOV2dGg5uNPtk2pSqLzMRXpgC-fazpwYe2mIRSTt8,4896
110
110
  netbox_dns/views/registrar.py,sha256=aznSKt1L5tILMLGgcZiBR7u7B8rNl-jM1B2-N0fTeK8,2072
111
111
  netbox_dns/views/view.py,sha256=uUvtlNEh5MYoEALvWWaCOqj_Zj8dpGOL2PUyg-UPfEA,1895
112
112
  netbox_dns/views/zone.py,sha256=SyttTAgrPPzf1jIT1B4RexCLdXYjSmPIZsefO_zog1Q,4587
113
- netbox_plugin_dns-0.22.5.dist-info/LICENSE,sha256=tziMJKpkMbySr09L6bIwsu7Ca9ICoqpMO3yAXgEMQA4,1076
114
- netbox_plugin_dns-0.22.5.dist-info/METADATA,sha256=U6WLJ-pstL29t54fKW1LAJMkq8r-rtSR8AtutZqxnHg,4572
115
- netbox_plugin_dns-0.22.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
116
- netbox_plugin_dns-0.22.5.dist-info/RECORD,,
113
+ netbox_plugin_dns-0.22.6.dist-info/LICENSE,sha256=tziMJKpkMbySr09L6bIwsu7Ca9ICoqpMO3yAXgEMQA4,1076
114
+ netbox_plugin_dns-0.22.6.dist-info/METADATA,sha256=v4cYHLNbhWBpdmkaefeFSQbmIqg5TxJfeI4SJpUsq4M,4572
115
+ netbox_plugin_dns-0.22.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
116
+ netbox_plugin_dns-0.22.6.dist-info/RECORD,,