Merge pull request #5470 from wanyaoqi/wyq/bugfix/region-misc-fix200311

region misc fix
This commit is contained in:
yunion-ci-robot
2020-03-12 17:31:18 +08:00
committed by GitHub
5 changed files with 34 additions and 7 deletions
+4
View File
@@ -29,6 +29,10 @@ type SimpleSnapshot struct {
CloudregionId string `json:"cloudregion_id"`
// 快照大小
Size int `json:"size"`
// 快照状态
Status string `json:"status"`
// 存储类型
StorageType string `json:"storage_type"`
}
type InstanceSnapshotDetails struct {
+10 -1
View File
@@ -3310,11 +3310,20 @@ func (self *SGuest) AllowPerformCreateBackup(ctx context.Context, userCred mccli
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "create-backup")
}
func (self *SGuest) guestDisksStorageTypeIsLocal() bool {
for _, gd := range self.GetDisks() {
if gd.GetDisk().GetStorage().StorageType != api.STORAGE_LOCAL {
return false
}
}
return true
}
func (self *SGuest) PerformCreateBackup(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
if len(self.BackupHostId) > 0 {
return nil, httperrors.NewBadRequestError("Already have backup server")
}
if self.getDefaultStorageType() != api.STORAGE_LOCAL {
if !self.guestDisksStorageTypeIsLocal() {
return nil, httperrors.NewBadRequestError("Cannot create backup with shared storage")
}
if self.Hypervisor != api.HYPERVISOR_KVM {
+5 -1
View File
@@ -4709,8 +4709,12 @@ func (self *SGuest) ToCreateInput(userCred mcclient.TokenCredential) *api.Server
if genInput.PreferZone != "" {
userInput.PreferZone = genInput.PreferZone
}
// clean GenerateName
// clean some of user input
userInput.GenerateName = ""
userInput.Description = ""
userInput.BillingType = ""
userInput.BillingCycle = ""
userInput.Duration = ""
return userInput
}
+8 -5
View File
@@ -66,6 +66,8 @@ type SInstanceSnapshot struct {
KeypairId string `width:"36" charset:"ascii" nullable:"true" list:"user"`
// 操作系统类型
OsType string `width:"36" charset:"ascii" nullable:"true" list:"user"`
// 套餐名称
InstanceType string `width:"64" charset:"utf8" nullable:"true" list:"user" create:"optional"`
}
type SInstanceSnapshotManager struct {
@@ -162,13 +164,12 @@ func (self *SInstanceSnapshot) getMoreDetails(userCred mcclient.TokenCredential,
DiskType: snapshots[i].DiskType,
CloudregionId: snapshots[i].CloudregionId,
Size: snapshots[i].Size,
Status: snapshots[i].Status,
StorageType: snapshots[i].GetStorageType(),
})
if len(snapshots[i].StorageId) > 0 {
storage := snapshots[i].GetStorage()
if storage != nil {
out.StorageType = storage.StorageType
}
if len(snapshots[i].StorageId) > 0 && out.StorageType == "" {
out.StorageType = snapshots[i].GetStorageType()
}
}
if len(osType) > 0 {
@@ -282,6 +283,7 @@ func (manager *SInstanceSnapshotManager) CreateInstanceSnapshot(
}
instanceSnapshot.OsType = guest.OsType
instanceSnapshot.ServerMetadata = serverMetadata
instanceSnapshot.InstanceType = guest.InstanceType
err := manager.TableSpec().Insert(instanceSnapshot)
if err != nil {
return nil, err
@@ -327,6 +329,7 @@ func (self *SInstanceSnapshot) ToInstanceCreateInput(
sourceInput.Secgroups = inputSecgs
}
sourceInput.OsType = self.OsType
sourceInput.InstanceType = self.InstanceType
// sourceInput.Networks = serverConfig.Networks
return sourceInput, nil
}
+7
View File
@@ -572,6 +572,13 @@ func (self *SSnapshot) GetStorage() *SStorage {
return StorageManager.FetchStorageById(self.StorageId)
}
func (self *SSnapshot) GetStorageType() string {
if storage := self.GetStorage(); storage != nil {
return storage.StorageType
}
return ""
}
func (self *SSnapshot) GetRegionDriver() IRegionDriver {
return self.GetRegion().GetDriver()
}