fix(region): Guest template & Service catalog

Add the common create input.
Not allow to delete the guest template used by some service catalog.
This commit is contained in:
郑雨
2019-12-10 10:34:30 +08:00
parent 68156f4a47
commit 8d21e622ec
6 changed files with 37 additions and 16 deletions
+1 -8
View File
@@ -7,14 +7,7 @@ import (
)
type GuesttemplateCreateInput struct {
apis.Meta
// description: guest template name
// unique: true
// required: true
// example: hello
Name string `json:"name"`
apis.SharableVirutalResourceCreateInput
// description: the content of guest template
// required: true
Content jsonutils.JSONObject `json:"content"`
@@ -3,14 +3,7 @@ package compute
import "yunion.io/x/onecloud/pkg/apis"
type ServiceCatalogCreateInput struct {
apis.Meta
// description: service catalog name
// uniqure: true
// required: true
// example: hello
Name string `json:"name`
apis.SharableVirutalResourceCreateInput
// description: service catalog icon url
// example: https://yunion.io/files/hello.png
IconUrl string `json:"icon_url"`
+6
View File
@@ -27,3 +27,9 @@ type SharableVirtualResourceDetails struct {
type SharableVirtualResourceListInput struct {
StandaloneResourceListInput
}
type SharableVirutalResourceCreateInput struct {
VirtualResourceCreateInput
IsPublic bool `json:"is_public"`
PublicScope string `json:"public_scope"`
}
+11
View File
@@ -27,3 +27,14 @@ type StandaloneResourceListInput struct {
Tags []string `json:"tags"`
WithoutUserMeta bool `json:"without_user_meta"`
}
type StandaloneResourceCreatInput struct {
Meta
// description: resource name
// unique: true
// required: true
// example: yunion
Name string `json:"name"`
Description string `json:"description"`
IsEmulated bool `json:"is_emulated"`
}
+5
View File
@@ -17,3 +17,8 @@ package apis
type VirtualResourceDetails struct {
ModelBaseDetails
}
type VirtualResourceCreateInput struct {
StandaloneResourceCreatInput
IsSystem bool `json:"is_system"`
}
+13
View File
@@ -395,3 +395,16 @@ func (gt *SGuestTemplate) genForbiddenError(resourceName, resourceStr, scope str
}
return httperrors.NewForbiddenError(msg)
}
func (gt *SGuestTemplate) ValidateDeleteCondition(ctx context.Context) error {
q := ServiceCatalogManager.Query("name").Equals("guest_template_id", gt.Id)
names := make([]string, 0, 1)
err := q.All(&names)
if err != nil {
return errors.Wrap(err, "SQuery.All")
}
if len(names) > 0 {
return httperrors.NewForbiddenError("guest template %s used by service catalog %s", gt.Id, names[0])
}
return nil
}