mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-28 03:16:25 -06:00
Rename _UNIT_DIVISOR to _BASE_UNIT
This commit is contained in:
parent
c35db10f22
commit
27b76870c4
@ -223,8 +223,8 @@ SESSION_FILE_PATH = None
|
||||
|
||||
# By default the memory and disk sizes are displayed using base 10 (e.g. 1000 MB = 1 GB).
|
||||
# If you would like to use base 2 (e.g. 1024 MB = 1 GB) set this to 1024.
|
||||
DISK_UNIT_DIVISOR = 1024
|
||||
RAM_UNIT_DIVISOR = 1024
|
||||
DISK_BASE_UNIT = 1024
|
||||
RAM_BASE_UNIT = 1024
|
||||
|
||||
# By default, uploaded media is stored on the local filesystem. Using Django-storages is also supported. Provide the
|
||||
# class path of the storage driver in STORAGE_BACKEND and any configuration options in STORAGE_CONFIG. For example:
|
||||
|
@ -176,8 +176,8 @@ STORAGE_BACKEND = getattr(configuration, 'STORAGE_BACKEND', None)
|
||||
STORAGE_CONFIG = getattr(configuration, 'STORAGE_CONFIG', {})
|
||||
TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC')
|
||||
TRANSLATION_ENABLED = getattr(configuration, 'TRANSLATION_ENABLED', True)
|
||||
DISK_UNIT_DIVISOR = getattr(configuration, 'DISK_UNIT_DIVISOR', 1000)
|
||||
RAM_UNIT_DIVISOR = getattr(configuration, 'MEMORY_UNIT_DIVISOR', 1000)
|
||||
DISK_BASE_UNIT = getattr(configuration, 'DISK_BASE_UNIT', 1000)
|
||||
RAM_BASE_UNIT = getattr(configuration, 'MEMORY_UNIT_DIVISOR', 1000)
|
||||
|
||||
# Load any dynamic configuration parameters which have been hard-coded in the configuration file
|
||||
for param in CONFIG_PARAMS:
|
||||
|
@ -8,7 +8,7 @@ from django.urls import NoReverseMatch, reverse
|
||||
from core.models import ObjectType
|
||||
from utilities.forms import get_selected_values, TableConfigForm
|
||||
from utilities.views import get_viewname
|
||||
from netbox.settings import DISK_UNIT_DIVISOR, RAM_UNIT_DIVISOR
|
||||
from netbox.settings import DISK_BASE_UNIT, RAM_BASE_UNIT
|
||||
|
||||
__all__ = (
|
||||
'applied_filters',
|
||||
@ -108,17 +108,17 @@ def _humanize_megabytes(mb, divisor=1000):
|
||||
def humanize_disk_megabytes(mb):
|
||||
"""
|
||||
Express a number of megabytes in the most suitable unit (e.g. gigabytes, terabytes, etc.).
|
||||
Use the DISK_UNIT_DIVISOR setting to determine the divisor. Default is 1000.
|
||||
Use the DISK_BASE_UNIT setting to determine the divisor. Default is 1000.
|
||||
"""
|
||||
return _humanize_megabytes(mb, DISK_UNIT_DIVISOR)
|
||||
return _humanize_megabytes(mb, DISK_BASE_UNIT)
|
||||
|
||||
@register.filter()
|
||||
def humanize_ram_megabytes(mb):
|
||||
"""
|
||||
Express a number of megabytes in the most suitable unit (e.g. gigabytes, terabytes, etc.).
|
||||
Use the RAM_UNIT_DIVISOR setting to determine the divisor. Default is 1000.
|
||||
Use the RAM_BASE_UNIT setting to determine the divisor. Default is 1000.
|
||||
"""
|
||||
return _humanize_megabytes(mb, RAM_UNIT_DIVISOR)
|
||||
return _humanize_megabytes(mb, RAM_BASE_UNIT)
|
||||
|
||||
|
||||
@register.filter()
|
||||
|
@ -1,13 +1,13 @@
|
||||
from django.db import migrations
|
||||
from django.db.models import F, Sum
|
||||
from netbox.settings import DISK_UNIT_DIVISOR
|
||||
from netbox.settings import DISK_BASE_UNIT
|
||||
|
||||
def convert_disk_size(apps, schema_editor):
|
||||
VirtualMachine = apps.get_model('virtualization', 'VirtualMachine')
|
||||
VirtualMachine.objects.filter(disk__isnull=False).update(disk=F('disk') * DISK_UNIT_DIVISOR)
|
||||
VirtualMachine.objects.filter(disk__isnull=False).update(disk=F('disk') * DISK_BASE_UNIT)
|
||||
|
||||
VirtualDisk = apps.get_model('virtualization', 'VirtualDisk')
|
||||
VirtualDisk.objects.filter(size__isnull=False).update(size=F('size') * DISK_UNIT_DIVISOR)
|
||||
VirtualDisk.objects.filter(size__isnull=False).update(size=F('size') * DISK_BASE_UNIT)
|
||||
|
||||
# Recalculate disk size on all VMs with virtual disks
|
||||
id_list = VirtualDisk.objects.values_list('virtual_machine_id').distinct()
|
||||
|
Loading…
Reference in New Issue
Block a user