Skip to content

Commit af1b216

Browse files
authored
BUG: Convert disk size from MB to GB for Aquilon (#49)
* BUG: Convert disk from MB to GB for Aquilon An update in NetBox has changed the disk size to be stored in MB instead of GB. This results in the code setting the disk size in Aquilon to be too large e.g. if a disk is 1024 MB in NetBox, the disk is set for the device as 1024 GB in Aquilon. Added a line to convert the disk size to GB. Netbox defines GB as SI/1000 and GiB as EIC/1024.
1 parent 5be43c5 commit af1b216

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

aquilon/netbox2aquilon.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,15 @@ def _netbox_copy_vm_disks(self, virtual_machine):
140140
if virtual_disks:
141141
boot = True
142142
for disk in virtual_disks:
143+
# Netbox stores virtual disk size in MB, Aquilon needs it in GB
144+
# For netbox 1000 MB = 1GB
145+
virtual_disk_gb = round(disk.size / 1000) # to nearest GB
143146
cmd = [
144147
'add_disk',
145148
'--machine', f'{virtual_machine.aq_machine_name}',
146149
'--disk', f'{disk.name}',
147150
'--controller', 'sata',
148-
'--size', f'{disk.size}',
151+
'--size', f'{virtual_disk_gb}',
149152
]
150153
if boot:
151154
cmd.append('--boot')
@@ -154,12 +157,14 @@ def _netbox_copy_vm_disks(self, virtual_machine):
154157
cmd += ['--comments', f'"{disk.description}"']
155158
cmds.append(cmd)
156159
else:
160+
# Netbox stores disk size in MB, Aquilon needs it in GB
161+
disk_gb = round(virtual_machine.disk / 1000) # to nearest GB
157162
cmds.append([
158163
'add_disk',
159164
'--machine', f'{virtual_machine.aq_machine_name}',
160165
'--disk', 'sda',
161166
'--controller', 'sata',
162-
'--size', f'{virtual_machine.disk}',
167+
'--size', f'{disk_gb}',
163168
'--boot',
164169
])
165170

aquilon/testdata/disks_virtual.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"name": "sda",
1313
"description": "",
14-
"size": 40,
14+
"size": 40000,
1515
"tags": [],
1616
"custom_fields": {},
1717
"created": "2025-06-02T13:43:40.552134Z",
@@ -29,7 +29,7 @@
2929
},
3030
"name": "sdb",
3131
"description": "",
32-
"size": 100,
32+
"size": 100000,
3333
"tags": [],
3434
"custom_fields": {},
3535
"created": "2025-06-02T13:43:49.494852Z",
@@ -47,7 +47,7 @@
4747
},
4848
"name": "sdc",
4949
"description": "/opt",
50-
"size": 100,
50+
"size": 100000,
5151
"tags": [],
5252
"custom_fields": {},
5353
"created": "2025-06-02T13:44:01.016349Z",

0 commit comments

Comments
 (0)