From f6bf63fa89029f179ec306a553a362dc869a5b34 Mon Sep 17 00:00:00 2001 From: rainzm Date: Fri, 14 May 2021 14:59:53 +0800 Subject: [PATCH] fix(esxiagent): make the copied disk type as thin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 磁盘首选精简制备,但是copy disk默认是预分配,所以需要特别指定为 精简制备 --- pkg/multicloud/esxi/host.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/multicloud/esxi/host.go b/pkg/multicloud/esxi/host.go index 8223573b07..f2cdcb80ce 100644 --- a/pkg/multicloud/esxi/host.go +++ b/pkg/multicloud/esxi/host.go @@ -820,10 +820,24 @@ func (self *SHost) addDisks(ctx context.Context, dc *SDatacenter, ds *SDatastore return nil, errors.Wrapf(err, "SHost.FileUrlPathToDsPath") } newImagePath := fmt.Sprintf("[%s] %s/%s.vmdk", ds.GetRelName(), uuid, uuid) - fm := ds.getDatastoreObj().NewFileManager(dc.getObjectDatacenter(), true) - err = fm.Copy(ctx, imagePath, newImagePath) + + dm := object.NewVirtualDiskManager(self.manager.client.Client) + spec := &types.VirtualDiskSpec{ + DiskType: "thin", + } + switch disk.Driver { + case "", "scsi", "pvscsi": + spec.AdapterType = "lsiLogic" + default: + spec.AdapterType = "ide" + } + task, err := dm.CopyVirtualDisk(self.manager.context, imagePath, self.datacenter.getDcObj(), newImagePath, self.datacenter.getDcObj(), spec, true) if err != nil { - return nil, errors.Wrap(err, "unable to copy system disk") + return nil, errors.Wrap(err, "unable to CopyVirtualDisk") + } + err = task.Wait(self.manager.context) + if err != nil { + return nil, errors.Wrap(err, "waith CopyVirtualDiskTask") } imagePath = newImagePath rootDiskSizeMb = size