From 5dd040dd2d4511677601a636f11fc1ed9d45a3b2 Mon Sep 17 00:00:00 2001 From: ioito Date: Thu, 1 Sep 2022 10:31:45 +0800 Subject: [PATCH] fix(region): support distinct sku by name --- pkg/apis/compute/sku_const.go | 3 +++ pkg/compute/models/skus.go | 4 ++++ pkg/mcclient/options/serverskus.go | 1 + 3 files changed, 8 insertions(+) diff --git a/pkg/apis/compute/sku_const.go b/pkg/apis/compute/sku_const.go index f36382e615..7daf56343a 100644 --- a/pkg/apis/compute/sku_const.go +++ b/pkg/apis/compute/sku_const.go @@ -83,6 +83,9 @@ type ServerSkuListInput struct { // 预付费状态 PrepaidStatus string `json:"prepaid_status"` + + // 按套餐名称去重 + Distinct bool `json:"distinct"` } type ElasticcacheSkuListInput struct { diff --git a/pkg/compute/models/skus.go b/pkg/compute/models/skus.go index cc46eced62..629b24718c 100644 --- a/pkg/compute/models/skus.go +++ b/pkg/compute/models/skus.go @@ -725,6 +725,10 @@ func (manager *SServerSkuManager) ListItemFilter( } } + if query.Distinct { + q = q.GroupBy(q.Field("name")) + } + brands := query.Brands if len(brands) > 0 { q = q.Filter(sqlchemy.In(q.Field("brand"), brands)) diff --git a/pkg/mcclient/options/serverskus.go b/pkg/mcclient/options/serverskus.go index e27ea55341..c540b2cca3 100644 --- a/pkg/mcclient/options/serverskus.go +++ b/pkg/mcclient/options/serverskus.go @@ -28,6 +28,7 @@ type ServerSkusListOptions struct { PostpaidStatus string `help:"Postpaid status" choices:"soldout|available"` PrepaidStatus string `help:"Prepaid status" choices:"soldout|available"` Enabled *bool `help:"Filter enabled skus"` + Distinct bool `help:"distinct sku by name"` } func (opts *ServerSkusListOptions) GetId() string {