mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
huawei fetch regions&projects fix
This commit is contained in:
@@ -209,9 +209,9 @@ func (self *SBaseManager) jsonRequest(request requests.IRequest) (http.Header, j
|
||||
|
||||
switch err := e.(type) {
|
||||
case *HuaweiClientError:
|
||||
if err.Code == 499 && retry > 0 && request.GetMethod() == "GET" {
|
||||
if (err.Code == 499 || err.Code == 429 )&& retry > 0 && request.GetMethod() == "GET" {
|
||||
retry -= 1
|
||||
time.Sleep(time.Second * time.Duration(MAX_RETRY-retry))
|
||||
time.Sleep(3 * time.Second * time.Duration(MAX_RETRY-retry))
|
||||
} else if (err.Code == 404 || strings.Contains(err.Details, "could not be found") || strings.Contains(err.Details, "does not exist")) && request.GetMethod() != "POST" {
|
||||
return h, b, errors.Wrap(cloudprovider.ErrNotFound, err.Error())
|
||||
} else {
|
||||
|
||||
@@ -91,6 +91,9 @@ type SHuaweiClient struct {
|
||||
|
||||
iregions []cloudprovider.ICloudRegion
|
||||
iBuckets []cloudprovider.ICloudBucket
|
||||
|
||||
projects []SProject
|
||||
regions []SRegion
|
||||
}
|
||||
|
||||
// 进行资源操作时参数account 对应数据库cloudprovider表中的account字段,由accessKey和projectID两部分组成,通过"/"分割。
|
||||
@@ -163,10 +166,14 @@ func (self *SHuaweiClient) newGeneralAPIClient() (*client.Client, error) {
|
||||
|
||||
func (self *SHuaweiClient) fetchRegions() error {
|
||||
huawei, _ := self.newGeneralAPIClient()
|
||||
regions := make([]SRegion, 0)
|
||||
err := doListAll(huawei.Regions.List, nil, ®ions)
|
||||
if err != nil {
|
||||
return err
|
||||
if self.regions == nil {
|
||||
regions := make([]SRegion, 0)
|
||||
err := doListAll(huawei.Regions.List, nil, ®ions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
self.regions = regions
|
||||
}
|
||||
|
||||
filtedRegions := make([]SRegion, 0)
|
||||
@@ -177,7 +184,7 @@ func (self *SHuaweiClient) fetchRegions() error {
|
||||
}
|
||||
|
||||
regionId := strings.Split(project.Name, "_")[0]
|
||||
for _, region := range regions {
|
||||
for _, region := range self.regions {
|
||||
if region.ID == regionId {
|
||||
filtedRegions = append(filtedRegions, region)
|
||||
}
|
||||
@@ -186,7 +193,7 @@ func (self *SHuaweiClient) fetchRegions() error {
|
||||
self.isMainProject = true
|
||||
}
|
||||
} else {
|
||||
filtedRegions = regions
|
||||
filtedRegions = self.regions
|
||||
}
|
||||
|
||||
self.iregions = make([]cloudprovider.ICloudRegion, len(filtedRegions))
|
||||
|
||||
@@ -47,9 +47,17 @@ func (self *SProject) GetHealthStatus() string {
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) fetchProjects() ([]SProject, error) {
|
||||
if self.projects != nil {
|
||||
return self.projects, nil
|
||||
}
|
||||
|
||||
huawei, _ := self.newGeneralAPIClient()
|
||||
projects := make([]SProject, 0)
|
||||
err := doListAll(huawei.Projects.List, nil, &projects)
|
||||
if err == nil {
|
||||
self.projects = projects
|
||||
}
|
||||
|
||||
return projects, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user