From 9142a6eb48bf93ecfb17db6257a7c6269dd3811c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E9=9B=A8?= Date: Tue, 10 Dec 2019 14:58:16 +0800 Subject: [PATCH] fix(region): Fix the list bug of Guest Template 1. Add function GetCustomizeColumns for Guest Template 2. Fix the ValidateDeleteCondition for Guest Template 3. Rename Config as ConfigInfo in apis.GuesttemplateDetails --- pkg/apis/compute/guesttemplate.go | 2 +- pkg/compute/models/guest_template.go | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/apis/compute/guesttemplate.go b/pkg/apis/compute/guesttemplate.go index 48cc8be90a..fbb3222aed 100644 --- a/pkg/apis/compute/guesttemplate.go +++ b/pkg/apis/compute/guesttemplate.go @@ -18,7 +18,7 @@ type GuesttemplateDetails struct { apis.SharableVirtualResourceDetails SGuestTemplate - Config GuesttemplateConfigInfo `json:"config"` + ConfigInfo GuesttemplateConfigInfo `json:"config_info"` } type GuesttemplateConfigInfo struct { diff --git a/pkg/compute/models/guest_template.go b/pkg/compute/models/guest_template.go index 79f53d51d5..bc752be625 100644 --- a/pkg/compute/models/guest_template.go +++ b/pkg/compute/models/guest_template.go @@ -150,6 +150,16 @@ func (gt *SGuestTemplate) ValidateUpdateData(ctx context.Context, userCred mccli return gt.SSharableVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, data) } +func (gt *SGuestTemplate) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, + query jsonutils.JSONObject) *jsonutils.JSONDict { + extra := gt.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query) + out := &computeapis.GuesttemplateDetails{} + gt.getMoreDetailsV2(ctx, userCred, out) + ret := out.JSON(out) + ret.Update(extra) + return ret +} + func (gt *SGuestTemplate) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*computeapis.GuesttemplateDetails, error) { @@ -293,7 +303,7 @@ func (gt *SGuestTemplate) getMoreDetailsV2(ctx context.Context, userCred mcclien // no arrivals } - out.Config = configInfo + out.ConfigInfo = configInfo return } @@ -398,13 +408,13 @@ func (gt *SGuestTemplate) genForbiddenError(resourceName, resourceStr, scope str func (gt *SGuestTemplate) ValidateDeleteCondition(ctx context.Context) error { q := ServiceCatalogManager.Query("name").Equals("guest_template_id", gt.Id) - names := make([]string, 0, 1) + names := make([]struct{ Name 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 httperrors.NewForbiddenError("guest template %s used by service catalog %s", gt.Id, names[0].Name) } return nil }