fix: nas support create from encrypted snapshot (#14481)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2022-06-21 11:21:15 +08:00
committed by GitHub
co-authored by Qiu Jian
parent 85bb1f0c4f
commit ee61887eac
4 changed files with 19 additions and 6 deletions
+1 -1
View File
@@ -42,10 +42,10 @@ func Init(initPrivatePrefixes []string, cloudrootDir string) error {
}
linuxFsDrivers := []newRootFsDriverFunc{
NewCentosRootFs, NewFedoraRootFs,
NewFangdeRootFs, NewUnionOSRootFs,
NewAnolisRootFs, NewGalaxyKylinRootFs, NewRhelRootFs,
NewFangdeDeskRootfs, NewUKylinRootfs,
NewCentosRootFs, NewFedoraRootFs,
NewDebianRootFs, NewCirrosRootFs, NewCirrosNewRootFs, NewUbuntuRootFs,
NewGentooRootFs, NewArchLinuxRootFs, NewOpenWrtRootFs, NewCoreOsRootFs,
NewOpenEulerRootFs,
+2 -2
View File
@@ -55,7 +55,7 @@ type IDisk interface {
PrepareMigrate(liveMigrate bool) (string, error)
CreateFromUrl(ctx context.Context, url string, size int64, callback func(progress, progressMbps float64, totalSizeMb int64)) error
CreateFromTemplate(context.Context, string, string, int64, *apis.SEncryptInfo) (jsonutils.JSONObject, error)
CreateFromSnapshotLocation(ctx context.Context, location string, size int64) error
CreateFromSnapshotLocation(ctx context.Context, location string, size int64, encryptInfo *apis.SEncryptInfo) error
CreateFromRbdSnapshot(ctx context.Context, snapshotId, srcDiskId, srcPool string) error
CreateFromImageFuse(ctx context.Context, url string, size int64, encryptInfo *apis.SEncryptInfo) error
CreateRaw(ctx context.Context, sizeMb int, diskFromat string, fsFormat string,
@@ -112,7 +112,7 @@ func (d *SBaseDisk) CreateFromTemplate(context.Context, string, string, int64, *
return nil, fmt.Errorf("Not implemented")
}
func (d *SBaseDisk) CreateFromSnapshotLocation(ctx context.Context, location string, size int64) error {
func (d *SBaseDisk) CreateFromSnapshotLocation(ctx context.Context, location string, size int64, encryptInfo *apis.SEncryptInfo) error {
return fmt.Errorf("Not implemented")
}
+9 -2
View File
@@ -59,7 +59,7 @@ func (d *SNasDisk) CreateFromImageFuse(ctx context.Context, url string, size int
return fmt.Errorf("Not implemented")
}
func (d *SNasDisk) CreateFromSnapshotLocation(ctx context.Context, snapshotLocation string, size int64) error {
func (d *SNasDisk) CreateFromSnapshotLocation(ctx context.Context, snapshotLocation string, size int64, encryptInfo *apis.SEncryptInfo) error {
snapshotPath := path.Join(d.Storage.GetPath(), snapshotLocation)
newImg, err := qemuimg.NewQemuImage(d.GetPath())
if err != nil {
@@ -71,7 +71,11 @@ func (d *SNasDisk) CreateFromSnapshotLocation(ctx context.Context, snapshotLocat
return err
}
}
err = newImg.CreateQcow2(0, false, snapshotPath, "", "", "")
if encryptInfo != nil {
err = newImg.CreateQcow2(0, false, snapshotPath, encryptInfo.Key, qemuimg.EncryptFormatLuks, encryptInfo.Alg)
} else {
err = newImg.CreateQcow2(0, false, snapshotPath, "", "", "")
}
if err != nil {
return errors.Wrap(err, "create image from snapshot")
}
@@ -80,6 +84,9 @@ func (d *SNasDisk) CreateFromSnapshotLocation(ctx context.Context, snapshotLocat
if size > retSize {
params := jsonutils.NewDict()
params.Set("size", jsonutils.NewInt(size))
if encryptInfo != nil {
params.Set("encrypt_info", jsonutils.Marshal(encryptInfo))
}
_, err = d.Resize(ctx, params)
return err
}
+7 -1
View File
@@ -22,6 +22,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/onecloud/pkg/apis"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/hostman/hostutils"
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
@@ -94,5 +95,10 @@ func (s *SNasStorage) SyncStorageInfo() (jsonutils.JSONObject, error) {
}
func (s *SNasStorage) CreateDiskFromSnapshot(ctx context.Context, disk IDisk, input *SDiskCreateByDiskinfo) error {
return disk.CreateFromSnapshotLocation(ctx, input.DiskInfo.SnapshotUrl, int64(input.DiskInfo.DiskSizeMb))
info := input.DiskInfo
var encryptInfo *apis.SEncryptInfo
if info.Encryption {
encryptInfo = &info.EncryptInfo
}
return disk.CreateFromSnapshotLocation(ctx, input.DiskInfo.SnapshotUrl, int64(input.DiskInfo.DiskSizeMb), encryptInfo)
}