mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix(esxi): Separate detach disk and delete disk when rebuilding.
In previous versions, set `removeSpec.FileOperation = types.VirtualDeviceConfigSpecFileOperationDestroy' to delete disk indirectly. But, when its parent has only one child, the parent will be deleted along with it. And the consequence is failure to reinstall the system. Now, detach disk without deleteing backing file and then remove backing
This commit is contained in:
@@ -610,6 +610,28 @@ func (self *SDatastore) FilePutContent(ctx context.Context, remotePath string, c
|
||||
return self.Upload(ctx, remotePath, strings.NewReader(content))
|
||||
}
|
||||
|
||||
// Delete2 can delete file from this Datastore.
|
||||
// isNamespace: remotePath is uuid of namespace on vsan datastore
|
||||
// force: ignore nonexistent files and arguments
|
||||
func (self *SDatastore) Delete2(ctx context.Context, remotePath string, isNamespace, force bool) error {
|
||||
var err error
|
||||
ds := self.getDatastoreObj()
|
||||
dc := self.datacenter.getObjectDatacenter()
|
||||
if isNamespace {
|
||||
nm := object.NewDatastoreNamespaceManager(self.manager.client.Client)
|
||||
err = nm.DeleteDirectory(ctx, dc, remotePath)
|
||||
} else {
|
||||
fm := ds.NewFileManager(dc, force)
|
||||
err = fm.Delete(ctx, remotePath)
|
||||
}
|
||||
|
||||
if err != nil && types.IsFileNotFound(err) && force {
|
||||
// Ignore error
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SDatastore) Delete(ctx context.Context, remotePath string) error {
|
||||
url := self.GetPathUrl(remotePath)
|
||||
|
||||
|
||||
@@ -296,7 +296,7 @@ func (disk *SVirtualDisk) Delete(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
ds := istorage.(*SDatastore)
|
||||
return ds.DeleteVmdk(ctx, disk.getBackingInfo().GetFileName())
|
||||
return ds.Delete2(ctx, disk.getBackingInfo().GetFileName(), false, false)
|
||||
}
|
||||
|
||||
func (disk *SVirtualDisk) CreateISnapshot(ctx context.Context, name string, desc string) (cloudprovider.ICloudSnapshot, error) {
|
||||
|
||||
@@ -547,10 +547,6 @@ func (self *SVirtualMachine) doDetachDisk(ctx context.Context, vdisk *SVirtualDi
|
||||
removeSpec.Operation = types.VirtualDeviceConfigSpecOperationRemove
|
||||
removeSpec.Device = vdisk.dev
|
||||
|
||||
if remove {
|
||||
removeSpec.FileOperation = types.VirtualDeviceConfigSpecFileOperationDestroy
|
||||
}
|
||||
|
||||
spec := types.VirtualMachineConfigSpec{}
|
||||
spec.DeviceChange = []types.BaseVirtualDeviceConfigSpec{&removeSpec}
|
||||
|
||||
@@ -568,7 +564,10 @@ func (self *SVirtualMachine) doDetachDisk(ctx context.Context, vdisk *SVirtualDi
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
if !remove {
|
||||
return nil
|
||||
}
|
||||
return vdisk.Delete(ctx)
|
||||
}
|
||||
|
||||
func (self *SVirtualMachine) GetVNCInfo() (jsonutils.JSONObject, error) {
|
||||
|
||||
Reference in New Issue
Block a user