Skip to content

Commit 4708121

Browse files
server: set template type to ROUTING or USER if template type is not specified when upload a template (#12768)
1 parent e10c066 commit 4708121

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

engine/schema/src/main/resources/META-INF/db/schema-42200to42210.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ UPDATE `cloud`.`alert` SET type = 34 WHERE name = 'ALERT.VR.PRIVATE.IFACE.MTU';
3535
UPDATE `cloud`.`configuration` SET description = 'True if the management server will restart the agent service via SSH into the KVM hosts after or during maintenance operations', is_dynamic = 1 WHERE name = 'kvm.ssh.to.agent';
3636

3737
UPDATE `cloud`.`vm_template` SET guest_os_id = 99 WHERE name = 'kvm-default-vm-import-dummy-template';
38+
39+
-- Update existing vm_template records with NULL type to "USER"
40+
UPDATE `cloud`.`vm_template` SET `type` = 'USER' WHERE `type` IS NULL;

server/src/main/java/com/cloud/template/TemplateManagerImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,7 @@ public TemplateType validateTemplateType(BaseCmd cmd, boolean isAdmin, boolean i
24162416
} else if ((cmd instanceof RegisterVnfTemplateCmd || cmd instanceof UpdateVnfTemplateCmd) && !TemplateType.VNF.equals(templateType)) {
24172417
throw new InvalidParameterValueException("The template type must be VNF for VNF templates, but the actual type is " + templateType);
24182418
}
2419-
} else if (cmd instanceof RegisterTemplateCmd) {
2419+
} else if (cmd instanceof RegisterTemplateCmd || cmd instanceof GetUploadParamsForTemplateCmd) {
24202420
boolean isRouting = Boolean.TRUE.equals(isRoutingType);
24212421
templateType = (cmd instanceof RegisterVnfTemplateCmd) ? TemplateType.VNF : (isRouting ? TemplateType.ROUTING : TemplateType.USER);
24222422
}
@@ -2426,6 +2426,8 @@ public TemplateType validateTemplateType(BaseCmd cmd, boolean isAdmin, boolean i
24262426
throw new InvalidParameterValueException(String.format("Users can not register Template with template type %s.", templateType));
24272427
} else if (cmd instanceof UpdateTemplateCmd) {
24282428
throw new InvalidParameterValueException(String.format("Users can not update Template to template type %s.", templateType));
2429+
} else if (cmd instanceof GetUploadParamsForTemplateCmd) {
2430+
throw new InvalidParameterValueException(String.format("Users can not request upload parameters for Template with template type %s.", templateType));
24292431
}
24302432
}
24312433
return templateType;

0 commit comments

Comments
 (0)