From a8996ec9d11b6c292a6a8014ff07824883fcef13 Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Fri, 25 Sep 2020 19:13:35 +0800 Subject: [PATCH] fix: avoid purge storages --- pkg/multicloud/aliyun/zone.go | 11 +++++++++-- pkg/multicloud/aws/zone.go | 13 ++++++++++--- pkg/multicloud/azure/zone.go | 13 ++++++++++--- pkg/multicloud/ctyun/zone.go | 11 +++++++++-- pkg/multicloud/huawei/zone.go | 11 +++++++++-- pkg/multicloud/qcloud/zone.go | 10 ++++++++-- pkg/multicloud/ucloud/zone.go | 11 +++++++++-- 7 files changed, 64 insertions(+), 16 deletions(-) diff --git a/pkg/multicloud/aliyun/zone.go b/pkg/multicloud/aliyun/zone.go index b3e2d8a064..9aea632176 100644 --- a/pkg/multicloud/aliyun/zone.go +++ b/pkg/multicloud/aliyun/zone.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/pkg/errors" "yunion.io/x/pkg/utils" api "yunion.io/x/onecloud/pkg/apis/compute" @@ -202,14 +203,20 @@ func (self *SZone) getStorageByCategory(category string) (*SStorage, error) { func (self *SZone) GetIStorages() ([]cloudprovider.ICloudStorage, error) { if self.istorages == nil { - self.fetchStorages() + err := self.fetchStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchStorages") + } } return self.istorages, nil } func (self *SZone) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) { if self.istorages == nil { - self.fetchStorages() + err := self.fetchStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchStorages") + } } for i := 0; i < len(self.istorages); i += 1 { if self.istorages[i].GetGlobalId() == id { diff --git a/pkg/multicloud/aws/zone.go b/pkg/multicloud/aws/zone.go index 5f75ff65b3..6b12485bb2 100644 --- a/pkg/multicloud/aws/zone.go +++ b/pkg/multicloud/aws/zone.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/pkg/errors" api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -145,21 +146,27 @@ func (self *SZone) GetIHostById(id string) (cloudprovider.ICloudHost, error) { func (self *SZone) GetIStorages() ([]cloudprovider.ICloudStorage, error) { if self.istorages == nil { - self.fetchStorages() + err := self.fetchStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchStorages") + } } return self.istorages, nil } func (self *SZone) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) { if self.istorages == nil { - self.fetchStorages() + err := self.fetchStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchStorages") + } } for i := 0; i < len(self.istorages); i += 1 { if self.istorages[i].GetGlobalId() == id { return self.istorages[i], nil } } - return nil, ErrorNotFound() + return nil, errors.Wrapf(cloudprovider.ErrNotFound, "not found %s", id) } func (self *SZone) getStorageByCategory(category string) (*SStorage, error) { diff --git a/pkg/multicloud/azure/zone.go b/pkg/multicloud/azure/zone.go index 975fc7dc2e..b38e04311a 100644 --- a/pkg/multicloud/azure/zone.go +++ b/pkg/multicloud/azure/zone.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/pkg/errors" "yunion.io/x/onecloud/pkg/cloudprovider" ) @@ -117,16 +118,22 @@ func (self *SZone) fetchStorages() error { func (self *SZone) GetIStorages() ([]cloudprovider.ICloudStorage, error) { err := self.fetchStorages() if err != nil { - return nil, err + return nil, errors.Wrapf(err, "fetchStorages") + } + err = self.fetchClassicStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchClassicStorages") } - self.fetchClassicStorages() istorages := append(self.istorages, self.iclassicStorages...) return istorages, nil } func (self *SZone) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) { if self.istorages == nil { - self.fetchStorages() + err := self.fetchStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchStorages") + } } for i := 0; i < len(self.istorages); i += 1 { if self.istorages[i].GetGlobalId() == id { diff --git a/pkg/multicloud/ctyun/zone.go b/pkg/multicloud/ctyun/zone.go index 3202c54fe2..f73d8bc043 100644 --- a/pkg/multicloud/ctyun/zone.go +++ b/pkg/multicloud/ctyun/zone.go @@ -18,6 +18,7 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/pkg/errors" "yunion.io/x/onecloud/pkg/cloudprovider" ) @@ -94,14 +95,20 @@ func (self *SZone) GetIHostById(id string) (cloudprovider.ICloudHost, error) { func (self *SZone) GetIStorages() ([]cloudprovider.ICloudStorage, error) { if self.istorages == nil { - self.fetchStorages() + err := self.fetchStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchStorages") + } } return self.istorages, nil } func (self *SZone) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) { if self.istorages == nil { - self.fetchStorages() + err := self.fetchStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchStorages") + } } for i := 0; i < len(self.istorages); i += 1 { if self.istorages[i].GetGlobalId() == id { diff --git a/pkg/multicloud/huawei/zone.go b/pkg/multicloud/huawei/zone.go index 6741bb32cc..bb4e739393 100644 --- a/pkg/multicloud/huawei/zone.go +++ b/pkg/multicloud/huawei/zone.go @@ -18,6 +18,7 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/pkg/errors" api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -125,14 +126,20 @@ func (self *SZone) GetIHostById(id string) (cloudprovider.ICloudHost, error) { func (self *SZone) GetIStorages() ([]cloudprovider.ICloudStorage, error) { if self.istorages == nil { - self.fetchStorages() + err := self.fetchStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchStorages") + } } return self.istorages, nil } func (self *SZone) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) { if self.istorages == nil { - self.fetchStorages() + err := self.fetchStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchStorages") + } } for i := 0; i < len(self.istorages); i += 1 { if self.istorages[i].GetGlobalId() == id { diff --git a/pkg/multicloud/qcloud/zone.go b/pkg/multicloud/qcloud/zone.go index 13fd71d0ef..3df5c71dd7 100644 --- a/pkg/multicloud/qcloud/zone.go +++ b/pkg/multicloud/qcloud/zone.go @@ -170,7 +170,10 @@ func (self *SZone) fetchStorages() error { func (self *SZone) GetIStorages() ([]cloudprovider.ICloudStorage, error) { if self.istorages == nil { - self.fetchStorages() + err := self.fetchStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchStorages") + } } return self.istorages, nil } @@ -221,7 +224,10 @@ func (self *SZone) getStorageByCategory(category string) (*SStorage, error) { func (self *SZone) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) { if self.istorages == nil { - self.fetchStorages() + err := self.fetchStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchStorages") + } } for i := 0; i < len(self.istorages); i += 1 { if self.istorages[i].GetGlobalId() == id { diff --git a/pkg/multicloud/ucloud/zone.go b/pkg/multicloud/ucloud/zone.go index 6dc57c271b..82478f5f3e 100644 --- a/pkg/multicloud/ucloud/zone.go +++ b/pkg/multicloud/ucloud/zone.go @@ -18,6 +18,7 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/pkg/errors" api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -127,14 +128,20 @@ func (self *SZone) GetIHostById(id string) (cloudprovider.ICloudHost, error) { func (self *SZone) GetIStorages() ([]cloudprovider.ICloudStorage, error) { if self.istorages == nil { - self.fetchStorages() + err := self.fetchStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchStorages") + } } return self.istorages, nil } func (self *SZone) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) { if self.istorages == nil { - self.fetchStorages() + err := self.fetchStorages() + if err != nil { + return nil, errors.Wrapf(err, "fetchStorages") + } } for i := 0; i < len(self.istorages); i += 1 { if self.istorages[i].GetGlobalId() == id {