1919from typing import List
2020from typing import Optional
2121
22+ import yaml
23+
2224from ..module_utils import errors
2325from ..module_utils .disk import Disk
2426from ..module_utils .errors import DeviceNotUnique
@@ -218,7 +220,7 @@ def __init__(
218220 power_state = None ,
219221 power_action = None ,
220222 nics = None , # nics represents a list of type Nic
221- disks = None , # disks represents a list of type Nic
223+ disks = None , # disks represents a list of type Disk
222224 # boot_devices are stored as list of nics and/or disks internally.
223225 boot_devices = None ,
224226 attach_guest_tools_iso = False ,
@@ -423,6 +425,24 @@ def create_export_or_import_vm_payload(ansible_dict, cloud_init, is_export):
423425 payload ["template" ]["cloudInitData" ] = cloud_init
424426 return payload
425427
428+ @staticmethod
429+ def clone_add_user_data_to_cloud_init (cloud_init ):
430+ # Task 370 - the generated cloud-init should include a runcmd
431+ # to fix the grub UUID issue at first boot
432+
433+ user_data = cloud_init .get ("user_data" )
434+ if not user_data :
435+ return cloud_init
436+
437+ cloud_init ["user_data" ] = user_data .rstrip () + """
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+ return cloud_init
445+
426446 @classmethod
427447 def create_clone_vm_payload (
428448 cls ,
@@ -446,6 +466,7 @@ def create_clone_vm_payload(
446466 hypercore_tags .append (tag )
447467 data ["template" ]["tags" ] = "," .join (hypercore_tags )
448468 if cloud_init :
469+ cloud_init = cls .clone_add_user_data_to_cloud_init (cloud_init )
449470 data ["template" ]["cloudInitData" ] = cloud_init
450471 if preserve_mac_address :
451472 data ["template" ]["netDevs" ] = [
@@ -610,6 +631,13 @@ def find_disk(self, slot):
610631 if disk .slot == slot :
611632 return disk
612633
634+ # primary disk is the largest Virtio disk
635+ def get_primary_disk (self ):
636+ virtio_disks = [disk for disk in self .disk_list if disk .disk_type == "virtio_disk" ]
637+ if not virtio_disks :
638+ return None
639+ return max (virtio_disks , key = lambda disk : disk .size )
640+
613641 def post_vm_payload (self , rest_client , ansible_dict ):
614642 # The rest of the keys from VM_PAYLOAD_KEYS will get set properly automatically
615643 # Cloud init will be obtained through ansible_dict - If method will be reused outside of vm module,
0 commit comments