mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): aliyun sync by resource group (#15191)
This commit is contained in:
@@ -192,7 +192,8 @@ type ComputeOptions struct {
|
||||
|
||||
EnableAwsMonitorAgent bool `help:"enable aws monitor agent" default:"true"`
|
||||
|
||||
EnableTlsMigration bool `help:"Enable TLS migration" default:"false"`
|
||||
EnableTlsMigration bool `help:"Enable TLS migration" default:"false"`
|
||||
AliyunResourceGroups []string `help:"Only sync indicate resource group resource"`
|
||||
|
||||
esxi.EsxiOptions
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import (
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/util/httputils"
|
||||
)
|
||||
@@ -139,6 +140,8 @@ type SAliyunClient struct {
|
||||
nasEndpoints map[string]string
|
||||
vpcEndpoints map[string]string
|
||||
|
||||
resourceGroups []SResourceGroup
|
||||
|
||||
iregions []cloudprovider.ICloudRegion
|
||||
iBuckets []cloudprovider.ICloudBucket
|
||||
}
|
||||
@@ -443,6 +446,7 @@ func (self *SAliyunClient) imsRequest(apiName string, params map[string]string)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params = self.SetResourceGropuId(params)
|
||||
return jsonRequest(cli, "ims.aliyuncs.com", ALIYUN_IMS_API_VERSION, apiName, params, self.debug)
|
||||
}
|
||||
|
||||
@@ -459,6 +463,7 @@ func (self *SAliyunClient) ecsRequest(apiName string, params map[string]string)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params = self.SetResourceGropuId(params)
|
||||
return jsonRequest(cli, "ecs.aliyuncs.com", ALIYUN_API_VERSION, apiName, params, self.debug)
|
||||
}
|
||||
|
||||
@@ -467,6 +472,7 @@ func (self *SAliyunClient) pvtzRequest(apiName string, params map[string]string)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params = self.SetResourceGropuId(params)
|
||||
return jsonRequest(cli, "pvtz.aliyuncs.com", ALIYUN_PVTZ_API_VERSION, apiName, params, self.debug)
|
||||
}
|
||||
|
||||
@@ -475,6 +481,7 @@ func (self *SAliyunClient) alidnsRequest(apiName string, params map[string]strin
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params = self.SetResourceGropuId(params)
|
||||
return jsonRequest(cli, "alidns.aliyuncs.com", ALIYUN_ALIDNS_API_VERSION, apiName, params, self.debug)
|
||||
}
|
||||
|
||||
@@ -483,6 +490,7 @@ func (self *SAliyunClient) cbnRequest(apiName string, params map[string]string)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params = self.SetResourceGropuId(params)
|
||||
return jsonRequest(cli, "cbn.aliyuncs.com", ALIYUN_CBN_API_VERSION, apiName, params, self.debug)
|
||||
}
|
||||
|
||||
@@ -491,6 +499,7 @@ func (self *SAliyunClient) cdnRequest(apiName string, params map[string]string)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params = self.SetResourceGropuId(params)
|
||||
return jsonRequest(cli, "cdn.aliyuncs.com", ALIYUN_CDN_API_VERSION, apiName, params, self.debug)
|
||||
}
|
||||
|
||||
@@ -735,20 +744,55 @@ func (self *SAliyunClient) GetIStorageById(id string) (cloudprovider.ICloudStora
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
func (self *SAliyunClient) GetProjects() ([]SResourceGroup, error) {
|
||||
if len(self.resourceGroups) > 0 {
|
||||
return self.resourceGroups, nil
|
||||
}
|
||||
pageSize, pageNumber := 50, 1
|
||||
resourceGroups := []SResourceGroup{}
|
||||
self.resourceGroups = []SResourceGroup{}
|
||||
for {
|
||||
parts, total, err := self.GetResourceGroups(pageNumber, pageSize)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetResourceGroups")
|
||||
}
|
||||
resourceGroups = append(resourceGroups, parts...)
|
||||
if len(resourceGroups) >= total {
|
||||
self.resourceGroups = append(self.resourceGroups, parts...)
|
||||
if len(self.resourceGroups) >= total {
|
||||
break
|
||||
}
|
||||
pageNumber += 1
|
||||
}
|
||||
return self.resourceGroups, nil
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) SetResourceGropuId(params map[string]string) map[string]string {
|
||||
if params == nil {
|
||||
params = map[string]string{}
|
||||
}
|
||||
for _, groupId := range options.Options.AliyunResourceGroups {
|
||||
if utils.IsInStringArray(groupId, self.GetResourceGroupIds()) {
|
||||
params["ResourceGroupId"] = groupId
|
||||
}
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) GetResourceGroupIds() []string {
|
||||
ret := []string{}
|
||||
resourceGroups, err := self.GetProjects()
|
||||
if err != nil {
|
||||
return ret
|
||||
}
|
||||
for i := range resourceGroups {
|
||||
ret = append(ret, resourceGroups[i].Id)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
resourceGroups, err := self.GetProjects()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := []cloudprovider.ICloudProject{}
|
||||
for i := range resourceGroups {
|
||||
ret = append(ret, &resourceGroups[i])
|
||||
|
||||
@@ -137,6 +137,7 @@ func (self *SRegion) ecsRequest(apiName string, params map[string]string) (jsonu
|
||||
if len(endpoint) == 0 {
|
||||
endpoint = "ecs.aliyuncs.com"
|
||||
}
|
||||
params = self.client.SetResourceGropuId(params)
|
||||
return jsonRequest(client, endpoint, ALIYUN_API_VERSION, apiName, params, self.client.debug)
|
||||
}
|
||||
|
||||
@@ -148,6 +149,7 @@ func (self *SRegion) wafRequest(apiName string, params map[string]string) (jsonu
|
||||
if self.RegionId != "cn-hangzhou" && self.RegionId != "ap-southeast-1" {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
}
|
||||
params = self.client.SetResourceGropuId(params)
|
||||
endpoint := fmt.Sprintf("wafopenapi.%s.aliyuncs.com", self.RegionId)
|
||||
return jsonRequest(client, endpoint, ALIYUN_WAF_API_VERSION, apiName, params, self.client.debug)
|
||||
}
|
||||
@@ -157,6 +159,7 @@ func (self *SRegion) esRequest(apiName string, params map[string]string) (jsonut
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params = self.client.SetResourceGropuId(params)
|
||||
domain := fmt.Sprintf("elasticsearch.%s.aliyuncs.com", self.RegionId)
|
||||
return jsonRequest(client, domain, ALIYUN_ES_API_VERSION, apiName, params, self.client.debug)
|
||||
}
|
||||
@@ -166,6 +169,7 @@ func (self *SRegion) kafkaRequest(apiName string, params map[string]string) (jso
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params = self.client.SetResourceGropuId(params)
|
||||
domain := fmt.Sprintf("alikafka.%s.aliyuncs.com", self.RegionId)
|
||||
return jsonRequest(client, domain, ALIYUN_KAFKA_API_VERSION, apiName, params, self.client.debug)
|
||||
}
|
||||
@@ -175,6 +179,7 @@ func (self *SRegion) rdsRequest(apiName string, params map[string]string) (jsonu
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params = self.client.SetResourceGropuId(params)
|
||||
return jsonRequest(client, "rds.aliyuncs.com", ALIYUN_RDS_API_VERSION, apiName, params, self.client.debug)
|
||||
}
|
||||
|
||||
@@ -183,6 +188,7 @@ func (self *SRegion) k8sRequest(apiName string, params map[string]string) (jsonu
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params = self.client.SetResourceGropuId(params)
|
||||
return jsonRequest(client, fmt.Sprintf("cs.%s.aliyuncs.com", self.RegionId), ALIYUN_K8S_API_VERSION, apiName, params, self.client.debug)
|
||||
}
|
||||
|
||||
@@ -191,6 +197,7 @@ func (self *SRegion) mongodbRequest(apiName string, params map[string]string) (j
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params = self.client.SetResourceGropuId(params)
|
||||
return jsonRequest(client, "mongodb.aliyuncs.com", ALIYUN_MONGO_DB_API_VERSION, apiName, params, self.client.debug)
|
||||
}
|
||||
|
||||
@@ -199,6 +206,7 @@ func (self *SRegion) vpcRequest(action string, params map[string]string) (jsonut
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params = self.client.SetResourceGropuId(params)
|
||||
endpoint := self.GetClient().getVpcEndpoint(self.RegionId)
|
||||
return jsonRequest(client, endpoint, ALIYUN_API_VERSION_VPC, action, params, self.client.debug)
|
||||
}
|
||||
@@ -222,6 +230,7 @@ func (self *SRegion) nasRequest(action string, params map[string]string) (jsonut
|
||||
}
|
||||
}
|
||||
|
||||
params = self.client.SetResourceGropuId(params)
|
||||
endpint := self.GetClient().getNasEndpoint(self.RegionId)
|
||||
return jsonRequest(client, endpint, ALIYUN_NAS_API_VERSION, action, params, self.client.debug)
|
||||
}
|
||||
@@ -236,6 +245,7 @@ func (self *SRegion) kvsRequest(action string, params map[string]string) (jsonut
|
||||
params["RegionId"] = transRegionIdFromEcsRegionId(self, "redis")
|
||||
}
|
||||
|
||||
params = self.client.SetResourceGropuId(params)
|
||||
return jsonRequest(client, "r-kvstore.aliyuncs.com", ALIYUN_API_VERSION_KVS, action, params, self.client.debug)
|
||||
}
|
||||
|
||||
@@ -282,6 +292,7 @@ func (self *SRegion) lbRequest(apiName string, params map[string]string) (jsonut
|
||||
domain = endpoint
|
||||
}
|
||||
}
|
||||
params = self.client.SetResourceGropuId(params)
|
||||
return self._lbRequest(client, apiName, domain, params)
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ func (self *SAliyunClient) otsRequest(apiName string, params map[string]string)
|
||||
return nil, err
|
||||
}
|
||||
regionId, _ := params["RegionId"]
|
||||
params = self.SetResourceGropuId(params)
|
||||
return jsonRequest(cli, fmt.Sprintf("ots.%s.aliyuncs.com", regionId), ALIYUN_OTS_API_VERSION, apiName, params, self.debug)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user