Skip to content

Commit

Permalink
fix: hostbackupstorage climc subcmds (#20284)
Browse files Browse the repository at this point in the history
Co-authored-by: Qiu Jian <[email protected]>
  • Loading branch information
swordqiu and Qiu Jian authored May 15, 2024
1 parent d2b86c8 commit 6df885c
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/climc/shell/compute/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ func init() {
ibCmd.Create(&compute.InstanceBackupManagerCreateFromPackageOptions{})
ibCmd.Perform("syncstatus", &compute.DiskBackupSyncstatusOptions{})
ibCmd.Perform("set-class-metadata", &options.ResourceMetadataOptions{})

hbsCmd := shell.NewJointCmd(&modules.HostBackupstorages)
hbsCmd.List(&compute.HostBackupStorageListOptions{})
hbsCmd.Show(&compute.HostBackupStorageJoinOptions{})
hbsCmd.Attach(&compute.HostBackupStorageJoinOptions{})
hbsCmd.Detach(&compute.HostBackupStorageJoinOptions{})
}
57 changes: 54 additions & 3 deletions cmd/climc/shell/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,15 +667,15 @@ func (cmd JointCmd) List(args IJointListOpt) {
cmd.RunWithDesc("list", fmt.Sprintf("list %s %s pairs", man.MasterManager().KeyString(), man.SlaveManager().KeyString()), args, callback)
}

type IJointShowOpt interface {
type IJointOpt interface {
IOpt
GetMasterId() string
GetSlaveId() string
}

func (cmd JointCmd) Show(args IJointShowOpt) {
func (cmd JointCmd) Show(args IJointOpt) {
man := cmd.manager.(modulebase.JointManager)
callback := func(s *mcclient.ClientSession, args IJointShowOpt) error {
callback := func(s *mcclient.ClientSession, args IJointOpt) error {
params, err := args.Params()
if err != nil {
return err
Expand All @@ -689,3 +689,54 @@ func (cmd JointCmd) Show(args IJointShowOpt) {
}
cmd.Run("show", args, callback)
}

func (cmd JointCmd) Attach(args IJointOpt) {
man := cmd.manager.(modulebase.JointManager)
callback := func(s *mcclient.ClientSession, args IJointOpt) error {
params, err := args.Params()
if err != nil {
return err
}
result, err := man.Attach(s, args.GetMasterId(), args.GetSlaveId(), params)
if err != nil {
return err
}
PrintObject(result)
return nil
}
cmd.Run("attach", args, callback)
}

func (cmd JointCmd) Detach(args IJointOpt) {
man := cmd.manager.(modulebase.JointManager)
callback := func(s *mcclient.ClientSession, args IJointOpt) error {
params, err := args.Params()
if err != nil {
return err
}
result, err := man.Detach(s, args.GetMasterId(), args.GetSlaveId(), params)
if err != nil {
return err
}
PrintObject(result)
return nil
}
cmd.Run("detach", args, callback)
}

func (cmd JointCmd) Update(args IJointOpt) {
man := cmd.manager.(modulebase.JointManager)
callback := func(s *mcclient.ClientSession, args IJointOpt) error {
params, err := args.Params()
if err != nil {
return err
}
result, err := man.Update(s, args.GetMasterId(), args.GetSlaveId(), nil, params)
if err != nil {
return err
}
PrintObject(result)
return nil
}
cmd.Run("update", args, callback)
}
35 changes: 35 additions & 0 deletions pkg/mcclient/options/compute/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,38 @@ type InstanceBackupManagerCreateFromPackageOptions struct {
func (opts *InstanceBackupManagerCreateFromPackageOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(opts), nil
}

type HostBackupStorageListOptions struct {
options.BaseListOptions
Host string `json:"-" help:"filter by host"`
Backupstorage string `json:"-" help:"filter by backupstorage"`
}

func (opts HostBackupStorageListOptions) GetMasterOpt() string {
return opts.Host
}

func (opts HostBackupStorageListOptions) GetSlaveOpt() string {
return opts.Backupstorage
}

func (opts *HostBackupStorageListOptions) Params() (jsonutils.JSONObject, error) {
return options.ListStructToParams(opts)
}

type HostBackupStorageJoinOptions struct {
HOST string `json:"-" help:"host id"`
BACKUPSTORAGE string `json:"-" help:"backup storage id"`
}

func (opts HostBackupStorageJoinOptions) GetMasterId() string {
return opts.HOST
}

func (opts HostBackupStorageJoinOptions) GetSlaveId() string {
return opts.BACKUPSTORAGE
}

func (opts HostBackupStorageJoinOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.NewDict(), nil
}

0 comments on commit 6df885c

Please sign in to comment.