1111
1212__metaclass__ = type
1313
14+ import yaml
1415import base64
1516from time import sleep
1617from time import time
@@ -423,6 +424,24 @@ def create_export_or_import_vm_payload(ansible_dict, cloud_init, is_export):
423424 payload ["template" ]["cloudInitData" ] = cloud_init
424425 return payload
425426
427+ def clone_add_user_data_to_cloud_init (cloud_init ):
428+ # Task 370 - the generated cloud-init should include a runcmd to fix the grub UUID issue at first boot
429+ if not cloud_init .get ("user_data" ):
430+ return cloud_init
431+
432+ config = yaml .safe_load (cloud_init ["user_data" ]) or {}
433+
434+ runcmd = config .setdefault ("runcmd" , [])
435+ runcmd .extend (
436+ [
437+ "sed -i 's/^GRUB_DISABLE_LINUX_UUID=true/#GRUB_DISABLE_LINUX_UUID=true/' /etc/default/grub" ,
438+ "update-grub" ,
439+ ]
440+ )
441+ # Keeps the header, safe_dump removes it
442+ cloud_init ["user_data" ] = "#cloud-config\n " + yaml .safe_dump (config )
443+ return cloud_init
444+
426445 @classmethod
427446 def create_clone_vm_payload (
428447 cls ,
@@ -446,6 +465,7 @@ def create_clone_vm_payload(
446465 hypercore_tags .append (tag )
447466 data ["template" ]["tags" ] = "," .join (hypercore_tags )
448467 if cloud_init :
468+ cloud_init = clone_add_user_data_to_cloud_init (cloud_init )
449469 data ["template" ]["cloudInitData" ] = cloud_init
450470 if preserve_mac_address :
451471 data ["template" ]["netDevs" ] = [
@@ -612,7 +632,10 @@ def find_disk(self, slot):
612632
613633 # primary disk is the largest Virtio disk
614634 def get_primary_disk (self ):
615- return max (self .disk_list , key = lambda disk : disk .size )
635+ virtio_disks = [disk for disk in self .disk_list if disk .disk_type == "virtio_disk" ]
636+ if not virtio_disks :
637+ return None
638+ return max (virtio_disks , key = lambda disk : disk .size )
616639
617640 def post_vm_payload (self , rest_client , ansible_dict ):
618641 # The rest of the keys from VM_PAYLOAD_KEYS will get set properly automatically
0 commit comments