mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-28 03:16:25 -06:00
Rename ServicePort.type to ServicePort.protocol
This commit is contained in:
parent
2a3c096af3
commit
4bf59c982e
@ -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
|
||||
#
|
||||
|
@ -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']
|
||||
fields = ['id', 'ip_address', 'port', 'protocol', 'name', 'description']
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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')},
|
||||
),
|
||||
]
|
@ -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')
|
||||
|
||||
|
@ -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):
|
||||
|
@ -24,13 +24,13 @@
|
||||
{% render_form form %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="form-group">
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<button type="submit" name="_create" class="btn btn-primary">Create</button>
|
||||
<button type="submit" name="_addanother" class="btn btn-primary">Create and Add More</button>
|
||||
<a href="{{ cancel_url }}" class="btn btn-default">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -8,7 +8,7 @@
|
||||
<div class="panel-body">
|
||||
{% render_field form.ip_address %}
|
||||
{% render_field form.port %}
|
||||
{% render_field form.type %}
|
||||
{% render_field form.protocol %}
|
||||
{% render_field form.name %}
|
||||
{% if obj %}
|
||||
<div class="form-group">
|
||||
|
Loading…
Reference in New Issue
Block a user