diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 3c99434a9..296cf085c 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -6,6 +6,7 @@ * [#6620](https://github.com/netbox-community/netbox/issues/6620) - Show assigned VMs count under device role view * [#6666](https://github.com/netbox-community/netbox/issues/6666) - Show management-only status under interface detail view +* [#6667](https://github.com/netbox-community/netbox/issues/6667) - Display VM memory as GB/TB as appropriate ### Bug Fixes diff --git a/netbox/templates/virtualization/virtualmachine.html b/netbox/templates/virtualization/virtualmachine.html index 03512d02f..a5ce03aab 100644 --- a/netbox/templates/virtualization/virtualmachine.html +++ b/netbox/templates/virtualization/virtualmachine.html @@ -138,7 +138,7 @@ Memory {% if object.memory %} - {{ object.memory }} MB + {{ object.memory|humanize_megabytes }} {% else %} {% endif %} diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 01dce8479..49d8323e9 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -129,6 +129,20 @@ def humanize_speed(speed): return '{} Kbps'.format(speed) +@register.filter() +def humanize_megabytes(mb): + """ + Express a number of megabytes in the most suitable unit (e.g. gigabytes or terabytes). + """ + if not mb: + return '' + if mb >= 1048576: + return f'{int(mb / 1048576)} TB' + if mb >= 1024: + return f'{int(mb / 1024)} GB' + return f'{mb} MB' + + @register.filter() def tzoffset(value): """