Skip to content

Commit b3fe545

Browse files
committed
adds config option to define VM values as decimal #400 #413
1 parent ee97fbb commit b3fe545

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

module/sources/vmware/config.py

+8
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,14 @@ def __init__(self):
374374
""",
375375
config_example="VB_LAST_BACKUP, VB_LAST_BACKUP2"
376376
),
377+
ConfigOption("vm_disk_and_ram_in_decimal",
378+
bool,
379+
description="""In NetBox version 4.1.0 and newer the VM disk and RAM values are displayed
380+
in power of 10 instead of power of 2. If this values is set to true 4GB of RAM will be
381+
set to a value of 4000 megabyte. If set to false 4GB of RAM will be reported as 4096MB.
382+
The same behavior also applies for VM disk sizes.""",
383+
default_value=True
384+
),
377385

378386
# removed settings
379387
ConfigOption("netbox_host_device_role",

module/sources/vmware/connection.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -2168,11 +2168,17 @@ def add_virtual_machine(self, obj):
21682168
# get vCenter tags
21692169
vm_tags.extend(self.collect_object_tags(obj))
21702170

2171+
# vm memory depending on setting
2172+
vm_memory = grab(obj, "config.hardware.memoryMB", fallback=0)
2173+
2174+
if self.settings.vm_disk_and_ram_in_decimal is True:
2175+
vm_memory = int(vm_memory / 1024 * 1000)
2176+
21712177
vm_data = {
21722178
"name": name,
21732179
"cluster": nb_cluster_object,
21742180
"status": status,
2175-
"memory": grab(obj, "config.hardware.memoryMB"),
2181+
"memory": vm_memory,
21762182
"vcpus": grab(obj, "config.hardware.numCPU")
21772183
}
21782184

@@ -2270,6 +2276,8 @@ def add_virtual_machine(self, obj):
22702276
# since NetBox 4.1.0 disk size is represented in MB
22712277
else:
22722278
disk_size = int(disk_size_in_kb / 1024)
2279+
if self.settings.vm_disk_and_ram_in_decimal:
2280+
disk_size = int(disk_size / 1024 * 1000)
22732281

22742282
disk_data.append({
22752283
"name": grab(vm_device, "deviceInfo.label"),

settings-example.ini

+6
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,12 @@ password = super-secret
378378
; Any custom attribute with a matching attribute key will be excluded from sync.
379379
;custom_attribute_exclude = VB_LAST_BACKUP, VB_LAST_BACKUP2
380380

381+
; In NetBox version 4.1.0 and newer the VM disk and RAM values are displayed in power of
382+
; 10 instead of power of 2. If this values is set to true 4GB of RAM will be set to a
383+
; value of 4000 megabyte. If set to false 4GB of RAM will be reported as 4096MB. The same
384+
; behavior also applies for VM disk sizes.
385+
;vm_disk_and_ram_in_decimal = True
386+
381387
[source/my-redfish-example]
382388

383389
; Defines if this source is enabled or not

0 commit comments

Comments
 (0)