mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #557 from wanyaoqi/bugfix/wyq/server-migrate-add-auto-start
feature: server migrate add auto start
This commit is contained in:
@@ -236,11 +236,15 @@ func (self *SGuest) PerformMigrate(ctx context.Context, userCred mcclient.TokenC
|
||||
host := iHost.(*SHost)
|
||||
preferHostId = host.Id
|
||||
}
|
||||
err := self.StartMigrateTask(ctx, userCred, isRescueMode, self.Status, preferHostId, "")
|
||||
return nil, err
|
||||
|
||||
autoStart := jsonutils.QueryBoolean(data, "auto_start", false)
|
||||
return nil, self.StartMigrateTask(ctx, userCred, isRescueMode, autoStart, self.Status, preferHostId, "")
|
||||
}
|
||||
|
||||
func (self *SGuest) StartMigrateTask(ctx context.Context, userCred mcclient.TokenCredential, isRescueMode bool, guestStatus, preferHostId, parentTaskId string) error {
|
||||
func (self *SGuest) StartMigrateTask(
|
||||
ctx context.Context, userCred mcclient.TokenCredential,
|
||||
isRescueMode, autoStart bool, guestStatus, preferHostId, parentTaskId string,
|
||||
) error {
|
||||
data := jsonutils.NewDict()
|
||||
if isRescueMode {
|
||||
data.Set("is_rescue_mode", jsonutils.JSONTrue)
|
||||
@@ -248,6 +252,9 @@ func (self *SGuest) StartMigrateTask(ctx context.Context, userCred mcclient.Toke
|
||||
if len(preferHostId) > 0 {
|
||||
data.Set("prefer_host_id", jsonutils.NewString(preferHostId))
|
||||
}
|
||||
if autoStart {
|
||||
data.Set("auto_start", jsonutils.JSONTrue)
|
||||
}
|
||||
data.Set("guest_status", jsonutils.NewString(guestStatus))
|
||||
if task, err := taskman.TaskManager.NewTask(ctx, "GuestMigrateTask", self, userCred, data, parentTaskId, "", nil); err != nil {
|
||||
log.Errorln(err)
|
||||
|
||||
@@ -200,10 +200,28 @@ func (self *GuestMigrateTask) OnNormalMigrateComplete(ctx context.Context, guest
|
||||
guest.StartUndeployGuestTask(ctx, self.UserCred, self.GetTaskId(), oldHostId)
|
||||
}
|
||||
|
||||
// Server migrate complete
|
||||
func (self *GuestMigrateTask) OnUndeployOldHostSucc(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
if jsonutils.QueryBoolean(self.Params, "auto_start", false) {
|
||||
self.SetStage("OnGuestStartSucc", nil)
|
||||
guest.StartGueststartTask(ctx, self.UserCred, nil, self.GetId())
|
||||
} else {
|
||||
self.TaskComplete(ctx, guest)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *GuestMigrateTask) OnUndeployOldHostSuccFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
self.TaskFailed(ctx, guest, fmt.Sprintf("Undeploy Old Guest Failed %s", data))
|
||||
}
|
||||
|
||||
func (self *GuestMigrateTask) OnGuestStartSucc(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
self.TaskComplete(ctx, guest)
|
||||
}
|
||||
|
||||
func (self *GuestMigrateTask) OnGuestStartSuccFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
self.TaskFailed(ctx, guest, fmt.Sprintf("Guest Start Failed %s", data))
|
||||
}
|
||||
|
||||
func (self *GuestMigrateTask) sharedStorageMigrateConf(ctx context.Context, guest *models.SGuest, targetHost *models.SHost) (*jsonutils.JSONDict, bool) {
|
||||
body := jsonutils.NewDict()
|
||||
body.Set("is_local_storage", jsonutils.JSONFalse)
|
||||
@@ -388,6 +406,7 @@ func (self *GuestLiveMigrateTask) OnUndeploySrcGuestComplete(ctx context.Context
|
||||
}
|
||||
}
|
||||
|
||||
// Server live migrate complete
|
||||
func (self *GuestLiveMigrateTask) OnGuestSyncStatus(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
self.TaskComplete(ctx, guest)
|
||||
}
|
||||
|
||||
@@ -538,6 +538,7 @@ type ServerRestartOptions struct {
|
||||
type ServerMigrateOptions struct {
|
||||
ID string `help:"ID of server" json:"-"`
|
||||
PreferHost string `help:"Server migration prefer host id or name" json:"prefer_host"`
|
||||
AutoStart *bool `help: "Server auto start after migrate" json:"auto_start"`
|
||||
RescueMode *bool `help:"Migrate server in rescue mode,
|
||||
all disk must store in shared storage;
|
||||
default false" json:"rescue_mode"`
|
||||
|
||||
Reference in New Issue
Block a user