mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
feat(region): support merging wire
1. support merging networks under a wire 2. auto merge networks under a wire when set 'merge_network' when merge this wire
This commit is contained in:
@@ -15,160 +15,21 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type WireListOptions struct {
|
||||
options.BaseListOptions
|
||||
|
||||
Bandwidth *int `help:"List wires by bandwidth"`
|
||||
|
||||
Region string `help:"List wires in region"`
|
||||
Zone string `help:"list wires in zone" json:"-"`
|
||||
Vpc string `help:"List wires in vpc"`
|
||||
Host string `help:"List wires attached to a host"`
|
||||
}
|
||||
R(&WireListOptions{}, "wire-list", "List wires", func(s *mcclient.ClientSession, opts *WireListOptions) error {
|
||||
params, err := options.ListStructToParams(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var result *modulebase.ListResult
|
||||
if len(opts.Zone) > 0 {
|
||||
result, err = modules.Wires.ListInContext(s, params, &modules.Zones, opts.Zone)
|
||||
} else {
|
||||
result, err = modules.Wires.List(s, params)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Wires.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type WireUpdateOptions struct {
|
||||
ID string `help:"ID or Name of zone to update"`
|
||||
Name string `help:"Name of wire"`
|
||||
Desc string `metavar:"<DESCRIPTION>" help:"Description"`
|
||||
Bw int64 `help:"Bandwidth in mbps"`
|
||||
Mtu int64 `help:"mtu in bytes"`
|
||||
}
|
||||
R(&WireUpdateOptions{}, "wire-update", "Update wire", func(s *mcclient.ClientSession, args *WireUpdateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if len(args.Name) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Name), "name")
|
||||
}
|
||||
if len(args.Desc) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Desc), "description")
|
||||
}
|
||||
if args.Bw > 0 {
|
||||
params.Add(jsonutils.NewInt(args.Bw), "bandwidth")
|
||||
}
|
||||
if args.Mtu > 0 {
|
||||
params.Add(jsonutils.NewInt(args.Mtu), "mtu")
|
||||
}
|
||||
if params.Size() == 0 {
|
||||
return InvalidUpdateError()
|
||||
}
|
||||
result, err := modules.Wires.Update(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type WireCreateOptions struct {
|
||||
ZONE string `help:"Zone ID or Name"`
|
||||
Vpc string `help:"VPC ID or Name" default:"default"`
|
||||
NAME string `help:"Name of wire"`
|
||||
BW int64 `help:"Bandwidth in mbps"`
|
||||
Mtu int64 `help:"mtu in bytes"`
|
||||
Desc string `metavar:"<DESCRIPTION>" help:"Description"`
|
||||
}
|
||||
R(&WireCreateOptions{}, "wire-create", "Create a wire", func(s *mcclient.ClientSession, args *WireCreateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "name")
|
||||
params.Add(jsonutils.NewInt(args.BW), "bandwidth")
|
||||
if args.Mtu > 0 {
|
||||
params.Add(jsonutils.NewInt(args.Mtu), "mtu")
|
||||
}
|
||||
if len(args.Vpc) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Vpc), "vpc")
|
||||
}
|
||||
if len(args.Desc) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Desc), "description")
|
||||
}
|
||||
result, err := modules.Wires.CreateInContext(s, params, &modules.Zones, args.ZONE)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type WireShowOptions struct {
|
||||
ID string `help:"ID or Name of the wire to show"`
|
||||
}
|
||||
R(&WireShowOptions{}, "wire-show", "Show wire details", func(s *mcclient.ClientSession, args *WireShowOptions) error {
|
||||
result, err := modules.Wires.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&WireShowOptions{}, "wire-delete", "Delete wire", func(s *mcclient.ClientSession, args *WireShowOptions) error {
|
||||
result, err := modules.Wires.Delete(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type WirePublicOptions struct {
|
||||
ID string `help:"ID or name of wire" json:"-"`
|
||||
Scope string `help:"sharing scope" choices:"system|domain"`
|
||||
SharedDomains []string `help:"share to domains"`
|
||||
}
|
||||
R(&WirePublicOptions{}, "wire-public", "Make wire public", func(s *mcclient.ClientSession, args *WirePublicOptions) error {
|
||||
params := jsonutils.Marshal(args)
|
||||
result, err := modules.Wires.PerformAction(s, args.ID, "public", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type WirePrivateOptions struct {
|
||||
ID string `help:"ID or name of wire" json:"-"`
|
||||
}
|
||||
R(&WirePrivateOptions{}, "wire-private", "Make wire private", func(s *mcclient.ClientSession, args *WirePrivateOptions) error {
|
||||
params := jsonutils.Marshal(args)
|
||||
result, err := modules.Wires.PerformAction(s, args.ID, "private", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&WireShowOptions{}, "wire-change-owner-candidate-domains", "Show candiate domains of a wire for changing owner", func(s *mcclient.ClientSession, args *WireShowOptions) error {
|
||||
result, err := modules.Wires.GetSpecific(s, args.ID, "change-owner-candidate-domains", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
cmd := shell.NewResourceCmd(&modules.Wires).WithKeyword("wire")
|
||||
cmd.List(new(options.WireListOptions))
|
||||
cmd.Create(new(options.WireCreateOptions))
|
||||
cmd.Update(new(options.WireUpdateOptions))
|
||||
cmd.Show(new(options.WireOptions))
|
||||
cmd.Delete(new(options.WireOptions))
|
||||
cmd.Perform("public", new(options.WirePublicOptions))
|
||||
cmd.Perform("private", new(options.WireOptions))
|
||||
cmd.Perform("change-owner-candidate-domains", new(options.WireOptions))
|
||||
cmd.Perform("merge", new(options.WireMergeOptions))
|
||||
cmd.Perform("merge-network", new(options.WireOptions))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user