mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region,host): disconnect esxi disk on disk delete (#15298)
This commit is contained in:
@@ -317,5 +317,6 @@ type DiskAllocateFromBackupInput struct {
|
||||
}
|
||||
|
||||
type DiskDeleteInput struct {
|
||||
SkipRecycle *bool
|
||||
SkipRecycle *bool
|
||||
EsxiFlatFilePath string
|
||||
}
|
||||
|
||||
@@ -294,6 +294,9 @@ func (self *SKVMHostDriver) RequestDeallocateDiskOnHost(ctx context.Context, hos
|
||||
|
||||
url := fmt.Sprintf("/disks/%s/delete/%s", storage.Id, disk.Id)
|
||||
body := jsonutils.NewDict()
|
||||
if flatPath := disk.GetMetadata(ctx, api.DISK_META_ESXI_FLAT_FILE_PATH, nil); flatPath != "" {
|
||||
body.Set("esxi_flat_file_path", jsonutils.NewString(flatPath))
|
||||
}
|
||||
_, err := host.Request(ctx, task.GetUserCred(), "POST", url, header, body)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
|
||||
@@ -1505,9 +1505,6 @@ func (s *SKVMGuestInstance) Delete(ctx context.Context, migrated bool) error {
|
||||
if err := s.delTmpDisks(ctx, migrated); err != nil {
|
||||
return errors.Wrap(err, "delTmpDisks")
|
||||
}
|
||||
if err := s.delFlatFiles(ctx); err != nil {
|
||||
return errors.Wrap(err, "delFlatFiles")
|
||||
}
|
||||
output, err := procutils.NewCommand("rm", "-rf", s.HomeDir()).Output()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "rm %s failed: %s", s.HomeDir(), output)
|
||||
|
||||
@@ -33,6 +33,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/appctx"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostdeployer/deployclient"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostutils"
|
||||
"yunion.io/x/onecloud/pkg/hostman/options"
|
||||
"yunion.io/x/onecloud/pkg/hostman/storageman/remotefile"
|
||||
@@ -134,16 +135,14 @@ func (d *SLocalDisk) Delete(ctx context.Context, params interface{}) (jsonutils.
|
||||
return nil, err
|
||||
}
|
||||
d.UmountFuseImage()
|
||||
|
||||
/* ????????????????
|
||||
files = os.listdir(self.storage.path)
|
||||
for f in files:
|
||||
if f.startswith(self.id):
|
||||
if not re.match(r'[a-z0-9\-]*\.\d{14}', f):
|
||||
path = os.path.join(self.storage.path, f)
|
||||
print 'delete backing-file:', path
|
||||
self.storage.delete_diskfile(path)
|
||||
*/
|
||||
if p.EsxiFlatFilePath != "" {
|
||||
connections := &deployapi.EsxiDisksConnectionInfo{Disks: []*deployapi.EsxiDiskInfo{{DiskPath: p.EsxiFlatFilePath}}}
|
||||
_, err := deployclient.GetDeployClient().DisconnectEsxiDisks(ctx, connections)
|
||||
if err != nil {
|
||||
log.Errorf("Disconnect %s esxi disks failed %s", p.EsxiFlatFilePath, err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
d.Storage.RemoveDisk(d)
|
||||
return nil, nil
|
||||
|
||||
@@ -280,8 +280,9 @@ func diskCreate(ctx context.Context, userCred mcclient.TokenCredential, storage
|
||||
}
|
||||
|
||||
func diskDelete(ctx context.Context, userCred mcclient.TokenCredential, storage storageman.IStorage, diskId string, disk storageman.IDisk, body jsonutils.JSONObject) (interface{}, error) {
|
||||
flatPath, _ := body.GetString("esxi_flat_file_path")
|
||||
if disk != nil {
|
||||
hostutils.DelayTask(ctx, disk.Delete, compute.DiskDeleteInput{})
|
||||
hostutils.DelayTask(ctx, disk.Delete, compute.DiskDeleteInput{EsxiFlatFilePath: flatPath})
|
||||
} else {
|
||||
hostutils.DelayTask(ctx, nil, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user