Skip to content

Commit

Permalink
Closes #166: Add dns_name to IPAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Apr 22, 2019
1 parent 695a07d commit a026ec4
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ functionality provided by the front end UI.

## Enhancements

* [#166](https://github.com/digitalocean/netbox/issues/166) - Add `dns_name` field to IPAddress
* [#323](https://github.com/digitalocean/netbox/issues/323) - Enforce view permissions by object type
* [#1792](https://github.com/digitalocean/netbox/issues/1792) - Add CustomFieldChoices API endpoint
* [#1863](https://github.com/digitalocean/netbox/issues/1863) - Add child object counts to API representation of organizational objects
Expand Down
4 changes: 2 additions & 2 deletions netbox/ipam/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ class IPAddressSerializer(TaggitSerializer, CustomFieldModelSerializer):
class Meta:
model = IPAddress
fields = [
'id', 'family', 'address', 'vrf', 'tenant', 'status', 'role', 'interface', 'description', 'nat_inside',
'nat_outside', 'tags', 'custom_fields', 'created', 'last_updated',
'id', 'family', 'address', 'vrf', 'tenant', 'status', 'role', 'interface', 'nat_inside',
'nat_outside', 'dns_name', 'description', 'tags', 'custom_fields', 'created', 'last_updated',
]
read_only_fields = ['family']

Expand Down
3 changes: 2 additions & 1 deletion netbox/ipam/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,13 @@ class IPAddressFilter(CustomFieldFilterSet, django_filters.FilterSet):

class Meta:
model = IPAddress
fields = ['family']
fields = ['family', 'dns_name']

def search(self, queryset, name, value):
if not value.strip():
return queryset
qs_filter = (
Q(dns_name__icontains=value) |
Q(description__icontains=value) |
Q(address__istartswith=value)
)
Expand Down
15 changes: 10 additions & 5 deletions netbox/ipam/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,8 @@ class IPAddressForm(BootstrapMixin, TenancyForm, ReturnURLForm, CustomFieldForm)
class Meta:
model = IPAddress
fields = [
'address', 'vrf', 'status', 'role', 'description', 'interface', 'primary_for_parent', 'nat_site',
'nat_rack', 'nat_inside', 'tenant_group', 'tenant', 'tags',
'address', 'vrf', 'status', 'role', 'dns_name', 'description', 'interface', 'primary_for_parent',
'nat_site', 'nat_rack', 'nat_inside', 'tenant_group', 'tenant', 'tags',
]
widgets = {
'status': StaticSelect2(),
Expand Down Expand Up @@ -746,7 +746,7 @@ class IPAddressBulkAddForm(BootstrapMixin, TenancyForm, CustomFieldForm):
class Meta:
model = IPAddress
fields = [
'address', 'vrf', 'status', 'role', 'description', 'tenant_group', 'tenant',
'address', 'vrf', 'status', 'role', 'dns_name', 'description', 'tenant_group', 'tenant',
]
widgets = {
'status': StaticSelect2(),
Expand Down Expand Up @@ -919,13 +919,18 @@ class IPAddressBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEd
required=False,
widget=StaticSelect2()
)
dns_name = forms.CharField(
max_length=255,
required=False
)
description = forms.CharField(
max_length=100, required=False
max_length=100,
required=False
)

class Meta:
nullable_fields = [
'vrf', 'role', 'tenant', 'description',
'vrf', 'role', 'tenant', 'dns_name', 'description',
]


Expand Down
19 changes: 19 additions & 0 deletions netbox/ipam/migrations/0027_ipaddress_add_dns_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2 on 2019-04-22 21:43

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('ipam', '0026_prefix_ordering_vrf_nulls_first'),
]

operations = [
migrations.AddField(
model_name='ipaddress',
name='dns_name',
field=models.CharField(blank=True, max_length=255, validators=[django.core.validators.RegexValidator(code='invalid', message='Only alphanumeric characters, hyphens, and periods are allowed in DNS names', regex='^[0-9A-Za-z\\.-]+$')]),
),
]
11 changes: 10 additions & 1 deletion netbox/ipam/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .constants import *
from .fields import IPNetworkField, IPAddressField
from .querysets import PrefixQuerySet
from .validators import DNSValidator


class VRF(ChangeLoggedModel, CustomFieldModel):
Expand Down Expand Up @@ -573,6 +574,13 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
verbose_name='NAT (Inside)',
help_text='The IP for which this address is the "outside" IP'
)
dns_name = models.CharField(
max_length=255,
blank=True,
validators=[DNSValidator],
verbose_name='DNS Name',
help_text='Hostname or FQDN'
)
description = models.CharField(
max_length=100,
blank=True
Expand All @@ -588,7 +596,7 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):

csv_headers = [
'address', 'vrf', 'tenant', 'status', 'role', 'device', 'virtual_machine', 'interface_name', 'is_primary',
'description',
'dns_name', 'description',
]

class Meta:
Expand Down Expand Up @@ -671,6 +679,7 @@ def to_csv(self):
self.virtual_machine.name if self.virtual_machine else None,
self.interface.name if self.interface else None,
is_primary,
self.dns_name,
self.description,
)

Expand Down
7 changes: 5 additions & 2 deletions netbox/ipam/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ class IPAddressTable(BaseTable):

class Meta(BaseTable.Meta):
model = IPAddress
fields = ('pk', 'address', 'vrf', 'status', 'role', 'tenant', 'parent', 'interface', 'description')
fields = (
'pk', 'address', 'vrf', 'status', 'role', 'tenant', 'parent', 'interface', 'dns_name', 'description',
)
row_attrs = {
'class': lambda record: 'success' if not isinstance(record, IPAddress) else '',
}
Expand All @@ -352,7 +354,8 @@ class IPAddressDetailTable(IPAddressTable):

class Meta(IPAddressTable.Meta):
fields = (
'pk', 'address', 'vrf', 'status', 'role', 'tenant', 'nat_inside', 'parent', 'interface', 'description',
'pk', 'address', 'vrf', 'status', 'role', 'tenant', 'nat_inside', 'parent', 'interface', 'dns_name',
'description',
)


Expand Down
8 changes: 8 additions & 0 deletions netbox/ipam/validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.core.validators import RegexValidator


DNSValidator = RegexValidator(
regex='^[a-z]+$',
message='Only alphanumeric characters, hyphens, and periods are allowed in DNS names',
code='invalid'
)
4 changes: 4 additions & 0 deletions netbox/templates/ipam/ipaddress.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ <h1>{% block title %}{{ ipaddress }}{% endblock %}</h1>
{% endif %}
</td>
</tr>
<tr>
<td>DNS Name</td>
<td>{{ ipaddress.dns_name|placeholder }}</td>
</tr>
<tr>
<td>Description</td>
<td>{{ ipaddress.description|placeholder }}</td>
Expand Down
1 change: 1 addition & 0 deletions netbox/templates/ipam/ipaddress_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
{% render_field form.status %}
{% render_field form.role %}
{% render_field form.vrf %}
{% render_field form.dns_name %}
{% render_field form.description %}
</div>
</div>
Expand Down

0 comments on commit a026ec4

Please sign in to comment.