mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #1840 from ioito/hotfix/qx-guest-detach-disk
卸载磁盘时忽略云上磁盘已经被删除的错误
This commit is contained in:
@@ -161,6 +161,13 @@ func (self *SManagedVirtualizedGuestDriver) RequestDetachDisk(ctx context.Contex
|
||||
if len(disk.ExternalId) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
_, err = disk.GetIDisk()
|
||||
if err == cloudprovider.ErrNotFound {
|
||||
//忽略云上磁盘已经被删除错误
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
err = iVM.DetachDisk(ctx, disk.ExternalId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "iVM.DetachDisk")
|
||||
|
||||
@@ -18,10 +18,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/osprofile"
|
||||
"yunion.io/x/pkg/util/seclib"
|
||||
"yunion.io/x/pkg/utils"
|
||||
@@ -869,8 +871,10 @@ func (self *SRegion) DetachDisk(instanceId string, diskId string) error {
|
||||
log.Infof("Detach instance %s disk %s", instanceId, diskId)
|
||||
_, err := self.ecsRequest("DetachDisk", params)
|
||||
if err != nil {
|
||||
log.Errorf("DetachDisk %s to %s fail %s", diskId, instanceId, err)
|
||||
return err
|
||||
if strings.Contains(err.Error(), "The specified disk has not been attached on the specified instance") {
|
||||
return nil
|
||||
}
|
||||
return errors.Wrap(err, "DetachDisk")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -37,10 +37,10 @@ func init() {
|
||||
})
|
||||
|
||||
type DiskDeleteOptions struct {
|
||||
Instance string `help:"Instance ID"`
|
||||
ID string `help:"Instance ID"`
|
||||
}
|
||||
shellutils.R(&DiskDeleteOptions{}, "disk-delete", "List disks", func(cli *aliyun.SRegion, args *DiskDeleteOptions) error {
|
||||
e := cli.DeleteDisk(args.Instance)
|
||||
e := cli.DeleteDisk(args.ID)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/osprofile"
|
||||
|
||||
billing_api "yunion.io/x/onecloud/pkg/apis/billing"
|
||||
@@ -1029,7 +1030,17 @@ func (self *SRegion) DetachDisk(instanceId string, diskId string) error {
|
||||
params.SetVolumeId(diskId)
|
||||
log.Debugf("DetachDisk %s", params.String())
|
||||
_, err := self.ec2Client.DetachVolume(params)
|
||||
return err
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), fmt.Sprintf("'%s'is in the 'available' state", diskId)) {
|
||||
return nil
|
||||
}
|
||||
//InvalidVolume.NotFound: The volume 'vol-0a9eeda0a70a8d7fe' does not exist
|
||||
if strings.Contains(err.Error(), "InvalidVolume.NotFound") {
|
||||
return nil
|
||||
}
|
||||
return errors.Wrap(err, "ec2Client.DetachVolume")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SRegion) AttachDisk(instanceId string, diskId string, deviceName string) error {
|
||||
|
||||
@@ -37,10 +37,10 @@ func init() {
|
||||
})
|
||||
|
||||
type DiskDeleteOptions struct {
|
||||
Instance string `help:"Instance ID"`
|
||||
ID string `help:"Disk ID"`
|
||||
}
|
||||
shellutils.R(&DiskDeleteOptions{}, "disk-delete", "List disks", func(cli *aws.SRegion, args *DiskDeleteOptions) error {
|
||||
e := cli.DeleteDisk(args.Instance)
|
||||
e := cli.DeleteDisk(args.ID)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -1148,7 +1148,12 @@ func (self *SRegion) AttachDisk(instanceId string, diskId string, device string)
|
||||
// 默认非强制卸载。delete_flag=0
|
||||
func (self *SRegion) DetachDisk(instanceId string, diskId string) error {
|
||||
path := fmt.Sprintf("detachvolume/%s", diskId)
|
||||
return DoDeleteWithSpec(self.ecsClient.Servers.DeleteInContextWithSpec, nil, instanceId, path, nil, nil)
|
||||
err := DoDeleteWithSpec(self.ecsClient.Servers.DeleteInContextWithSpec, nil, instanceId, path, nil, nil)
|
||||
//volume a2091934-2669-4fca-8eb4-a950c1836b3c is not in server 49b053d2-f798-432f-af55-76eb6ef2c769 attach volume list => 磁盘已经被卸载了
|
||||
if err != nil && strings.Contains(err.Error(), fmt.Sprintf("is not in server")) && strings.Contains(err.Error(), fmt.Sprintf("attach volume list")) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// // https://support.huaweicloud.com/api-bpconsole/zh-cn_topic_0082522029.html
|
||||
|
||||
@@ -18,10 +18,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
billing_api "yunion.io/x/onecloud/pkg/apis/billing"
|
||||
@@ -744,8 +746,12 @@ func (self *SRegion) DetachDisk(instanceId string, diskId string) error {
|
||||
log.Infof("Detach instance %s disk %s", instanceId, diskId)
|
||||
_, err := self.cbsRequest("DetachDisks", params)
|
||||
if err != nil {
|
||||
log.Errorf("DetachDisks %s to %s fail %s", diskId, instanceId, err)
|
||||
return err
|
||||
// 可重复卸载,无报错,若磁盘被删除会有以下错误
|
||||
//[TencentCloudSDKError] Code=InvalidDisk.NotSupported, Message=disk(disk-4g5s7zhl) deleted (39a711ce2d17), RequestId=508d7fe3-e64e-4bb8-8ad7-39a711ce2d17
|
||||
if strings.Contains(err.Error(), fmt.Sprintf("disk(%s) deleted", diskId)) {
|
||||
return nil
|
||||
}
|
||||
return errors.Wrap(err, "DetachDisks")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -262,9 +262,13 @@ func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
}
|
||||
}
|
||||
|
||||
disks, err := self.host.zone.region.GetDisks("", "", diskIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
disks := []SDisk{}
|
||||
var err error
|
||||
if len(diskIds) > 0 {
|
||||
disks, err = self.host.zone.region.GetDisks("", "", diskIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
disks = append(disks, localDisks...)
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -449,7 +450,11 @@ func (instance *SInstance) DetachDisk(ctx context.Context, diskId string) error
|
||||
|
||||
func (region *SRegion) DetachDisk(instanceId, diskId string) error {
|
||||
url := fmt.Sprintf("volumes/%s/vm-instances?vmUuid=%s", diskId, instanceId)
|
||||
return region.client.delete(url, "", "")
|
||||
err := region.client.delete(url, "", "")
|
||||
if err != nil && strings.Contains(err.Error(), "is not attached to any vm") {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (instance *SInstance) DeleteVM(ctx context.Context) error {
|
||||
|
||||
@@ -357,6 +357,9 @@ func (cli *SZStackClient) wait(client *http.Client, header http.Header, action s
|
||||
}
|
||||
_, result, err := httputils.ParseJSONResponse(resp, err, cli.debug)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "not found") {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if time.Now().Sub(startTime) > timeout {
|
||||
|
||||
Reference in New Issue
Block a user