From ee78bf545598101b36648d4f66aa0531fb84595d Mon Sep 17 00:00:00 2001 From: rdujardin Date: Wed, 27 Jul 2016 15:10:28 +0200 Subject: [PATCH] Rename field in IPAddr : "hostname" to "ptr" --- netbox/ipam/forms.py | 8 +++---- .../migrations/0008_auto_20160727_1307.py | 24 +++++++++++++++++++ netbox/ipam/models.py | 14 +++++------ netbox/ipam/tables.py | 4 ++-- netbox/templates/ipam/ipaddress.html | 6 ++--- .../templates/ipam/ipaddress_bulk_edit.html | 2 +- netbox/templates/ipam/ipaddress_edit.html | 2 +- netbox/templates/ipam/ipaddress_import.html | 4 ++-- 8 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 netbox/ipam/migrations/0008_auto_20160727_1307.py diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py index a33e68362..a3a73f32d 100644 --- a/netbox/ipam/forms.py +++ b/netbox/ipam/forms.py @@ -335,11 +335,11 @@ class IPAddressForm(forms.ModelForm, BootstrapMixin): class Meta: model = IPAddress - fields = ['address', 'vrf', 'hostname', 'nat_device', 'nat_inside', 'description'] + fields = ['address', 'vrf', 'ptr', 'nat_device', 'nat_inside', 'description'] help_texts = { 'address': "IPv4 or IPv6 address and mask", 'vrf': "VRF (if applicable)", - 'hostname': "Reverse DNS host name", + 'ptr': "Reverse DNS name", } def __init__(self, *args, **kwargs): @@ -392,7 +392,7 @@ class IPAddressFromCSVForm(forms.ModelForm): class Meta: model = IPAddress - fields = ['address', 'vrf', 'hostname', 'device', 'interface_name', 'is_primary', 'description'] + fields = ['address', 'vrf', 'ptr', 'device', 'interface_name', 'is_primary', 'description'] def clean(self): @@ -439,7 +439,7 @@ class IPAddressBulkEditForm(forms.Form, BootstrapMixin): pk = forms.ModelMultipleChoiceField(queryset=IPAddress.objects.all(), widget=forms.MultipleHiddenInput) vrf = forms.ModelChoiceField(queryset=VRF.objects.all(), required=False, label='VRF', help_text="Select the VRF to assign, or check below to remove VRF assignment") - hostname = forms.CharField(max_length=100, required=False) + ptr = forms.CharField(max_length=100, required=False, label='PTR') vrf_global = forms.BooleanField(required=False, label='Set VRF to global') description = forms.CharField(max_length=50, required=False) diff --git a/netbox/ipam/migrations/0008_auto_20160727_1307.py b/netbox/ipam/migrations/0008_auto_20160727_1307.py new file mode 100644 index 000000000..2d3f88dbf --- /dev/null +++ b/netbox/ipam/migrations/0008_auto_20160727_1307.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-07-27 13:07 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ipam', '0007_auto_20160722_0958'), + ] + + operations = [ + migrations.RemoveField( + model_name='ipaddress', + name='hostname', + ), + migrations.AddField( + model_name='ipaddress', + name='ptr', + field=models.CharField(blank=True, max_length=100, verbose_name=b'PTR'), + ), + ] diff --git a/netbox/ipam/models.py b/netbox/ipam/models.py index e407ebf00..1d518ffb8 100644 --- a/netbox/ipam/models.py +++ b/netbox/ipam/models.py @@ -376,7 +376,7 @@ class Prefix(CreatedUpdatedModel): ipaddresses = IPAddress.objects.filter(family=4) for ip in ipaddresses: - if ip.hostname: + if ip.ptr: ibytes = str(ip.address).split('/')[0].split('.') islash = str(ip.address).split('/')[1] i = netaddr.IPAddress(unicode('.'.join(ibytes))) @@ -386,12 +386,12 @@ class Prefix(CreatedUpdatedModel): zone_id = ibytes[2] + '.' + ibytes[1] + '.' + ibytes[0] + '.in-addr.arpa.' if not zone_id in zones: zones[zone_id] = header(zone_id) - zones[zone_id] += ibytes[3].ljust(3) + ' IN PTR ' + ip.hostname.ljust(40) + ' ; ' + ip.description.ljust(20) + ' ; gen by netbox ( '+time.strftime('%A %B %d %Y %H:%M:%S',time.localtime())+' ) \n' + zones[zone_id] += ibytes[3].ljust(3) + ' IN PTR ' + ip.ptr.ljust(40) + ' ; ' + ip.description.ljust(20) + ' ; gen by netbox ( '+time.strftime('%A %B %d %Y %H:%M:%S',time.localtime())+' ) \n' else: zone_id = ibytes[1]+'.'+ibytes[0]+'.in-addr.arpa.' if not zone_id in zones: zones[zone_id] = header(zone_id) - zones[zone_id] += (ibytes[3]+'.'+ibytes[2]).ljust(7) + ' IN PTR ' + ip.hostname.ljust(40) + ' ; ' + ip.description.ljust(20) + ' ; gen by netbox ( '+time.strftime('%A %B %d %Y %H:%M:%S',time.localtime())+' ) \n' + zones[zone_id] += (ibytes[3]+'.'+ibytes[2]).ljust(7) + ' IN PTR ' + ip.ptr.ljust(40) + ' ; ' + ip.description.ljust(20) + ' ; gen by netbox ( '+time.strftime('%A %B %d %Y %H:%M:%S',time.localtime())+' ) \n' @@ -416,7 +416,7 @@ class Prefix(CreatedUpdatedModel): pnibbles = pnibbles[:zslash/16] + ['0000'] * (8 - zslash/16) for ip in ipaddresses: - if ip.hostname: + if ip.ptr: ifull = str(ipaddress.IPv6Address(unicode(str(ip.address).split('/')[0])).exploded) inibbles = ifull.split(':') idigits = ifull.replace(':','')[::-1] @@ -427,7 +427,7 @@ class Prefix(CreatedUpdatedModel): if not zone_id in zones: zones[zone_id] = header(zone_id) - zones[zone_id] += ('.'.join(idigits[:32-zslash/4])).ljust(30)+' IN PTR ' + ip.hostname.ljust(40) + ' ; ' + ip.description.ljust(20) + ' ; gen by netbox ( '+time.strftime('%A %B %d %Y %H:%M:%S',time.localtime())+' ) \n' + zones[zone_id] += ('.'.join(idigits[:32-zslash/4])).ljust(30)+' IN PTR ' + ip.ptr.ljust(40) + ' ; ' + ip.description.ljust(20) + ' ; gen by netbox ( '+time.strftime('%A %B %d %Y %H:%M:%S',time.localtime())+' ) \n' for z in zones: @@ -459,7 +459,7 @@ class IPAddress(CreatedUpdatedModel): address = IPAddressField() vrf = models.ForeignKey('VRF', related_name='ip_addresses', on_delete=models.PROTECT, blank=True, null=True, verbose_name='VRF') - hostname = models.CharField(max_length=100, blank=True, verbose_name='Host Name') + ptr = models.CharField(max_length=100, blank=True, verbose_name='PTR') interface = models.ForeignKey(Interface, related_name='ip_addresses', on_delete=models.CASCADE, blank=True, null=True) nat_inside = models.OneToOneField('self', related_name='nat_outside', on_delete=models.SET_NULL, blank=True, @@ -513,7 +513,7 @@ class IPAddress(CreatedUpdatedModel): return ','.join([ str(self.address), self.vrf.rd if self.vrf else '', - self.hostname if self.hostname else '', + self.ptr if self.ptr else '', self.device.identifier if self.device else '', self.interface.name if self.interface else '', 'True' if is_primary else '', diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py index 83d062ec9..5048e3ee5 100644 --- a/netbox/ipam/tables.py +++ b/netbox/ipam/tables.py @@ -160,7 +160,7 @@ class IPAddressTable(BaseTable): pk = ToggleColumn() address = tables.LinkColumn('ipam:ipaddress', args=[Accessor('pk')], verbose_name='IP Address') vrf = tables.Column(orderable=False, default='Global', verbose_name='VRF') - hostname = tables.Column(verbose_name='Host Name') + ptr = tables.Column(verbose_name='PTR') device = tables.LinkColumn('dcim:device', args=[Accessor('interface.device.pk')], orderable=False, verbose_name='Device') interface = tables.Column(orderable=False, verbose_name='Interface') @@ -168,7 +168,7 @@ class IPAddressTable(BaseTable): class Meta(BaseTable.Meta): model = IPAddress - fields = ('pk', 'address', 'vrf', 'hostname', 'device', 'interface', 'description') + fields = ('pk', 'address', 'vrf', 'ptr', 'device', 'interface', 'description') class IPAddressBriefTable(BaseTable): diff --git a/netbox/templates/ipam/ipaddress.html b/netbox/templates/ipam/ipaddress.html index ea008bca7..400d80cc9 100644 --- a/netbox/templates/ipam/ipaddress.html +++ b/netbox/templates/ipam/ipaddress.html @@ -65,10 +65,10 @@ - Host Name + PTR - {% if ipaddress.hostname %} - {{ ipaddress.hostname }} + {% if ipaddress.ptr %} + {{ ipaddress.ptr }} {% else %} None {% endif %} diff --git a/netbox/templates/ipam/ipaddress_bulk_edit.html b/netbox/templates/ipam/ipaddress_bulk_edit.html index cf52a3b06..85e9e9488 100644 --- a/netbox/templates/ipam/ipaddress_bulk_edit.html +++ b/netbox/templates/ipam/ipaddress_bulk_edit.html @@ -8,7 +8,7 @@ {{ ipaddress }} {{ ipaddress.vrf }} - {{ ipaddress.hostname }} + {{ ipaddress.ptr }} {{ ipaddress.interface.device }} {{ ipaddress.interface }} {{ ipaddress.description }} diff --git a/netbox/templates/ipam/ipaddress_edit.html b/netbox/templates/ipam/ipaddress_edit.html index e2b0dec02..d7958a2ba 100644 --- a/netbox/templates/ipam/ipaddress_edit.html +++ b/netbox/templates/ipam/ipaddress_edit.html @@ -8,7 +8,7 @@
{% render_field form.address %} {% render_field form.vrf %} - {% render_field form.hostname %} + {% render_field form.ptr %} {% if obj %}
diff --git a/netbox/templates/ipam/ipaddress_import.html b/netbox/templates/ipam/ipaddress_import.html index 76906d683..a890798a5 100644 --- a/netbox/templates/ipam/ipaddress_import.html +++ b/netbox/templates/ipam/ipaddress_import.html @@ -39,8 +39,8 @@ 65000:123 - Host Name - Reverse DNS host name + PTR + Reverse DNS Name foo.com