diff --git a/pkg/hostman/guestfs/fsdriver/drivers.go b/pkg/hostman/guestfs/fsdriver/drivers.go index 44993d48c3..573b409b3f 100644 --- a/pkg/hostman/guestfs/fsdriver/drivers.go +++ b/pkg/hostman/guestfs/fsdriver/drivers.go @@ -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, diff --git a/pkg/hostman/storageman/disk_base.go b/pkg/hostman/storageman/disk_base.go index e421fd8169..87f7ea5a61 100644 --- a/pkg/hostman/storageman/disk_base.go +++ b/pkg/hostman/storageman/disk_base.go @@ -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") } diff --git a/pkg/hostman/storageman/disk_nas.go b/pkg/hostman/storageman/disk_nas.go index d5cc841ac6..e4cbefabb6 100644 --- a/pkg/hostman/storageman/disk_nas.go +++ b/pkg/hostman/storageman/disk_nas.go @@ -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 } diff --git a/pkg/hostman/storageman/storage_nas.go b/pkg/hostman/storageman/storage_nas.go index b2eba7d138..c21928e80e 100644 --- a/pkg/hostman/storageman/storage_nas.go +++ b/pkg/hostman/storageman/storage_nas.go @@ -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) }