diff --git a/netbox/circuits/forms.py b/netbox/circuits/forms.py index edf974d62..7046b8ec3 100644 --- a/netbox/circuits/forms.py +++ b/netbox/circuits/forms.py @@ -105,7 +105,7 @@ class CircuitForm(forms.ModelForm, BootstrapMixin): 'cid': "Unique circuit ID", 'install_date': "Format: YYYY-MM-DD", 'port_speed': "Physical circuit speed", - 'commit_rate': "Commited rate (in Mbps)", + 'commit_rate': "Commited rate", 'xconnect_id': "ID of the local cross-connect", 'pp_info': "Patch panel ID and port number(s)" } diff --git a/netbox/circuits/models.py b/netbox/circuits/models.py index b82706e66..66d3b07ab 100644 --- a/netbox/circuits/models.py +++ b/netbox/circuits/models.py @@ -91,3 +91,28 @@ class Circuit(models.Model): self.xconnect_id, self.pp_info, ]) + + def _humanize_speed(self, speed): + """ + Humanize speeds given in Kbps (e.g. 10000000 becomes '10 Gbps') + """ + if speed >= 1000000000 and speed % 1000000000 == 0: + return '{} Tbps'.format(speed / 1000000000) + elif speed >= 1000000 and speed % 1000000 == 0: + return '{} Gbps'.format(speed / 1000000) + elif speed >= 1000 and speed % 1000 == 0: + return '{} Mbps'.format(speed / 1000) + elif speed >= 1000: + return '{} Mbps'.format(float(speed) / 1000) + else: + return '{} Kbps'.format(speed) + + @property + def port_speed_human(self): + return self._humanize_speed(self.port_speed) + + @property + def commit_rate_human(self): + if not self.commit_rate: + return '' + return self._humanize_speed(self.commit_rate) diff --git a/netbox/circuits/tables.py b/netbox/circuits/tables.py index 45e2b80d8..0a0b92d43 100644 --- a/netbox/circuits/tables.py +++ b/netbox/circuits/tables.py @@ -62,12 +62,12 @@ class CircuitTable(tables.Table): type = tables.Column(verbose_name='Type') provider = tables.LinkColumn('circuits:provider', args=[Accessor('provider.slug')], verbose_name='Provider') site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')], verbose_name='Site') - port_speed = tables.Column(verbose_name='Port Speed') - commit_rate = tables.Column(verbose_name='Commit (Mbps)') + port_speed_human = tables.Column(verbose_name='Port Speed') + commit_rate_human = tables.Column(verbose_name='Commit Rate') class Meta: model = Circuit - fields = ('pk', 'cid', 'type', 'provider', 'site', 'port_speed', 'commit_rate') + fields = ('pk', 'cid', 'type', 'provider', 'site', 'port_speed_human', 'commit_rate_human') empty_text = "No circuits found." attrs = { 'class': 'table table-hover', diff --git a/netbox/templates/circuits/circuit.html b/netbox/templates/circuits/circuit.html index d2881932f..0d354549d 100644 --- a/netbox/templates/circuits/circuit.html +++ b/netbox/templates/circuits/circuit.html @@ -79,11 +79,11 @@