Skip to content

Commit

Permalink
fix: avoid purge storages
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Xuan committed Sep 25, 2020
1 parent 5d39338 commit f5cf093
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 16 deletions.
11 changes: 9 additions & 2 deletions pkg/multicloud/aliyun/zone.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 10 additions & 3 deletions pkg/multicloud/aws/zone.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions pkg/multicloud/azure/zone.go
Expand Up @@ -19,6 +19,7 @@ import (

"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"

"yunion.io/x/onecloud/pkg/cloudprovider"
)
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions pkg/multicloud/ctyun/zone.go
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"

"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"

"yunion.io/x/onecloud/pkg/cloudprovider"
)
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions pkg/multicloud/huawei/zone.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions pkg/multicloud/qcloud/zone.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions pkg/multicloud/ucloud/zone.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f5cf093

Please sign in to comment.