mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
fix: add more deetails for sub-snapshot/sub-backup/sub-images (#14197)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -14,7 +14,11 @@
|
||||
|
||||
package compute
|
||||
|
||||
import "yunion.io/x/onecloud/pkg/apis"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
const (
|
||||
INSTANCE_BACKUP_STATUS_CREATING = "creating"
|
||||
@@ -63,6 +67,30 @@ type InstanceBackupDetails struct {
|
||||
|
||||
// 主机快照大小
|
||||
Size int `json:"size"`
|
||||
|
||||
// 硬盘备份详情
|
||||
DiskBackups []SSimpleBackup `json:"disk_backups"`
|
||||
}
|
||||
|
||||
type SSimpleBackup struct {
|
||||
// 备份Id
|
||||
Id string `json:"id"`
|
||||
// 备份名称
|
||||
Name string `json:"name"`
|
||||
// 备份大小
|
||||
SizeMb int `json:"size_mb"`
|
||||
// 磁盘大小
|
||||
DiskSizeMb int `json:"disk_size_mb"`
|
||||
// 磁盘类型
|
||||
DiskType string `json:"disk_type"`
|
||||
// 备份存储Id
|
||||
BackupStorageId string `json:"backup_storage_id"`
|
||||
// 快照状态
|
||||
Status string `json:"status"`
|
||||
// 密钥
|
||||
EncryptKeyId string `json:"encrypt_key_id"`
|
||||
// 创建时间
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type InstanceBackupRecoveryInput struct {
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
|
||||
package compute
|
||||
|
||||
import "yunion.io/x/onecloud/pkg/apis"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
type SimpleSnapshot struct {
|
||||
// 快照Id
|
||||
@@ -33,6 +37,10 @@ type SimpleSnapshot struct {
|
||||
Status string `json:"status"`
|
||||
// 存储类型
|
||||
StorageType string `json:"storage_type"`
|
||||
// 密钥
|
||||
EncryptKeyId string `json:"encrypt_key_id"`
|
||||
// 创建时间
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type InstanceSnapshotDetails struct {
|
||||
|
||||
@@ -48,6 +48,9 @@ type SubImageInfo struct {
|
||||
Size int64 `json:"size"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
EncryptKeyId string `json:"encrypt_key_id"`
|
||||
DisableDelete bool `json:"disable_delete"`
|
||||
}
|
||||
|
||||
type GuestImageCreateInputBase struct {
|
||||
|
||||
@@ -1484,7 +1484,8 @@ func (manager *SGuestManager) validateCreateData(
|
||||
return nil, httperrors.NewInputParameterError("parse disk description error %s", err)
|
||||
}
|
||||
if diskConfig.DiskType == api.DISK_TYPE_SYS {
|
||||
return nil, httperrors.NewBadRequestError("Snapshot error: disk index %d > 0 but disk type is %s", i+1, api.DISK_TYPE_SYS)
|
||||
log.Warningf("Snapshot error: disk index %d > 0 but disk type is %s", i+1, api.DISK_TYPE_SYS)
|
||||
diskConfig.DiskType = api.DISK_TYPE_DATA
|
||||
}
|
||||
if len(diskConfig.Backend) == 0 {
|
||||
diskConfig.Backend = rootDiskConfig.Backend
|
||||
|
||||
@@ -200,6 +200,20 @@ func (self *SInstanceBackup) getMoreDetails(userCred mcclient.TokenCredential, o
|
||||
if backupStorage != nil {
|
||||
out.BackupStorageName = backupStorage.GetName()
|
||||
}
|
||||
backups, _ := self.GetBackups()
|
||||
out.DiskBackups = []api.SSimpleBackup{}
|
||||
for i := 0; i < len(backups); i++ {
|
||||
out.DiskBackups = append(out.DiskBackups, api.SSimpleBackup{
|
||||
Id: backups[i].Id,
|
||||
Name: backups[i].Name,
|
||||
SizeMb: backups[i].SizeMb,
|
||||
DiskSizeMb: backups[i].DiskSizeMb,
|
||||
DiskType: backups[i].DiskType,
|
||||
Status: backups[i].Status,
|
||||
EncryptKeyId: backups[i].EncryptKeyId,
|
||||
CreatedAt: backups[i].CreatedAt,
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
@@ -245,6 +245,8 @@ func (self *SInstanceSnapshot) getMoreDetails(userCred mcclient.TokenCredential,
|
||||
Size: snapshots[i].Size,
|
||||
Status: snapshots[i].Status,
|
||||
StorageType: snapshots[i].GetStorageType(),
|
||||
EncryptKeyId: snapshots[i].EncryptKeyId,
|
||||
CreatedAt: snapshots[i].CreatedAt,
|
||||
})
|
||||
out.Size += snapshots[i].Size
|
||||
|
||||
|
||||
@@ -54,6 +54,10 @@ func (self *DiskBackupRecoveryTask) OnInit(ctx context.Context, obj db.IStandalo
|
||||
input.ProjectDomainId = ownerId.GetProjectDomainId()
|
||||
input.ProjectId = ownerId.GetProjectId()
|
||||
|
||||
if backup.IsEncrypted() {
|
||||
input.EncryptKeyId = &backup.EncryptKeyId
|
||||
}
|
||||
|
||||
params := input.JSON(input)
|
||||
diskObj, err := db.DoCreate(models.DiskManager, ctx, self.UserCred, nil, params, ownerId)
|
||||
if err != nil {
|
||||
|
||||
@@ -315,6 +315,9 @@ func (self *SGuestImage) getMoreDetails(ctx context.Context, userCred mcclient.T
|
||||
Size: image.Size,
|
||||
Status: image.Status,
|
||||
CreatedAt: image.CreatedAt,
|
||||
|
||||
EncryptKeyId: image.EncryptKeyId,
|
||||
DisableDelete: image.Protected.Bool(),
|
||||
}
|
||||
out.MinRamMb = image.MinRamMB
|
||||
out.DiskFormat = image.DiskFormat
|
||||
@@ -328,6 +331,9 @@ func (self *SGuestImage) getMoreDetails(ctx context.Context, userCred mcclient.T
|
||||
Size: image.Size,
|
||||
Status: image.Status,
|
||||
CreatedAt: image.CreatedAt,
|
||||
|
||||
EncryptKeyId: image.EncryptKeyId,
|
||||
DisableDelete: image.Protected.Bool(),
|
||||
})
|
||||
}
|
||||
// make sure that the sort of dataimage is fixed
|
||||
|
||||
@@ -85,7 +85,7 @@ func (p *ClassMetadataPredicate) PreExecute(ctx context.Context, u *core.Unit, c
|
||||
case len(info.InstanceBackupId) > 0:
|
||||
obj, err := models.InstanceBackupManager.FetchById(info.InstanceBackupId)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "unable to fetch instanceBackup %s", info.InstanceSnapshotId)
|
||||
return false, errors.Wrapf(err, "unable to fetch instanceBackup %s", info.InstanceBackupId)
|
||||
}
|
||||
stand = obj.(db.IStandaloneModel)
|
||||
case len(info.InstanceSnapshotId) > 0:
|
||||
|
||||
Reference in New Issue
Block a user