Skip to content

Commit

Permalink
Fixed the ready() method in init.py
Browse files Browse the repository at this point in the history
* Some required CFs were missing from the list of CFs to check
* manage.py createstatic fails when there is no database connection
  • Loading branch information
peteeckel committed Jan 18, 2024
1 parent e10f9d3 commit 36a6564
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions netbox_dns/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys

from extras.plugins import PluginConfig
from django.db.utils import OperationalError

try:
# NetBox 3.5.0 - 3.5.7, 3.5.9+
Expand Down Expand Up @@ -50,17 +51,29 @@ def ready(self):
from ipam.models import IPAddress
from django.contrib.contenttypes.models import ContentType

objtype = ContentType.objects.get_for_model(IPAddress)
required_cf = ("ipaddress_dns_record_name", "ipaddress_dns_zone_id")
try:
objtype = ContentType.objects.get_for_model(IPAddress)
required_cf = (
"ipaddress_dns_record_name",
"ipaddress_dns_record_ttl",
"ipaddress_dns_record_disable_ptr",
"ipaddress_dns_zone_id",
)

if CustomField.objects.filter(
name__in=required_cf, content_types=objtype
).count() < len(required_cf):
if CustomField.objects.filter(
name__in=required_cf, content_types=objtype
).count() < len(required_cf):
print(
"WARNING: 'feature_ipam_coupling' is enabled, but the required"
" custom fields for IPAM DNS coupling are missing. Please run"
" the Django management command 'setup_coupling' to create the"
" missing custom fields.",
file=sys.stderr,
)
except OperationalError as exc:
print(
"WARNING: 'feature_ipam_coupling' is enabled, but the required"
" custom fields for IPAM DNS coupling are missing. Please run"
" the Django management command 'setup_coupling' to create the"
" custom fields.",
"WARNING: Unable to connect to PostgreSQL, cannot check custom fields"
" for feature_ipam_coupling",
file=sys.stderr,
)

Expand Down

0 comments on commit 36a6564

Please sign in to comment.