@@ -153,14 +153,33 @@ def _netbox_copy_vm(self, virtual_machine):
153153 '--memory' , f'{ virtual_machine .memory } ' ,
154154 ])
155155
156- cmds .append ([
157- 'add_disk' ,
158- '--machine' , f'{ virtual_machine .aq_machine_name } ' ,
159- '--disk' , 'sda' ,
160- '--controller' , 'sata' ,
161- '--size' , f'{ virtual_machine .disk } ' ,
162- '--boot' ,
163- ])
156+ # Check if VM has any new-style virtual disks defined,
157+ # If so, use them and set the first as bootable,
158+ # If not, fall back to the classic single bootable disk method.
159+ virtual_disks = self .get_disks_from_device (virtual_machine )
160+ if virtual_disks :
161+ boot = True
162+ for disk in virtual_disks :
163+ cmd = [
164+ 'add_disk' ,
165+ '--machine' , f'{ virtual_machine .aq_machine_name } ' ,
166+ '--disk' , f'{ disk .name } ' ,
167+ '--controller' , 'sata' ,
168+ '--size' , f'{ disk .size } ' ,
169+ ]
170+ if boot :
171+ cmd .append ('--boot' )
172+ boot = False
173+ cmds .append (cmd )
174+ else :
175+ cmds .append ([
176+ 'add_disk' ,
177+ '--machine' , f'{ virtual_machine .aq_machine_name } ' ,
178+ '--disk' , 'sda' ,
179+ '--controller' , 'sata' ,
180+ '--size' , f'{ virtual_machine .disk } ' ,
181+ '--boot' ,
182+ ])
164183
165184 return cmds
166185
0 commit comments