mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: allow update network server_type (#20351)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -472,6 +472,9 @@ type NetworkUpdateInput struct {
|
||||
|
||||
// 是否加入自动分配地址池
|
||||
IsAutoAlloc *bool `json:"is_auto_alloc"`
|
||||
|
||||
// 更新网络类型
|
||||
ServerType TNetworkType `json:"server_type"`
|
||||
}
|
||||
|
||||
type GetNetworkAddressesInput struct {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user