fix: allow update network server_type (#20351)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2024-05-24 15:15:28 +08:00
committed by GitHub
co-authored by Qiu Jian
parent f348c04d56
commit a216a37d32
3 changed files with 13 additions and 1 deletions
+3
View File
@@ -472,6 +472,9 @@ type NetworkUpdateInput struct {
// 是否加入自动分配地址池
IsAutoAlloc *bool `json:"is_auto_alloc"`
// 更新网络类型
ServerType TNetworkType `json:"server_type"`
}
type GetNetworkAddressesInput struct {
+5 -1
View File
@@ -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
}
+5
View File
@@ -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()
}