diff --git a/pkg/apis/compute/instance_snapshot.go b/pkg/apis/compute/instance_snapshot.go index fbc2f0bc66..6d283339a9 100644 --- a/pkg/apis/compute/instance_snapshot.go +++ b/pkg/apis/compute/instance_snapshot.go @@ -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 { diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 4e45e789b8..019161100a 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -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 { diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 6c38778ffd..1d9c16c81e 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -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 } diff --git a/pkg/compute/models/instance_snapshots.go b/pkg/compute/models/instance_snapshots.go index a8b1b0b387..059f7c5176 100644 --- a/pkg/compute/models/instance_snapshots.go +++ b/pkg/compute/models/instance_snapshots.go @@ -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 } diff --git a/pkg/compute/models/snapshots.go b/pkg/compute/models/snapshots.go index 4e0712418e..f4cb935e30 100644 --- a/pkg/compute/models/snapshots.go +++ b/pkg/compute/models/snapshots.go @@ -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() }