From a216a37d321ed02f2adc6266955c031c84cc77e9 Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Fri, 24 May 2024 15:15:28 +0800 Subject: [PATCH] fix: allow update network server_type (#20351) Co-authored-by: Qiu Jian --- pkg/apis/compute/network.go | 3 +++ pkg/compute/models/networks.go | 6 +++++- pkg/mcclient/options/compute/network.go | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/apis/compute/network.go b/pkg/apis/compute/network.go index 9cdccdfead..76ca318eb0 100644 --- a/pkg/apis/compute/network.go +++ b/pkg/apis/compute/network.go @@ -472,6 +472,9 @@ type NetworkUpdateInput struct { // 是否加入自动分配地址池 IsAutoAlloc *bool `json:"is_auto_alloc"` + + // 更新网络类型 + ServerType TNetworkType `json:"server_type"` } type GetNetworkAddressesInput struct { diff --git a/pkg/compute/models/networks.go b/pkg/compute/models/networks.go index 9d89600919..a9a6d0ec33 100644 --- a/pkg/compute/models/networks.go +++ b/pkg/compute/models/networks.go @@ -127,7 +127,7 @@ type SNetwork struct { // 服务器类型 // example: server - ServerType api.TNetworkType `width:"16" charset:"ascii" default:"guest" nullable:"true" list:"user" create:"optional"` + ServerType api.TNetworkType `width:"16" charset:"ascii" default:"guest" nullable:"true" list:"user" update:"admin" create:"optional"` // 分配策略 AllocPolicy string `width:"16" charset:"ascii" nullable:"true" get:"user" update:"user" create:"optional"` @@ -2207,6 +2207,10 @@ func (snet *SNetwork) validateUpdateData(ctx context.Context, userCred mcclient. } } + if len(input.ServerType) > 0 && !api.IsInNetworkTypes(input.ServerType, api.ALL_NETWORK_TYPES) { + return input, errors.Wrapf(httperrors.ErrInputParameter, "invalid server_type %q", input.ServerType) + } + return input, nil } diff --git a/pkg/mcclient/options/compute/network.go b/pkg/mcclient/options/compute/network.go index 46ae1664d4..2700d72c7e 100644 --- a/pkg/mcclient/options/compute/network.go +++ b/pkg/mcclient/options/compute/network.go @@ -157,6 +157,8 @@ type NetworkUpdateOptions struct { ExternalId string `help:"External ID"` AllocPolicy string `help:"Address allocation policy" choices:"none|stepdown|stepup|random"` IsAutoAlloc *bool `help:"Add network into auto-allocation pool" negative:"no_auto_alloc"` + + ServerType string `help:"specify network server_type" choices:"baremetal|container|guest|pxe|ipmi|eip|hostlocal"` } func (opts *NetworkUpdateOptions) Params() (jsonutils.JSONObject, error) { @@ -234,6 +236,9 @@ func (opts *NetworkUpdateOptions) Params() (jsonutils.JSONObject, error) { if opts.IsAutoAlloc != nil { params.Add(jsonutils.NewBool(*opts.IsAutoAlloc), "is_auto_alloc") } + if len(opts.ServerType) > 0 { + params.Add(jsonutils.NewString(opts.ServerType), "server_type") + } if params.Size() == 0 { return nil, shell.InvalidUpdateError() }