Skip to content

Commit

Permalink
added cable IDs for network, power and console connections netbox-com…
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasDOTwtf committed Jun 29, 2018
1 parent a1f624c commit 22d2bb1
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CUSTOM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
postgres=# \c netbox
Sie sind jetzt verbunden mit der Datenbank »netbox« als Benutzer »postgres«.
netbox=# ALTER TABLE public.dcim_interfaceconnection ADD COLUMN connection_comments text;
ALTER TABLE public.dcim_consoleport ADD COLUMN connection_comments text;
ALTER TABLE public.dcim_powerport ADD COLUMN connection_comments text;

10 changes: 7 additions & 3 deletions netbox/dcim/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1300,10 +1300,11 @@ class ConsolePortConnectionForm(BootstrapMixin, ChainedFieldsMixin, forms.ModelF
disabled_indicator='connected_console',
)
)
connection_comments = forms.CharField(max_length=100, required=False, label='Cable ID')

class Meta:
model = ConsolePort
fields = ['site', 'rack', 'console_server', 'livesearch', 'cs_port', 'connection_status']
fields = ['site', 'rack', 'console_server', 'livesearch', 'cs_port', 'connection_status', 'connection_comments']
labels = {
'cs_port': 'Port',
'connection_status': 'Status',
Expand Down Expand Up @@ -1565,13 +1566,15 @@ class PowerPortConnectionForm(BootstrapMixin, ChainedFieldsMixin, forms.ModelFor
disabled_indicator='connected_port'
)
)
connection_comments = forms.CharField(max_length=100, required=False, label='Cable ID')

class Meta:
model = PowerPort
fields = ['site', 'rack', 'pdu', 'livesearch', 'power_outlet', 'connection_status']
fields = ['site', 'rack', 'pdu', 'livesearch', 'power_outlet', 'connection_status', 'connection_comments']
labels = {
'power_outlet': 'Outlet',
'connection_status': 'Status',
'connection_comments': 'Cable-ID'
}

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -1888,6 +1891,7 @@ class InterfaceBulkDisconnectForm(ConfirmationForm):
#

class InterfaceConnectionForm(BootstrapMixin, ChainedFieldsMixin, forms.ModelForm):
connection_comments = forms.CharField(max_length=100, required=False, label='Cable ID')
interface_a = forms.ChoiceField(
choices=[],
widget=SelectWithDisabled,
Expand Down Expand Up @@ -1952,7 +1956,7 @@ class InterfaceConnectionForm(BootstrapMixin, ChainedFieldsMixin, forms.ModelFor

class Meta:
model = InterfaceConnection
fields = ['interface_a', 'site_b', 'rack_b', 'device_b', 'interface_b', 'livesearch', 'connection_status']
fields = ['interface_a', 'site_b', 'rack_b', 'device_b', 'interface_b', 'livesearch', 'connection_status', 'connection_comments']

def __init__(self, device_a, *args, **kwargs):

Expand Down
10 changes: 6 additions & 4 deletions netbox/dcim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,8 +1173,9 @@ class ConsolePort(models.Model):
cs_port = models.OneToOneField('ConsoleServerPort', related_name='connected_console', on_delete=models.SET_NULL,
verbose_name='Console server port', blank=True, null=True)
connection_status = models.NullBooleanField(choices=CONNECTION_STATUS_CHOICES, default=CONNECTION_STATUS_CONNECTED)
connection_comments = models.TextField(blank=True)

csv_headers = ['console_server', 'cs_port', 'device', 'console_port', 'connection_status']
csv_headers = ['console_server', 'cs_port', 'device', 'console_port', 'connection_comments']

class Meta:
ordering = ['device', 'name']
Expand Down Expand Up @@ -1255,8 +1256,8 @@ class PowerPort(models.Model):
power_outlet = models.OneToOneField('PowerOutlet', related_name='connected_port', on_delete=models.SET_NULL,
blank=True, null=True)
connection_status = models.NullBooleanField(choices=CONNECTION_STATUS_CHOICES, default=CONNECTION_STATUS_CONNECTED)

csv_headers = ['pdu', 'power_outlet', 'device', 'power_port', 'connection_status']
connection_comments = models.TextField(blank=True)
csv_headers = ['pdu', 'power_outlet', 'device', 'power_port', 'connection_status', 'connection_comments']

class Meta:
ordering = ['device', 'name']
Expand Down Expand Up @@ -1525,10 +1526,11 @@ class InterfaceConnection(models.Model):
"""
interface_a = models.OneToOneField('Interface', related_name='connected_as_a', on_delete=models.CASCADE)
interface_b = models.OneToOneField('Interface', related_name='connected_as_b', on_delete=models.CASCADE)
connection_comments = models.TextField(blank=True)
connection_status = models.BooleanField(choices=CONNECTION_STATUS_CHOICES, default=CONNECTION_STATUS_CONNECTED,
verbose_name='Status')

csv_headers = ['device_a', 'interface_a', 'device_b', 'interface_b', 'connection_status']
csv_headers = ['device_a', 'interface_a', 'device_b', 'interface_b', 'connection_status', 'connection_comments']

def clean(self):
try:
Expand Down
4 changes: 4 additions & 0 deletions netbox/dcim/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ def post(self, request, pk):
cs_port = consoleport.cs_port
consoleport.cs_port = None
consoleport.connection_status = None
consoleport.connection_comments = None
consoleport.save()
msg = 'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
consoleport.device.get_absolute_url(),
Expand Down Expand Up @@ -1286,6 +1287,7 @@ def post(self, request, pk):
consoleport = consoleserverport.connected_console
consoleport.cs_port = None
consoleport.connection_status = None
consoleport.connection_comments = None
consoleport.save()
msg = 'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
consoleport.device.get_absolute_url(),
Expand Down Expand Up @@ -1431,6 +1433,7 @@ def post(self, request, pk):
power_outlet = powerport.power_outlet
powerport.power_outlet = None
powerport.connection_status = None
powerport.connection_comments = None
powerport.save()
msg = 'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
powerport.device.get_absolute_url(),
Expand Down Expand Up @@ -1570,6 +1573,7 @@ def post(self, request, pk):
powerport = poweroutlet.connected_port
powerport.power_outlet = None
powerport.connection_status = None
powerport.connection_comments = None
powerport.save()
msg = 'Disconnected <a href="{}">{}</a> {} from <a href="{}">{}</a> {}'.format(
powerport.device.get_absolute_url(),
Expand Down
1 change: 1 addition & 0 deletions netbox/templates/dcim/consoleport_connect.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
</div>
{% render_field form.cs_port %}
{% render_field form.connection_status %}
{% render_field form.connection_comments %}
</div>
</div>
<div class="form-group">
Expand Down
4 changes: 2 additions & 2 deletions netbox/templates/dcim/device.html
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@
<th>Description</th>
<th>MTU</th>
<th>MAC Address</th>
<th colspan="2">Connection</th>
<th colspan="3">Connection</th>
<th></th>
</tr>
</thead>
Expand Down Expand Up @@ -515,7 +515,7 @@
<th class="pk"><input type="checkbox" class="toggle" title="Toggle all" /></th>
{% endif %}
<th>Name</th>
<th colspan="2">Connection</th>
<th colspan="3">Connection</th>
<th></th>
</tr>
</thead>
Expand Down
7 changes: 6 additions & 1 deletion netbox/templates/dcim/inc/consoleport.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
<td>
{{ cp.cs_port }}
</td>
<td>
{% if cp.connection_comments %}
Cable ID: {{ cp.connection_comments }}
{% endif %}
</td>
{% else %}
<td colspan="2">
<td colspan="3">
<span class="text-muted">Not connected</span>
</td>
{% endif %}
Expand Down
7 changes: 6 additions & 1 deletion netbox/templates/dcim/inc/consoleserverport.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
<td>
{{ csp.connected_console }}
</td>
<td>
{% if csp.connected_console.connection_comments %}
Cable ID: {{ csp.connected_console.connection_comments }}
{% endif %}
</td>
{% else %}
<td colspan="2">
<td colspan="3">
<span class="text-muted">Not connected</span>
</td>
{% endif %}
Expand Down
9 changes: 7 additions & 2 deletions netbox/templates/dcim/inc/interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@
<td>
<span title="{{ connected_iface.get_form_factor_display }}">{{ connected_iface }}</span>
</td>
<td>
{% if iface.connection.connection_comments %}
Cable ID: {{ iface.connection.connection_comments }}
{% endif %}
</td>
{% endwith %}
{% elif iface.circuit_termination %}
{% with iface.circuit_termination.get_peer_termination as peer_termination %}
<td colspan="2">
<td colspan="3">
<i class="fa fa-fw fa-globe" title="Circuit"></i>
{% if peer_termination %}
{% if peer_termination.interface %}
Expand All @@ -67,7 +72,7 @@
</td>
{% endwith %}
{% else %}
<td colspan="2">
<td colspan="3">
<span class="text-muted">Not connected</span>
</td>
{% endif %}
Expand Down
3 changes: 3 additions & 0 deletions netbox/templates/dcim/inc/poweroutlet.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
</td>
<td>
{{ po.connected_port }}
{% if po.connected_port.connection_comments %}
Cable ID: {{ po.connected_port.connection_comments }}
{% endif %}
</td>
{% else %}
<td colspan="2">
Expand Down
7 changes: 6 additions & 1 deletion netbox/templates/dcim/inc/powerport.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
</td>
<td>
{{ pp.power_outlet }}
</td>
<td>
{% if pp.connection_comments %}
Cable ID: {{ pp.connection_comments }}
{% endif %}
</td>
{% else %}
<td colspan="2">
<td colspan="3">
<span class="text-muted">Not connected</span>
</td>
{% endif %}
Expand Down
1 change: 1 addition & 0 deletions netbox/templates/dcim/interfaceconnection_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ <h1>Connect Interfaces</h1>
<div class="row">
<div class="col-md-4 col-md-offset-4">
{% render_field form.connection_status %}
{% render_field form.connection_comments %}
</div>
</div>
<div class="text-center">
Expand Down
1 change: 1 addition & 0 deletions netbox/templates/dcim/powerport_connect.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
</div>
{% render_field form.power_outlet %}
{% render_field form.connection_status %}
{% render_field form.connection_comments %}
</div>
</div>
<div class="form-group">
Expand Down

0 comments on commit 22d2bb1

Please sign in to comment.