Просмотр исходного кода

Define `is_path_endpoint` and `is_connected_endpoint` separately, as a CableTermination is a possible connected endpoint but not always the end of the path.

Sander Steffann 5 лет назад
Родитель
Сommit
715ddc6b02
3 измененных файлов с 18 добавлено и 1 удалено
  1. 3 0
      netbox/circuits/models.py
  2. 14 0
      netbox/dcim/models/device_components.py
  3. 1 1
      netbox/dcim/signals.py

+ 3 - 0
netbox/circuits/models.py

@@ -303,6 +303,9 @@ class CircuitTermination(CableTermination):
     # Paths do not end on cable terminations, they continue at the other end of the circuit
     # Paths do not end on cable terminations, they continue at the other end of the circuit
     is_path_endpoint = False
     is_path_endpoint = False
 
 
+    # But they are a possible connected endpoint
+    is_connected_endpoint = True
+
     class Meta:
     class Meta:
         ordering = ['circuit', 'term_side']
         ordering = ['circuit', 'term_side']
         unique_together = ['circuit', 'term_side']
         unique_together = ['circuit', 'term_side']

+ 14 - 0
netbox/dcim/models/device_components.py

@@ -86,8 +86,12 @@ class CableTermination(models.Model):
         object_id_field='termination_b_id'
         object_id_field='termination_b_id'
     )
     )
 
 
+    # Whether this class is always an endpoint for cable traces
     is_path_endpoint = True
     is_path_endpoint = True
 
 
+    # Whether this class can be a connected endpoint
+    is_connected_endpoint = True
+
     class Meta:
     class Meta:
         abstract = True
         abstract = True
 
 
@@ -895,8 +899,13 @@ class FrontPort(CableTermination, ComponentModel):
     tags = TaggableManager(through=TaggedItem)
     tags = TaggableManager(through=TaggedItem)
 
 
     csv_headers = ['device', 'name', 'type', 'rear_port', 'rear_port_position', 'description']
     csv_headers = ['device', 'name', 'type', 'rear_port', 'rear_port_position', 'description']
+
+    # Whether this class is always an endpoint for cable traces
     is_path_endpoint = False
     is_path_endpoint = False
 
 
+    # Whether this class can be a connected endpoint
+    is_connected_endpoint = False
+
     class Meta:
     class Meta:
         ordering = ('device', '_name')
         ordering = ('device', '_name')
         unique_together = (
         unique_together = (
@@ -963,8 +972,13 @@ class RearPort(CableTermination, ComponentModel):
     tags = TaggableManager(through=TaggedItem)
     tags = TaggableManager(through=TaggedItem)
 
 
     csv_headers = ['device', 'name', 'type', 'positions', 'description']
     csv_headers = ['device', 'name', 'type', 'positions', 'description']
+
+    # Whether this class is always an endpoint for cable traces
     is_path_endpoint = False
     is_path_endpoint = False
 
 
+    # Whether this class can be a connected endpoint
+    is_connected_endpoint = False
+
     class Meta:
     class Meta:
         ordering = ('device', '_name')
         ordering = ('device', '_name')
         unique_together = ('device', 'name')
         unique_together = ('device', 'name')

+ 1 - 1
netbox/dcim/signals.py

@@ -63,7 +63,7 @@ def update_connected_endpoints(instance, **kwargs):
         endpoint_a = path[0][0]
         endpoint_a = path[0][0]
         endpoint_b = path[-1][2] if not split_ends and not position_stack else None
         endpoint_b = path[-1][2] if not split_ends and not position_stack else None
 
 
-        if getattr(endpoint_a, 'is_path_endpoint', False) and getattr(endpoint_b, 'is_path_endpoint', False):
+        if getattr(endpoint_a, 'is_connected_endpoint', False) and getattr(endpoint_b, 'is_connected_endpoint', False):
             logger.debug("Updating path endpoints: {} <---> {}".format(endpoint_a, endpoint_b))
             logger.debug("Updating path endpoints: {} <---> {}".format(endpoint_a, endpoint_b))
             endpoint_a.connected_endpoint = endpoint_b
             endpoint_a.connected_endpoint = endpoint_b
             endpoint_a.connection_status = path_status
             endpoint_a.connection_status = path_status