mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 06:09:39 +08:00
Merge pull request #55 in YUNIONIO/onecloud from ~WANYAOQI/onecloud:feature/wyq/kvm-server-reset to release/2.1.0
* commit 'f991bd67f15f73efa54cd765e19848879027ddbc': region: kvm server reset, fix climc parmas
This commit is contained in:
+1
-1
@@ -181,7 +181,7 @@ func main() {
|
||||
fmt.Print(parser.HelpString())
|
||||
} else if options.Version {
|
||||
fmt.Printf("Yunion API client version:\n %s\n", version.GetJsonString())
|
||||
} else if len(options.SUBCOMMAND) == 0 {
|
||||
} else if len(os.Args) <= 1 || (options.ApiVersion == "v2" && len(os.Args) <= 3) {
|
||||
session, e := newClientSession(options)
|
||||
if e != nil {
|
||||
showErrorAndExit(e)
|
||||
|
||||
@@ -339,8 +339,16 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&ServerOpsOptions{}, "server-reset", "Reset servers", func(s *mcclient.ClientSession, args *ServerOpsOptions) error {
|
||||
ret := modules.Servers.BatchPerformAction(s, args.ID, "reset", nil)
|
||||
type ServerResetOptions struct {
|
||||
ServerOpsOptions
|
||||
Hard bool `help:"Hard reset or not; default soft"`
|
||||
}
|
||||
R(&ServerResetOptions{}, "server-reset", "Reset servers", func(s *mcclient.ClientSession, args *ServerResetOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if args.Hard {
|
||||
params.Add(jsonutils.JSONTrue, "is_hard")
|
||||
}
|
||||
ret := modules.Servers.BatchPerformAction(s, args.ID, "reset", params)
|
||||
printBatchResults(ret, modules.Servers.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -102,6 +102,14 @@ func (self *SBaseGuestDriver) RqeuestSuspendOnHost(ctx context.Context, guest *m
|
||||
return fmt.Errorf("Not Implement")
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) StartGuestResetTask(guest *models.SGuest, ctx context.Context, userCred mcclient.TokenCredential, isHard bool, parentTaskId string) error {
|
||||
return fmt.Errorf("Not Implement")
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) RequestSoftReset(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement")
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) AllowReconfigGuest() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -206,6 +206,11 @@ func (self *SKVMGuestDriver) RequestChangeVmConfig(ctx context.Context, guest *m
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) RequestSoftReset(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
|
||||
_, err := guest.SendMonitorCommand(ctx, task.GetUserCred(), "system_reset")
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) RequestDetachDisk(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
|
||||
return guest.StartSyncTask(ctx, task.GetUserCred(), false, task.GetTaskId())
|
||||
}
|
||||
|
||||
@@ -95,6 +95,19 @@ func (self *SVirtualizedGuestDriver) StartGuestStopTask(guest *models.SGuest, ct
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVirtualizedGuestDriver) StartGuestResetTask(guest *models.SGuest, ctx context.Context, userCred mcclient.TokenCredential, isHard bool, parentTaskId string) error {
|
||||
var taskName = "GuestSoftResetTask"
|
||||
if isHard {
|
||||
taskName = "GuestHardResetTask"
|
||||
}
|
||||
task, err := taskman.TaskManager.NewTask(ctx, taskName, guest, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVirtualizedGuestDriver) OnGuestDeployTaskComplete(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
|
||||
if jsonutils.QueryBoolean(task.GetParams(), "restart", false) {
|
||||
task.SetStage("OnDeployStartGuestComplete", nil)
|
||||
|
||||
@@ -39,6 +39,9 @@ type IGuestDriver interface {
|
||||
RequestGuestCreateInsertIso(ctx context.Context, imageId string, guest *SGuest, task taskman.ITask) error
|
||||
|
||||
StartGuestStopTask(guest *SGuest, ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error
|
||||
StartGuestResetTask(guest *SGuest, ctx context.Context, userCred mcclient.TokenCredential, isHard bool, parentTaskId string) error
|
||||
|
||||
RequestSoftReset(ctx context.Context, guest *SGuest, task taskman.ITask) error
|
||||
|
||||
RequestDeployGuestOnHost(ctx context.Context, guest *SGuest, host *SHost, task taskman.ITask) error
|
||||
|
||||
|
||||
@@ -3103,6 +3103,23 @@ func (self *SGuest) PerformStart(ctx context.Context, userCred mcclient.TokenCre
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SGuest) AllowPerformReset(ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred)
|
||||
}
|
||||
|
||||
func (self *SGuest) PerformReset(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
isHard := jsonutils.QueryBoolean(data, "is_hard", false)
|
||||
if self.Status == VM_RUNNING || self.Status == VM_STOP_FAILED {
|
||||
self.GetDriver().StartGuestResetTask(self, ctx, userCred, isHard, "")
|
||||
return nil, nil
|
||||
}
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot reset VM in status %s", self.Status)
|
||||
}
|
||||
|
||||
func (self *SGuest) AllowPerformStop(ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(GuestSoftResetTask{})
|
||||
taskman.RegisterTask(GuestHardResetTask{})
|
||||
}
|
||||
|
||||
type GuestSoftResetTask struct {
|
||||
SGuestBaseTask
|
||||
}
|
||||
|
||||
func (self *GuestSoftResetTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
guest := obj.(*models.SGuest)
|
||||
err := guest.GetDriver().RequestSoftReset(ctx, guest, self)
|
||||
if err == nil {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
} else {
|
||||
self.SetStageFailed(ctx, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
type GuestHardResetTask struct {
|
||||
SGuestBaseTask
|
||||
}
|
||||
|
||||
func (self *GuestHardResetTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
guest := obj.(*models.SGuest)
|
||||
self.StopServer(ctx, guest)
|
||||
}
|
||||
|
||||
func (self *GuestHardResetTask) StopServer(ctx context.Context, guest *models.SGuest) {
|
||||
guest.SetStatus(self.UserCred, models.VM_STOPPING, "")
|
||||
self.SetStage("OnServerStopComplete", nil)
|
||||
guest.StartGuestStopTask(ctx, self.UserCred, false, self.GetTaskId())
|
||||
}
|
||||
|
||||
func (self *GuestHardResetTask) OnServerStopComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
self.StartServer(ctx, guest)
|
||||
}
|
||||
|
||||
func (self *GuestHardResetTask) StartServer(ctx context.Context, guest *models.SGuest) {
|
||||
self.SetStage("OnServerStartComplete", nil)
|
||||
guest.StartGueststartTask(ctx, self.UserCred, nil, self.GetTaskId())
|
||||
}
|
||||
|
||||
func (self *GuestHardResetTask) OnServerStartComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user