Skip to content

Commit

Permalink
adds config option to define VM values as decimal #400 #413
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-Ricardo committed Sep 23, 2024
1 parent ee97fbb commit b3fe545
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions module/sources/vmware/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@ def __init__(self):
""",
config_example="VB_LAST_BACKUP, VB_LAST_BACKUP2"
),
ConfigOption("vm_disk_and_ram_in_decimal",
bool,
description="""In NetBox version 4.1.0 and newer the VM disk and RAM values are displayed
in power of 10 instead of power of 2. If this values is set to true 4GB of RAM will be
set to a value of 4000 megabyte. If set to false 4GB of RAM will be reported as 4096MB.
The same behavior also applies for VM disk sizes.""",
default_value=True
),

# removed settings
ConfigOption("netbox_host_device_role",
Expand Down
10 changes: 9 additions & 1 deletion module/sources/vmware/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2168,11 +2168,17 @@ def add_virtual_machine(self, obj):
# get vCenter tags
vm_tags.extend(self.collect_object_tags(obj))

# vm memory depending on setting
vm_memory = grab(obj, "config.hardware.memoryMB", fallback=0)

if self.settings.vm_disk_and_ram_in_decimal is True:
vm_memory = int(vm_memory / 1024 * 1000)

vm_data = {
"name": name,
"cluster": nb_cluster_object,
"status": status,
"memory": grab(obj, "config.hardware.memoryMB"),
"memory": vm_memory,
"vcpus": grab(obj, "config.hardware.numCPU")
}

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

disk_data.append({
"name": grab(vm_device, "deviceInfo.label"),
Expand Down
6 changes: 6 additions & 0 deletions settings-example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ password = super-secret
; Any custom attribute with a matching attribute key will be excluded from sync.
;custom_attribute_exclude = VB_LAST_BACKUP, VB_LAST_BACKUP2

; In NetBox version 4.1.0 and newer the VM disk and RAM values are displayed in power of
; 10 instead of power of 2. If this values is set to true 4GB of RAM will be set to a
; value of 4000 megabyte. If set to false 4GB of RAM will be reported as 4096MB. The same
; behavior also applies for VM disk sizes.
;vm_disk_and_ram_in_decimal = True

[source/my-redfish-example]

; Defines if this source is enabled or not
Expand Down

0 comments on commit b3fe545

Please sign in to comment.