Skip to content

Commit

Permalink
feat(climc): update port_mappings of server network (#20518)
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi authored Jun 13, 2024
1 parent 15cc91c commit 0b85e31
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
24 changes: 17 additions & 7 deletions cmd/climc/shell/compute/servernetworks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strconv"

"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/printutils"
"yunion.io/x/pkg/util/regutils"

Expand Down Expand Up @@ -88,13 +89,14 @@ func init() {
})

type ServerNetworkUpdateOptions struct {
SERVER string `help:"ID or Name of Server"`
NETWORK string `help:"ID or Name of Wire"`
Mac string `help:"Mac of NIC"`
Driver string `help:"Driver model of vNIC" choices:"virtio|e1000|vmxnet3|rtl8139"`
Index int64 `help:"Index of NIC" default:"-1"`
Ifname string `help:"Interface name of vNIC on host"`
Default bool `help:"is default nic?"`
SERVER string `help:"ID or Name of Server"`
NETWORK string `help:"ID or Name of Wire"`
Mac string `help:"Mac of NIC"`
Driver string `help:"Driver model of vNIC" choices:"virtio|e1000|vmxnet3|rtl8139"`
Index int64 `help:"Index of NIC" default:"-1"`
Ifname string `help:"Interface name of vNIC on host"`
Default bool `help:"is default nic?"`
PortMapping []string `help:"Network port mapping, e.g. 'port=80,host_port=8080,protocol=<tcp|udp>,host_port_range=<int>-<int>,remote_ips=x.x.x.x|y.y.y.y'" short-token:"p"`
}
R(&ServerNetworkUpdateOptions{}, "server-network-update", "Update server network settings", func(s *mcclient.ClientSession, args *ServerNetworkUpdateOptions) error {
params := jsonutils.NewDict()
Expand All @@ -110,6 +112,14 @@ func init() {
if args.Default {
params.Add(jsonutils.JSONTrue, "is_default")
}
if len(args.PortMapping) > 0 {
psm, err := cmdline.ParseNetworkConfigPortMappings(args.PortMapping)
if err != nil {
return errors.Wrap(err, "parse port mapping")
}
ps := psm[0]
params.Add(jsonutils.Marshal(ps), "port_mappings")
}
if params.Size() == 0 {
return InvalidUpdateError()
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/cloudcommon/cmdline/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ func parseNetworkConfigPortMapping(desc string) (int, *compute.GuestPortMapping,
Start: start,
End: end,
}
case "remote_ips", "remote_ip":
ips := strings.Split(val, "|")
pm.RemoteIps = ips
}
}
if pm.Port == 0 {
Expand Down

0 comments on commit 0b85e31

Please sign in to comment.