mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Automatic merge from release/2.2.0 -> release/2.3.0
* commit '6e35123634d4c2edc3556cf8b300ae8252309a30': guest适配操作状态
This commit is contained in:
@@ -56,6 +56,18 @@ func (self *SAliyunGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
return []string{models.VM_READY, models.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SAliyunGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{models.VM_READY, models.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SAliyunGuestDriver) GetChangeConfigStatus() ([]string, error) {
|
||||
return []string{models.VM_READY, models.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SAliyunGuestDriver) GetDeployStatus() ([]string, error) {
|
||||
return []string{models.VM_READY, models.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SAliyunGuestDriver) RequestDetachDisk(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
|
||||
return guest.StartSyncTask(ctx, task.GetUserCred(), false, task.GetTaskId())
|
||||
}
|
||||
|
||||
@@ -104,6 +104,18 @@ func (self *SBaseGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
return []string{}, fmt.Errorf("This Guest driver dose not implement GetAttachDiskStatus")
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{}, fmt.Errorf("This Guest driver dose not implement GetRebuildRootStatus")
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) GetChangeConfigStatus() ([]string, error) {
|
||||
return []string{}, fmt.Errorf("This Guest driver dose not implement GetChangeConfigStatus")
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) GetDeployStatus() ([]string, error) {
|
||||
return []string{}, fmt.Errorf("This Guest driver dose not implement GetDeployStatus")
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) RequestDeleteDetachedDisk(ctx context.Context, disk *models.SDisk, task taskman.ITask, isPurge bool) error {
|
||||
return fmt.Errorf("Not Implement")
|
||||
}
|
||||
|
||||
@@ -263,6 +263,18 @@ func (self *SKVMGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
return []string{models.VM_READY, models.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{models.VM_READY, models.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) GetChangeConfigStatus() ([]string, error) {
|
||||
return []string{models.VM_READY}, nil
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) GetDeployStatus() ([]string, error) {
|
||||
return []string{models.VM_READY}, nil
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) RequestDeleteDetachedDisk(ctx context.Context, disk *models.SDisk, task taskman.ITask, isPurge bool) error {
|
||||
return disk.StartDiskDeleteTask(ctx, task.GetUserCred(), task.GetTaskId(), isPurge)
|
||||
}
|
||||
|
||||
@@ -83,6 +83,9 @@ type IGuestDriver interface {
|
||||
RequestDetachDisk(ctx context.Context, guest *SGuest, task taskman.ITask) error
|
||||
GetDetachDiskStatus() ([]string, error)
|
||||
GetAttachDiskStatus() ([]string, error)
|
||||
GetRebuildRootStatus() ([]string, error)
|
||||
GetChangeConfigStatus() ([]string, error)
|
||||
GetDeployStatus() ([]string, error)
|
||||
CanKeepDetachDisk() bool
|
||||
|
||||
RequestDeleteDetachedDisk(ctx context.Context, disk *SDisk, task taskman.ITask, isPurge bool) error
|
||||
|
||||
@@ -2112,7 +2112,12 @@ func (self *SGuest) PerformDeploy(ctx context.Context, userCred mcclient.TokenCr
|
||||
}
|
||||
}
|
||||
|
||||
if utils.IsInStringArray(self.Status, []string{VM_RUNNING, VM_READY, VM_ADMIN}) {
|
||||
deployStatus, err := self.GetDriver().GetDeployStatus()
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError(err.Error())
|
||||
}
|
||||
|
||||
if utils.IsInStringArray(self.Status, deployStatus) {
|
||||
if doRestart && self.Status == VM_RUNNING {
|
||||
kwargs.Set("restart", jsonutils.JSONTrue)
|
||||
}
|
||||
@@ -2847,7 +2852,13 @@ func (self *SGuest) AllowPerformRebuildRoot(ctx context.Context, userCred mcclie
|
||||
|
||||
func (self *SGuest) PerformRebuildRoot(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
imageId, _ := data.GetString("image_id")
|
||||
if !utils.IsInStringArray(self.Status, []string{VM_READY, VM_RUNNING, VM_ADMIN}) {
|
||||
|
||||
rebuildStatus, err := self.GetDriver().GetRebuildRootStatus()
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError(err.Error())
|
||||
}
|
||||
|
||||
if !utils.IsInStringArray(self.Status, rebuildStatus) {
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot reset root in status %s", self.Status)
|
||||
}
|
||||
|
||||
@@ -2899,9 +2910,7 @@ func (self *SGuest) PerformRebuildRoot(ctx context.Context, userCred mcclient.To
|
||||
}
|
||||
}
|
||||
|
||||
err := self.StartRebuildRootTask(ctx, userCred, imageId, needStop, autoStart, passwd, resetPasswd)
|
||||
return nil, err
|
||||
|
||||
return nil, self.StartRebuildRootTask(ctx, userCred, imageId, needStop, autoStart, passwd, resetPasswd)
|
||||
}
|
||||
|
||||
func (self *SGuest) StartRebuildRootTask(ctx context.Context, userCred mcclient.TokenCredential, imageId string, needStop, autoStart bool, passwd string, resetPasswd bool) error {
|
||||
@@ -3261,7 +3270,11 @@ func (self *SGuest) AllowPerformChangeConfig(ctx context.Context, userCred mccli
|
||||
}
|
||||
|
||||
func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
if !utils.IsInStringArray(self.Status, []string{VM_READY}) {
|
||||
changeStatus, err := self.GetDriver().GetChangeConfigStatus()
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError(err.Error())
|
||||
}
|
||||
if !utils.IsInStringArray(self.Status, changeStatus) {
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot change config in %s", self.Status)
|
||||
}
|
||||
if !self.GetDriver().AllowReconfigGuest() {
|
||||
|
||||
Reference in New Issue
Block a user