mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-06-23 23:44:12 +08:00
- instance snapshot
- instance clone - create form snapshot don't reset passwd
This commit is contained in:
49
cmd/climc/shell/instance_snapshots.go
Normal file
49
cmd/climc/shell/instance_snapshots.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type InstanceSnapshotsListOptions struct {
|
||||
options.BaseListOptions
|
||||
|
||||
GuestId string `help:"guest id" json:"guest_id"`
|
||||
}
|
||||
R(&InstanceSnapshotsListOptions{}, "instance-snapshot-list", "Show instance snapshots", func(s *mcclient.ClientSession, args *InstanceSnapshotsListOptions) error {
|
||||
params, err := options.ListStructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := modules.InstanceSnapshots.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.InstanceSnapshots.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type InstanceSnapshotDeleteOptions struct {
|
||||
ID []string `help:"Delete snapshot id"`
|
||||
}
|
||||
R(&InstanceSnapshotDeleteOptions{}, "instance-snapshot-delete", "Delete snapshots", func(s *mcclient.ClientSession, args *InstanceSnapshotDeleteOptions) error {
|
||||
ret := modules.InstanceSnapshots.BatchDelete(s, args.ID, nil)
|
||||
printBatchResults(ret, modules.InstanceSnapshots.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type InstanceSnapshotShowOptions struct {
|
||||
ID string `help:"ID or Name of snapshot"`
|
||||
}
|
||||
R(&InstanceSnapshotShowOptions{}, "snapshot-show", "Show snapshot details", func(s *mcclient.ClientSession, args *InstanceSnapshotShowOptions) error {
|
||||
result, err := modules.InstanceSnapshots.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -156,6 +156,25 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.ServerCreateFromInstanceSnapshot{}, "server-create-from-instance-snapshot", "server create from instance snapshot",
|
||||
func(s *mcclient.ClientSession, opts *options.ServerCreateFromInstanceSnapshot) error {
|
||||
params := &compute.ServerCreateInput{}
|
||||
params.InstanceSnapshotId = opts.InstaceSnapshotId
|
||||
params.Name = opts.NAME
|
||||
params.AutoStart = opts.AutoStart
|
||||
params.Eip = opts.Eip
|
||||
params.EipChargeType = opts.EipChargeType
|
||||
params.EipBw = opts.EipBw
|
||||
|
||||
server, err := modules.Servers.Create(s, params.JSON(params))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(server)
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
R(&options.ServerCreateOptions{}, "server-create", "Create a server", func(s *mcclient.ClientSession, opts *options.ServerCreateOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
@@ -1080,4 +1099,52 @@ func init() {
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
type ServerCreateSnapshot struct {
|
||||
ID string `help:"ID or name of VM" json:"-"`
|
||||
SNAPSHOT string `help:"Instance snapshot name" json:"name"`
|
||||
}
|
||||
R(&ServerCreateSnapshot{}, "instance-snapshot-create", "create instance snapshot", func(s *mcclient.ClientSession, opts *ServerCreateSnapshot) error {
|
||||
params := jsonutils.Marshal(opts)
|
||||
result, err := modules.Servers.PerformAction(s, opts.ID, "instance-snapshot", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type ServerSnapshotAndClone struct {
|
||||
ID string `help:"ID or name of VM" json:"-"`
|
||||
NAME string `help:"Newly instance name" json:"name"`
|
||||
AutoStart bool `help:"Auto start new guest"`
|
||||
AllowDelete bool `help:"Allow new guest delete" json:"-"`
|
||||
Count int `help:"Guest count"`
|
||||
}
|
||||
R(&ServerSnapshotAndClone{}, "instance-snapshot-and-clone", "create instance snapshot and clone new instance", func(s *mcclient.ClientSession, opts *ServerSnapshotAndClone) error {
|
||||
params := jsonutils.Marshal(opts)
|
||||
dictParams := params.(*jsonutils.JSONDict)
|
||||
if opts.AllowDelete {
|
||||
dictParams.Set("disable_delete", jsonutils.JSONFalse)
|
||||
}
|
||||
result, err := modules.Servers.PerformAction(s, opts.ID, "snapshot-and-clone", dictParams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type ServerRollBackSnapshot struct {
|
||||
ID string `help:"ID or name of VM" json:"-"`
|
||||
InstanceSnapshot string `help:"Instance snapshot id or name" json:"instance_snapshot"`
|
||||
}
|
||||
R(&ServerRollBackSnapshot{}, "instance-snapshot-reset", "reset instance snapshot", func(s *mcclient.ClientSession, opts *ServerRollBackSnapshot) error {
|
||||
params := jsonutils.Marshal(opts)
|
||||
result, err := modules.Servers.PerformAction(s, opts.ID, "instance-snapshot-reset", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user