Rename field in IPAddr : "hostname" to "ptr"

This commit is contained in:
rdujardin 2016-07-27 15:10:28 +02:00
parent 705690edda
commit ee78bf5455
8 changed files with 44 additions and 20 deletions

View File

@ -335,11 +335,11 @@ class IPAddressForm(forms.ModelForm, BootstrapMixin):
class Meta: class Meta:
model = IPAddress model = IPAddress
fields = ['address', 'vrf', 'hostname', 'nat_device', 'nat_inside', 'description'] fields = ['address', 'vrf', 'ptr', 'nat_device', 'nat_inside', 'description']
help_texts = { help_texts = {
'address': "IPv4 or IPv6 address and mask", 'address': "IPv4 or IPv6 address and mask",
'vrf': "VRF (if applicable)", 'vrf': "VRF (if applicable)",
'hostname': "Reverse DNS host name", 'ptr': "Reverse DNS name",
} }
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -392,7 +392,7 @@ class IPAddressFromCSVForm(forms.ModelForm):
class Meta: class Meta:
model = IPAddress 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): def clean(self):
@ -439,7 +439,7 @@ class IPAddressBulkEditForm(forms.Form, BootstrapMixin):
pk = forms.ModelMultipleChoiceField(queryset=IPAddress.objects.all(), widget=forms.MultipleHiddenInput) pk = forms.ModelMultipleChoiceField(queryset=IPAddress.objects.all(), widget=forms.MultipleHiddenInput)
vrf = forms.ModelChoiceField(queryset=VRF.objects.all(), required=False, label='VRF', 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") 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') vrf_global = forms.BooleanField(required=False, label='Set VRF to global')
description = forms.CharField(max_length=50, required=False) description = forms.CharField(max_length=50, required=False)

View File

@ -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'),
),
]

View File

@ -376,7 +376,7 @@ class Prefix(CreatedUpdatedModel):
ipaddresses = IPAddress.objects.filter(family=4) ipaddresses = IPAddress.objects.filter(family=4)
for ip in ipaddresses: for ip in ipaddresses:
if ip.hostname: if ip.ptr:
ibytes = str(ip.address).split('/')[0].split('.') ibytes = str(ip.address).split('/')[0].split('.')
islash = str(ip.address).split('/')[1] islash = str(ip.address).split('/')[1]
i = netaddr.IPAddress(unicode('.'.join(ibytes))) i = netaddr.IPAddress(unicode('.'.join(ibytes)))
@ -386,12 +386,12 @@ class Prefix(CreatedUpdatedModel):
zone_id = ibytes[2] + '.' + ibytes[1] + '.' + ibytes[0] + '.in-addr.arpa.' zone_id = ibytes[2] + '.' + ibytes[1] + '.' + ibytes[0] + '.in-addr.arpa.'
if not zone_id in zones: if not zone_id in zones:
zones[zone_id] = header(zone_id) 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: else:
zone_id = ibytes[1]+'.'+ibytes[0]+'.in-addr.arpa.' zone_id = ibytes[1]+'.'+ibytes[0]+'.in-addr.arpa.'
if not zone_id in zones: if not zone_id in zones:
zones[zone_id] = header(zone_id) 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) pnibbles = pnibbles[:zslash/16] + ['0000'] * (8 - zslash/16)
for ip in ipaddresses: for ip in ipaddresses:
if ip.hostname: if ip.ptr:
ifull = str(ipaddress.IPv6Address(unicode(str(ip.address).split('/')[0])).exploded) ifull = str(ipaddress.IPv6Address(unicode(str(ip.address).split('/')[0])).exploded)
inibbles = ifull.split(':') inibbles = ifull.split(':')
idigits = ifull.replace(':','')[::-1] idigits = ifull.replace(':','')[::-1]
@ -427,7 +427,7 @@ class Prefix(CreatedUpdatedModel):
if not zone_id in zones: if not zone_id in zones:
zones[zone_id] = header(zone_id) 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: for z in zones:
@ -459,7 +459,7 @@ class IPAddress(CreatedUpdatedModel):
address = IPAddressField() address = IPAddressField()
vrf = models.ForeignKey('VRF', related_name='ip_addresses', on_delete=models.PROTECT, blank=True, null=True, vrf = models.ForeignKey('VRF', related_name='ip_addresses', on_delete=models.PROTECT, blank=True, null=True,
verbose_name='VRF') 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, interface = models.ForeignKey(Interface, related_name='ip_addresses', on_delete=models.CASCADE, blank=True,
null=True) null=True)
nat_inside = models.OneToOneField('self', related_name='nat_outside', on_delete=models.SET_NULL, blank=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([ return ','.join([
str(self.address), str(self.address),
self.vrf.rd if self.vrf else '', 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.device.identifier if self.device else '',
self.interface.name if self.interface else '', self.interface.name if self.interface else '',
'True' if is_primary else '', 'True' if is_primary else '',

View File

@ -160,7 +160,7 @@ class IPAddressTable(BaseTable):
pk = ToggleColumn() pk = ToggleColumn()
address = tables.LinkColumn('ipam:ipaddress', args=[Accessor('pk')], verbose_name='IP Address') address = tables.LinkColumn('ipam:ipaddress', args=[Accessor('pk')], verbose_name='IP Address')
vrf = tables.Column(orderable=False, default='Global', verbose_name='VRF') 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, device = tables.LinkColumn('dcim:device', args=[Accessor('interface.device.pk')], orderable=False,
verbose_name='Device') verbose_name='Device')
interface = tables.Column(orderable=False, verbose_name='Interface') interface = tables.Column(orderable=False, verbose_name='Interface')
@ -168,7 +168,7 @@ class IPAddressTable(BaseTable):
class Meta(BaseTable.Meta): class Meta(BaseTable.Meta):
model = IPAddress model = IPAddress
fields = ('pk', 'address', 'vrf', 'hostname', 'device', 'interface', 'description') fields = ('pk', 'address', 'vrf', 'ptr', 'device', 'interface', 'description')
class IPAddressBriefTable(BaseTable): class IPAddressBriefTable(BaseTable):

View File

@ -65,10 +65,10 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Host Name</td> <td>PTR</td>
<td> <td>
{% if ipaddress.hostname %} {% if ipaddress.ptr %}
<span>{{ ipaddress.hostname }}</span> <span>{{ ipaddress.ptr }}</span>
{% else %} {% else %}
<span class="text-muted">None</span> <span class="text-muted">None</span>
{% endif %} {% endif %}

View File

@ -8,7 +8,7 @@
<tr> <tr>
<td><a href="{% url 'ipam:ipaddress' pk=ipaddress.pk %}">{{ ipaddress }}</a></td> <td><a href="{% url 'ipam:ipaddress' pk=ipaddress.pk %}">{{ ipaddress }}</a></td>
<td>{{ ipaddress.vrf }}</td> <td>{{ ipaddress.vrf }}</td>
<td>{{ ipaddress.hostname }}</td> <td>{{ ipaddress.ptr }}</td>
<td>{{ ipaddress.interface.device }}</td> <td>{{ ipaddress.interface.device }}</td>
<td>{{ ipaddress.interface }}</td> <td>{{ ipaddress.interface }}</td>
<td>{{ ipaddress.description }}</td> <td>{{ ipaddress.description }}</td>

View File

@ -8,7 +8,7 @@
<div class="panel-body"> <div class="panel-body">
{% render_field form.address %} {% render_field form.address %}
{% render_field form.vrf %} {% render_field form.vrf %}
{% render_field form.hostname %} {% render_field form.ptr %}
{% if obj %} {% if obj %}
<div class="form-group"> <div class="form-group">
<label class="col-md-3 control-label">Device</label> <label class="col-md-3 control-label">Device</label>

View File

@ -39,8 +39,8 @@
<td>65000:123</td> <td>65000:123</td>
</tr> </tr>
<tr> <tr>
<td>Host Name</td> <td>PTR</td>
<td>Reverse DNS host name</td> <td>Reverse DNS Name</td>
<td>foo.com</td> <td>foo.com</td>
</tr> </tr>
<tr> <tr>