- local disk snapshot create and delete

- auto snapshot everyday
- rewrite cornman
- make dep and some fix
- fix conflict
This commit is contained in:
wanyaoqi
2018-09-06 16:22:36 +08:00
parent 6d29c36abb
commit 4f2b50a869
21 changed files with 1014 additions and 67 deletions
+12 -4
View File
@@ -120,10 +120,11 @@ func init() {
})
type DiskUpdateOptions struct {
ID string `help:"ID or name of disk"`
Name string `help:"New name of disk"`
Desc string `help:"Description" metavar:"DESCRIPTION"`
AutoDelete string `help:"enable/disable auto delete of disk" choices:"enable|disable"`
ID string `help:"ID or name of disk"`
Name string `help:"New name of disk"`
Desc string `help:"Description" metavar:"DESCRIPTION"`
AutoDelete string `help:"enable/disable auto delete of disk" choices:"enable|disable"`
AutoSnapshot string `help:"enable/disable auto snapshot of disk" choices:"enable|disable"`
}
R(&DiskUpdateOptions{}, "disk-update", "Update property of a virtual disk", func(s *mcclient.ClientSession, args *DiskUpdateOptions) error {
params := jsonutils.NewDict()
@@ -140,6 +141,13 @@ func init() {
params.Add(jsonutils.JSONFalse, "auto_delete")
}
}
if len(args.AutoSnapshot) > 0 {
if args.AutoSnapshot == "enable" {
params.Add(jsonutils.JSONTrue, "auto_snapshot")
} else {
params.Add(jsonutils.JSONFalse, "auto_snapshot")
}
}
if params.Size() == 0 {
return InvalidUpdateError()
}
+17
View File
@@ -352,6 +352,23 @@ func init() {
return nil
})
type ServerDiskSnapshotOptions struct {
SERVER string `help:"server ID or Name"`
DISK string `help:"create snapshot disk id"`
SNAPSHOTNAME string `help:"Snapshot name"`
}
R(&ServerDiskSnapshotOptions{}, "server-disk-create-snapshot", "Task server disk snapshot", func(s *mcclient.ClientSession, args *ServerDiskSnapshotOptions) error {
params := jsonutils.NewDict()
params.Set("disk_id", jsonutils.NewString(args.DISK))
params.Set("name", jsonutils.NewString(args.SNAPSHOTNAME))
srv, err := modules.Servers.PerformAction(s, args.SERVER, "disk-snapshot", params)
if err != nil {
return err
}
printObject(srv)
return nil
})
type ServerInsertISOOptions struct {
ID string `help:"server ID or Name"`
ISO string `help:"Glance image ID of the ISO"`
+40
View File
@@ -0,0 +1,40 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
type SnapshotsListOptions struct {
options.BaseListOptions
Disk string `help:"Disk snapshots"`
}
R(&SnapshotsListOptions{}, "snapshot-list", "Show snapshots", func(s *mcclient.ClientSession, args *SnapshotsListOptions) error {
params, err := args.BaseListOptions.Params()
if err != nil {
return err
}
params.Add(jsonutils.NewString(args.Disk), "disk_id")
result, err := modules.Snapshots.List(s, params)
if err != nil {
return err
}
printList(result, modules.Snapshots.GetColumns(s))
return nil
})
type SnapshotDeleteOptions struct {
ID string `help:"Delete snapshot id"`
}
R(&SnapshotDeleteOptions{}, "snapshot-delete", "Delete snapshots", func(s *mcclient.ClientSession, args *SnapshotDeleteOptions) error {
result, err := modules.Snapshots.Delete(s, args.ID, nil)
if err != nil {
return err
}
printObject(result)
return nil
})
}