Skip to content

Commit

Permalink
fix: allow update network server_type (#20351)
Browse files Browse the repository at this point in the history
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
  • Loading branch information
swordqiu and Qiu Jian committed May 24, 2024
1 parent f348c04 commit a216a37
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/apis/compute/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ type NetworkUpdateInput struct {

// 是否加入自动分配地址池
IsAutoAlloc *bool `json:"is_auto_alloc"`

// 更新网络类型
ServerType TNetworkType `json:"server_type"`
}

type GetNetworkAddressesInput struct {
Expand Down
6 changes: 5 additions & 1 deletion pkg/compute/models/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/mcclient/options/compute/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit a216a37

Please sign in to comment.