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 {