mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
Merge pull request #600 from ioito/hotfix/qx-validate-rebuild-root
OpenStack加入重装系统参数校验
This commit is contained in:
@@ -112,6 +112,10 @@ func (self *SBaseGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{}, fmt.Errorf("This Guest driver dose not implement GetRebuildRootStatus")
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) IsRebuildRootSupportChangeImage() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) GetChangeConfigStatus() ([]string, error) {
|
||||
return []string{}, fmt.Errorf("This Guest driver dose not implement GetChangeConfigStatus")
|
||||
}
|
||||
|
||||
@@ -78,6 +78,10 @@ func (self *SOpenStackGuestDriver) IsNeedRestartForResetLoginInfo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SOpenStackGuestDriver) IsRebuildRootSupportChangeImage() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SOpenStackGuestDriver) GetDeployStatus() ([]string, error) {
|
||||
return []string{api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
@@ -870,6 +870,11 @@ func (self *SDisk) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenC
|
||||
}
|
||||
|
||||
func (self *SDisk) GetTemplateId() string {
|
||||
imageObj, err := CachedimageManager.FetchById(self.TemplateId)
|
||||
if err != nil || imageObj == nil {
|
||||
log.Errorf("failed to found disk %s(%s) templateId", self.Name, self.Id)
|
||||
return ""
|
||||
}
|
||||
return self.TemplateId
|
||||
}
|
||||
|
||||
|
||||
@@ -1123,6 +1123,16 @@ func (self *SGuest) PerformRebuildRoot(ctx context.Context, userCred mcclient.To
|
||||
return nil, httperrors.NewInputParameterError(err.Error())
|
||||
}
|
||||
|
||||
if !self.GetDriver().IsRebuildRootSupportChangeImage() && len(imageId) > 0 {
|
||||
templateId := self.GetTemplateId()
|
||||
if len(templateId) == 0 {
|
||||
return nil, httperrors.NewBadRequestError("No template for root disk, cannot rebuild root")
|
||||
}
|
||||
if imageId != templateId {
|
||||
return nil, httperrors.NewInputParameterError("%s not support rebuild root with a different image", self.GetDriver().GetHypervisor())
|
||||
}
|
||||
}
|
||||
|
||||
if !utils.IsInStringArray(self.Status, rebuildStatus) {
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot reset root in status %s", self.Status)
|
||||
}
|
||||
@@ -1163,13 +1173,17 @@ func (self *SGuest) PerformRebuildRoot(ctx context.Context, userCred mcclient.To
|
||||
return nil, self.StartRebuildRootTask(ctx, userCred, imageId, needStop, autoStart, passwd, resetPasswd, allDisks)
|
||||
}
|
||||
|
||||
func (self *SGuest) GetTemplateId() string {
|
||||
gdc := self.CategorizeDisks()
|
||||
return gdc.Root.GetTemplateId()
|
||||
}
|
||||
|
||||
func (self *SGuest) StartRebuildRootTask(ctx context.Context, userCred mcclient.TokenCredential, imageId string, needStop, autoStart bool, passwd string, resetPasswd bool, allDisk bool) error {
|
||||
data := jsonutils.NewDict()
|
||||
if len(imageId) == 0 {
|
||||
gdc := self.CategorizeDisks()
|
||||
imageId = gdc.Root.GetTemplateId()
|
||||
imageId = self.GetTemplateId()
|
||||
if len(imageId) == 0 {
|
||||
return httperrors.NewBadRequestError("No template for root disk")
|
||||
return httperrors.NewBadRequestError("No template for root disk, cannot rebuild root")
|
||||
}
|
||||
}
|
||||
data.Set("image_id", jsonutils.NewString(imageId))
|
||||
|
||||
@@ -127,6 +127,7 @@ type IGuestDriver interface {
|
||||
ValidateResizeDisk(guest *SGuest, disk *SDisk, storage *SStorage) error
|
||||
CanKeepDetachDisk() bool
|
||||
IsNeedRestartForResetLoginInfo() bool
|
||||
IsRebuildRootSupportChangeImage() bool
|
||||
|
||||
RequestDeleteDetachedDisk(ctx context.Context, disk *SDisk, task taskman.ITask, isPurge bool) error
|
||||
StartGuestDetachdiskTask(ctx context.Context, userCred mcclient.TokenCredential, guest *SGuest, params *jsonutils.JSONDict, parentTaskId string) error
|
||||
|
||||
@@ -3513,20 +3513,6 @@ func (manager *SGuestManager) GetSpecIdent(spec *jsonutils.JSONDict) []string {
|
||||
return specKeys
|
||||
}
|
||||
|
||||
func (self *SGuest) GetTemplateId() string {
|
||||
guestdisks := self.GetDisks()
|
||||
for _, guestdisk := range guestdisks {
|
||||
disk := guestdisk.GetDisk()
|
||||
if disk != nil {
|
||||
templateId := disk.GetTemplateId()
|
||||
if len(templateId) > 0 {
|
||||
return templateId
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SGuest) GetShortDesc(ctx context.Context) *jsonutils.JSONDict {
|
||||
desc := self.SVirtualResourceBase.GetShortDesc(ctx)
|
||||
desc.Set("mem", jsonutils.NewInt(int64(self.VmemSize)))
|
||||
|
||||
Reference in New Issue
Block a user