Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new registers in guest_os #4699

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,44 @@ CREATE VIEW `cloud`.`host_view` AS
`cloud`.`user` ON `user`.`uuid` = `last_annotation_view`.`user_uuid`
GROUP BY
`host`.`id`;

-- PR#4699 Drop the procedure `ADD_GUEST_OS_AND_HYPERVISOR_MAPPING` if it already exist.
DROP PROCEDURE IF EXISTS `cloud`.`ADD_GUEST_OS_AND_HYPERVISOR_MAPPING`;

-- PR#4699 Create the procedure `ADD_GUEST_OS_AND_HYPERVISOR_MAPPING` to add guest_os and guest_os_hypervisor mapping.
CREATE PROCEDURE `cloud`.`ADD_GUEST_OS_AND_HYPERVISOR_MAPPING` (
IN guest_os_category_id bigint(20) unsigned,
IN guest_os_display_name VARCHAR(255),
IN guest_os_hypervisor_hypervisor_type VARCHAR(32),
IN guest_os_hypervisor_hypervisor_version VARCHAR(32),
IN guest_os_hypervisor_guest_os_name VARCHAR(255)
)
BEGIN
INSERT INTO cloud.guest_os (uuid, category_id, display_name, created)
SELECT UUID(), guest_os_category_id, guest_os_display_name, now()
FROM DUAL
WHERE not exists( SELECT 1
FROM cloud.guest_os
WHERE cloud.guest_os.category_id = guest_os_category_id
AND cloud.guest_os.display_name = guest_os_display_name)

; INSERT INTO cloud.guest_os_hypervisor (uuid, hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created)
SELECT UUID(), guest_os_hypervisor_hypervisor_type, guest_os_hypervisor_hypervisor_version, guest_os_hypervisor_guest_os_name, guest_os.id, now()
FROM cloud.guest_os
WHERE guest_os.category_id = guest_os_category_id
AND guest_os.display_name = guest_os_display_name
AND NOT EXISTS (SELECT 1
FROM cloud.guest_os_hypervisor as hypervisor
WHERE hypervisor_type = guest_os_hypervisor_hypervisor_type
AND hypervisor_version = guest_os_hypervisor_hypervisor_version
AND hypervisor.guest_os_id = guest_os.id
AND hypervisor.guest_os_name = guest_os_hypervisor_guest_os_name)
;END;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GutoVeronezi
this procedure might work in mysql, but I think it will not in cloudstack upgrade.
";" should not be the last character of a line in a procedure in schema-XXX.sql.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GutoVeronezi
what I said is not clear.
I mean you need to change line 322 and 334 which have ";" at the end of line.
line 335 was ok (it is not ok now).

for line 322, you can move the ";" at the end of line, to be beginning of line 324.
for line 334, you can move the ";" to the position before "END;".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weizhouapache done.

I misunderstood it at first, but now i see.

I took a look into the file that reads and execute the SQL script and wondered why it was wrote that way.

-- PR#4699 Call procedure `ADD_GUEST_OS_AND_HYPERVISOR_MAPPING` to add new data to guest_os and guest_os_hypervisor.
CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (10, 'Ubuntu 20.04 LTS', 'KVM', 'default', 'Ubuntu 20.04 LTS');
CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (10, 'Ubuntu 21.04', 'KVM', 'default', 'Ubuntu 21.04');
CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (9, 'pfSense 2.4', 'KVM', 'default', 'pfSense 2.4');
CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (9, 'OpenBSD 6.7', 'KVM', 'default', 'OpenBSD 6.7');
CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (9, 'OpenBSD 6.8', 'KVM', 'default', 'OpenBSD 6.8');
CALL ADD_GUEST_OS_AND_HYPERVISOR_MAPPING (1, 'AlmaLinux 8.3', 'KVM', 'default', 'AlmaLinux 8.3');