diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index a1441eb4b..caf27bad9 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -1273,7 +1273,7 @@ class ServicePortForm(forms.ModelForm, BootstrapMixin): class Meta: model = ServicePort - fields = ['ip_address', 'type', 'port', 'name', 'description'] + fields = ['ip_address', 'protocol', 'port', 'name', 'description'] help_texts = { 'port': '0-65535', 'name': 'Service running on this port', @@ -1287,6 +1287,7 @@ class ServicePortForm(forms.ModelForm, BootstrapMixin): super(ServicePortForm, self).__init__(*args, **kwargs) self.fields['ip_address'].queryset = IPAddress.objects.filter(interface__device=device) + # # Modules # diff --git a/netbox/ipam/api/serializers.py b/netbox/ipam/api/serializers.py index 7069496ce..d8b783bdc 100644 --- a/netbox/ipam/api/serializers.py +++ b/netbox/ipam/api/serializers.py @@ -181,18 +181,18 @@ class ServicePortSerializer(serializers.ModelSerializer): class Meta: model = ServicePort - fields = ['id', 'ip_address', 'port', 'type', 'name', 'description'] + fields = ['id', 'ip_address', 'port', 'protocol', 'name', 'description'] class ServicePortNestedSerializer(ServicePortSerializer): ip_address = IPAddressNestedSerializer() class Meta(ServicePortSerializer.Meta): - fields = ['id', 'ip_address', 'port', 'type'] + fields = ['id', 'ip_address', 'port', 'protocol'] class ServicePortDetailSerializer(ServicePortSerializer): ip_address = IPAddressNestedSerializer() class Meta(ServicePortSerializer.Meta): - fields = ['id', 'ip_address', 'port', 'type', 'name', 'description'] \ No newline at end of file + fields = ['id', 'ip_address', 'port', 'protocol', 'name', 'description'] diff --git a/netbox/ipam/api/views.py b/netbox/ipam/api/views.py index 917448db1..dbeffba5b 100644 --- a/netbox/ipam/api/views.py +++ b/netbox/ipam/api/views.py @@ -136,14 +136,14 @@ class IPAddressDetailView(CustomFieldModelAPIView, generics.RetrieveAPIView): # -# IP addresses +# Service Port # class ServicePortListView(generics.ListAPIView): """ List IP addresses (filterable) """ - queryset = ServicePort.objects.select_related('ip_address', 'port', 'type', 'name', 'description') + queryset = ServicePort.objects.select_related('ip_address', 'port', 'protocol', 'name', 'description') serializer_class = serializers.ServicePortSerializer @@ -151,7 +151,7 @@ class ServicePortDetailView(generics.RetrieveAPIView): """ Retrieve a single IP address """ - queryset = ServicePort.objects.select_related('ip_address', 'port', 'type', 'name', 'description') + queryset = ServicePort.objects.select_related('ip_address', 'port', 'protocol', 'name', 'description') serializer_class = serializers.ServicePortSerializer diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py index 72e20f4d3..58e9b1836 100644 --- a/netbox/ipam/forms.py +++ b/netbox/ipam/forms.py @@ -451,7 +451,7 @@ class IPAddressFilterForm(BootstrapMixin, CustomFieldFilterForm): class ServicePortForm(forms.ModelForm, BootstrapMixin): class Meta: model = ServicePort - fields = ['ip_address', 'type', 'port', 'name', 'description'] + fields = ['ip_address', 'protocol', 'port', 'name', 'description'] help_texts = { 'port': '0-65535', 'name': 'Service running on this port', diff --git a/netbox/ipam/migrations/0009_add_service_port.py b/netbox/ipam/migrations/0010_add_service_port.py similarity index 85% rename from netbox/ipam/migrations/0009_add_service_port.py rename to netbox/ipam/migrations/0010_add_service_port.py index 4d5a28068..3c35245a0 100644 --- a/netbox/ipam/migrations/0009_add_service_port.py +++ b/netbox/ipam/migrations/0010_add_service_port.py @@ -9,7 +9,7 @@ import django.db.models.deletion class Migration(migrations.Migration): dependencies = [ - ('ipam', '0008_prefix_change_order'), + ('ipam', '0009_ipaddress_add_status'), ] operations = [ @@ -19,7 +19,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('created', models.DateField(auto_now_add=True)), ('last_updated', models.DateTimeField(auto_now=True)), - ('type', models.PositiveSmallIntegerField(choices=[(0, b'TCP'), (1, b'UDP')], default=0)), + ('protocol', models.PositiveSmallIntegerField(choices=[(0, b'TCP'), (1, b'UDP')], default=0)), ('port', models.PositiveIntegerField()), ('name', models.CharField(max_length=30)), ('description', models.TextField(blank=True)), @@ -33,6 +33,6 @@ class Migration(migrations.Migration): ), migrations.AlterUniqueTogether( name='serviceport', - unique_together={('ip_address', 'port', 'type')}, + unique_together={('ip_address', 'port', 'protocol')}, ), ] diff --git a/netbox/ipam/models.py b/netbox/ipam/models.py index 542915e49..ea7d859c0 100644 --- a/netbox/ipam/models.py +++ b/netbox/ipam/models.py @@ -444,21 +444,21 @@ class IPAddress(CreatedUpdatedModel, CustomFieldModel): class ServicePort(CreatedUpdatedModel): """ A ServicePort represents a port on a specific IPAddress on which a service is running. - The port can be one of 2 predefined types - TCP or UDP. + The port can be one of 2 predefined protocols - TCP or UDP. A ServicePort is always associated with a specific IPAddress on a Device. If an user wants to specify a service running on all IP Addresses on a device, this can be done by assigning the port to the '0.0.0.0/32' IPAddress. - The combination of IPAddress, Port Number and Port Type is always unique for ServicePort. + The combination of IPAddress, Port Number and Port Protocol is always unique for ServicePort. - If a port number + port type combination is assigned to '0.0.0.0/32' IPAddress, + If a port number + port protocol combination is assigned to '0.0.0.0/32' IPAddress, it cannot be assigned to any other IPAddress on the same Device. """ ip_address = models.ForeignKey('IPAddress', related_name='service_ports', on_delete=models.CASCADE, blank=False, null=False, verbose_name='ip_address') - type = models.PositiveSmallIntegerField(choices=SERVICE_PORT_CHOICES, default=0) + protocol = models.PositiveSmallIntegerField(choices=SERVICE_PORT_CHOICES, default=0) port = models.PositiveIntegerField() name = models.CharField(max_length=30, blank=False, null=False) @@ -468,11 +468,11 @@ class ServicePort(CreatedUpdatedModel): ordering = ['ip_address', 'port'] verbose_name = 'Service Port' verbose_name_plural = 'Service Ports' - unique_together = ['ip_address', 'port', 'type'] + unique_together = ['ip_address', 'port', 'protocol'] def __unicode__(self): - port_type = dict(SERVICE_PORT_CHOICES).get(self.type) - return u'{}/{}'.format(self.port, port_type) + port_protocol = dict(SERVICE_PORT_CHOICES).get(self.protocol) + return u'{}/{}'.format(self.port, port_protocol) def get_absolute_url(self): return reverse('ipam:serviceport', args=[self.pk]) @@ -487,7 +487,7 @@ class ServicePort(CreatedUpdatedModel): # if port is already assigned on '0.0.0.0/32' # that means it is assigned on all IPs on the device port_assigned_on_all_ips = bool(ServicePort.objects.filter( - ip_address__address='0.0.0.0/32', port=self.port, type=self.type).exclude(pk=self.id)) + ip_address__address='0.0.0.0/32', port=self.port, protocol=self.protocol).exclude(pk=self.id)) if port_assigned_on_all_ips: raise ValidationError('Port already assigned on address 0.0.0.0/24') diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index adf7827bd..5721e98c2 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -662,7 +662,7 @@ class ServicePortEditView(PermissionRequiredMixin, ObjectEditView): permission_required = 'ipam.change_ipaddress' model = ServicePort form_class = forms.ServicePortForm - fields_initial = ['ip_address', 'port' 'type', 'name', 'description'] + fields_initial = ['ip_address', 'port' 'protocol', 'name', 'description'] template_name = 'ipam/serviceport_edit.html' def post(self, request, *args, **kwargs): diff --git a/netbox/templates/dcim/serviceport_assign.html b/netbox/templates/dcim/serviceport_assign.html index e5a0467fa..6f3786df9 100644 --- a/netbox/templates/dcim/serviceport_assign.html +++ b/netbox/templates/dcim/serviceport_assign.html @@ -24,13 +24,13 @@ {% render_form form %} -