diff --git a/pkg/apis/compute/host.go b/pkg/apis/compute/host.go index 1a1eaced6b..b1f08aa656 100644 --- a/pkg/apis/compute/host.go +++ b/pkg/apis/compute/host.go @@ -120,4 +120,7 @@ type HostDetails struct { IsPrepaidRecycle bool `json:"is_prepaid_recycle"` CanPrepare bool `json:"can_prepare"` PrepareFailReason string `json:"prepare_fail_reason"` + + // 标签 + Metadata map[string]string `json:"metadata"` } diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index fd82609fb9..09f59c08bc 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -2434,6 +2434,10 @@ func (self *SHost) getMoreDetails(ctx context.Context, out api.HostDetails) api. return out } +func (self *SHost) GetMetadataHideKeys() []string { + return []string{} +} + func (self *SHost) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.HostDetails, error) { var err error out := api.HostDetails{} @@ -2441,6 +2445,10 @@ func (self *SHost) GetExtraDetails(ctx context.Context, userCred mcclient.TokenC if err != nil { return out, err } + out.Metadata, err = db.GetVisiableMetadata(self, nil) + if err != nil { + return out, err + } return self.getMoreDetails(ctx, out), nil }