mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #11037 from ioito/automated-cherry-pick-of-#11036-upstream-release-3.7
Automated cherry pick of #11036: fix(region): aliyun nas endpoint
This commit is contained in:
@@ -123,6 +123,8 @@ type SAliyunClient struct {
|
||||
ownerId string
|
||||
ownerName string
|
||||
|
||||
nasEndpoints map[string]string
|
||||
|
||||
iregions []cloudprovider.ICloudRegion
|
||||
iBuckets []cloudprovider.ICloudBucket
|
||||
}
|
||||
@@ -130,6 +132,7 @@ type SAliyunClient struct {
|
||||
func NewAliyunClient(cfg *AliyunClientConfig) (*SAliyunClient, error) {
|
||||
client := SAliyunClient{
|
||||
AliyunClientConfig: cfg,
|
||||
nasEndpoints: map[string]string{},
|
||||
}
|
||||
err := client.fetchRegions()
|
||||
if err != nil {
|
||||
@@ -245,6 +248,41 @@ func _jsonRequest(client *sdk.Client, domain string, version string, apiName str
|
||||
return body, nil
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) getNasEndpoint(regionId string) string {
|
||||
err := self.fetchNasEndpoints()
|
||||
if err != nil {
|
||||
return "nas.aliyuncs.com"
|
||||
}
|
||||
ep, ok := self.nasEndpoints[regionId]
|
||||
if ok && len(ep) > 0 {
|
||||
return ep
|
||||
}
|
||||
return "nas.aliyuncs.com"
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) fetchNasEndpoints() error {
|
||||
if len(self.nasEndpoints) > 0 {
|
||||
return nil
|
||||
}
|
||||
client, err := self.getDefaultClient()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "getDefaultClient")
|
||||
}
|
||||
resp, err := jsonRequest(client, "nas.aliyuncs.com", ALIYUN_NAS_API_VERSION, "DescribeRegions", nil, self.debug)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "DescribeRegions")
|
||||
}
|
||||
regions := []SRegion{}
|
||||
err = resp.Unmarshal(®ions, "Regions", "Region")
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "resp.Unmarshal")
|
||||
}
|
||||
for _, region := range regions {
|
||||
self.nasEndpoints[region.RegionId] = region.RegionEndpoint
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) getDefaultClient() (*sdk.Client, error) {
|
||||
client, err := self.getSdkClient(ALIYUN_DEFAULT_REGION)
|
||||
return client, err
|
||||
|
||||
@@ -158,7 +158,8 @@ func (self *SRegion) nasRequest(action string, params map[string]string) (jsonut
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if self.GetCloudEnv() == ALIYUN_FINANCE_CLOUDENV {
|
||||
switch self.GetCloudEnv() {
|
||||
case ALIYUN_FINANCE_CLOUDENV:
|
||||
if strings.Contains(action, "FileSystem") {
|
||||
if self.RegionId == "cn-hangzhou" {
|
||||
params["RegionId"] = "cn-hangzhou-dg-a01"
|
||||
@@ -171,7 +172,8 @@ func (self *SRegion) nasRequest(action string, params map[string]string) (jsonut
|
||||
}
|
||||
}
|
||||
|
||||
return jsonRequest(client, "nas.aliyuncs.com", ALIYUN_NAS_API_VERSION, action, params, self.client.debug)
|
||||
endpint := self.GetClient().getNasEndpoint(self.RegionId)
|
||||
return jsonRequest(client, endpint, ALIYUN_NAS_API_VERSION, action, params, self.client.debug)
|
||||
}
|
||||
|
||||
func (self *SRegion) kvsRequest(action string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
|
||||
Reference in New Issue
Block a user