@@ -301,3 +301,44 @@ from
301301 left join
302302 ` cloud` .` resource_count` secondary_storage_count ON domain .id = secondary_storage_count .domain_id
303303 and secondary_storage_count .type = ' secondary_storage' ;
304+
305+ -- Create a temporary table to use as a list of new guest_os to insert.
306+ CREATE TEMPORARY TABLE temp_new_guest_os_to_insert (name varchar (50 ));
307+
308+ -- Populate the temporary table with the new guest_os to insert.
309+ INSERT INTO temp_new_guest_os_to_insert (name)
310+ VALUES
311+ (' Ubuntu 20.04 LTS' ),
312+ (' Ubuntu 21.04' ),
313+ (' pfSense 2.4' ),
314+ (' OpenBSD 6.7' ),
315+ (' OpenBSD 6.8' ),
316+ (' AlmaLinux 8.3' );
317+
318+ -- Insert the new guest_os if they do not already exists in the table.
319+ INSERT INTO cloud .guest_os (uuid, category_id, display_name, created, is_user_defined)
320+ SELECT UUID(), ' 1' , new_guest_os .name , now(), ' 0'
321+ FROM temp_new_guest_os_to_insert AS new_guest_os
322+ WHERE NOT EXISTS (SELECT 1
323+ FROM cloud .guest_os
324+ WHERE cloud .guest_os .category_id = 1
325+ AND cloud .guest_os .is_user_defined = 0
326+ AND cloud .guest_os .display_name = new_guest_os .name );
327+
328+ -- Insert the new guest_os_hypervisor if they do not already exists in the table.
329+ INSERT INTO cloud .guest_os_hypervisor (uuid, hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created, is_user_defined)
330+ SELECT UUID(), ' KVM' , ' default' , new_guest_os .name , guest_os .id , now(), 0
331+ FROM temp_new_guest_os_to_insert AS new_guest_os
332+ INNER JOIN cloud .guest_os AS guest_os ON (guest_os .category_id = 1
333+ AND guest_os .is_user_defined = 0
334+ AND guest_os .display_name = new_guest_os .name )
335+ WHERE NOT EXISTS (SELECT 1
336+ FROM cloud .guest_os_hypervisor AS hypervisor
337+ WHERE hypervisor .hypervisor_type = ' KVM'
338+ AND hypervisor .hypervisor_version = ' default'
339+ AND hypervisor .guest_os_id = guest_os .id
340+ AND hypervisor .guest_os_name = new_guest_os .name );
341+
342+ -- Drop temporary table after use it.
343+ DROP TEMPORARY TABLE temp_new_guest_os_to_insert;
344+
0 commit comments