@@ -218,7 +218,7 @@ def __init__(
218218 power_state = None ,
219219 power_action = None ,
220220 nics = None , # nics represents a list of type Nic
221- disks = None , # disks represents a list of type Nic
221+ disks = None , # disks represents a list of type Disk
222222 # boot_devices are stored as list of nics and/or disks internally.
223223 boot_devices = None ,
224224 attach_guest_tools_iso = False ,
@@ -423,6 +423,27 @@ def create_export_or_import_vm_payload(ansible_dict, cloud_init, is_export):
423423 payload ["template" ]["cloudInitData" ] = cloud_init
424424 return payload
425425
426+ @staticmethod
427+ def clone_add_user_data_to_cloud_init (cloud_init ):
428+ # Task 370 - the generated cloud-init should include a runcmd
429+ # to fix the grub UUID issue at first boot
430+
431+ user_data = cloud_init .get ("user_data" )
432+ if not user_data :
433+ return cloud_init
434+
435+ cloud_init ["user_data" ] = (
436+ user_data .rstrip ()
437+ + """
438+
439+ runcmd:
440+ - sed -i 's/^GRUB_DISABLE_LINUX_UUID=true/#GRUB_DISABLE_LINUX_UUID=true/' /etc/default/grub
441+ - update-grub
442+ """
443+ )
444+
445+ return cloud_init
446+
426447 @classmethod
427448 def create_clone_vm_payload (
428449 cls ,
@@ -446,6 +467,7 @@ def create_clone_vm_payload(
446467 hypercore_tags .append (tag )
447468 data ["template" ]["tags" ] = "," .join (hypercore_tags )
448469 if cloud_init :
470+ cloud_init = cls .clone_add_user_data_to_cloud_init (cloud_init )
449471 data ["template" ]["cloudInitData" ] = cloud_init
450472 if preserve_mac_address :
451473 data ["template" ]["netDevs" ] = [
@@ -610,6 +632,13 @@ def find_disk(self, slot):
610632 if disk .slot == slot :
611633 return disk
612634
635+ # primary disk is the largest Virtio disk
636+ def get_primary_disk (self ):
637+ virtio_disks = [disk for disk in self .disk_list if disk .disk_type == "virtio_disk" ]
638+ if not virtio_disks :
639+ return None
640+ return max (virtio_disks , key = lambda disk : disk .size )
641+
613642 def post_vm_payload (self , rest_client , ansible_dict ):
614643 # The rest of the keys from VM_PAYLOAD_KEYS will get set properly automatically
615644 # Cloud init will be obtained through ansible_dict - If method will be reused outside of vm module,
0 commit comments