mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): clirc with region (#15842)
This commit is contained in:
@@ -81,7 +81,7 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230118073927-53e52d3127cb
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230128105426-c27a4f0c1075
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
|
||||
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
|
||||
yunion.io/x/log v1.0.0
|
||||
|
||||
@@ -1158,8 +1158,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230118073927-53e52d3127cb h1:kyCp49u5lWCqhmLLC17KyszRAt92YNtaLa5i5yucKT0=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230118073927-53e52d3127cb/go.mod h1:yEMFtIKPyIdIfPzsw7oTcH41JXc8G5StUAQw3ZoGj5I=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230128105426-c27a4f0c1075 h1:LR6RixdJ5Ck7FFQ87AU9iyu9+QLbqFawntZDJkLv2X4=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230128105426-c27a4f0c1075/go.mod h1:yEMFtIKPyIdIfPzsw7oTcH41JXc8G5StUAQw3ZoGj5I=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656 h1:0zlZD5uhZoIHgLVAWCz2aHaYk2ZrNsACCYD7R6EIBII=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -1425,6 +1425,14 @@ func (provider *SCloudprovider) GetCloudproviderRegions() []SCloudproviderregion
|
||||
return CloudproviderRegionManager.fetchRecordsByQuery(q)
|
||||
}
|
||||
|
||||
func (provider *SCloudprovider) GetRegions() ([]SCloudregion, error) {
|
||||
q := CloudregionManager.Query()
|
||||
crcp := CloudproviderRegionManager.Query().SubQuery()
|
||||
q = q.Join(crcp, sqlchemy.Equals(q.Field("id"), crcp.Field("cloudregion_id"))).Filter(sqlchemy.Equals(crcp.Field("cloudprovider_id"), provider.Id))
|
||||
ret := []SCloudregion{}
|
||||
return ret, db.FetchModelObjects(CloudregionManager, q, &ret)
|
||||
}
|
||||
|
||||
func (provider *SCloudprovider) resetAutoSync() {
|
||||
cprs := provider.GetCloudproviderRegions()
|
||||
for i := range cprs {
|
||||
@@ -1721,8 +1729,21 @@ func (provider *SCloudprovider) GetDetailsClirc(ctx context.Context, userCred mc
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rc, err := cloudprovider.GetClientRC(provider.Name, accessUrl, provider.Account, passwd, provider.Provider, account.Options)
|
||||
info := cloudprovider.SProviderInfo{
|
||||
Name: provider.Name,
|
||||
Url: accessUrl,
|
||||
Account: provider.Account,
|
||||
Secret: passwd,
|
||||
Options: account.Options,
|
||||
}
|
||||
regions, err := provider.GetRegions()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetRegions")
|
||||
}
|
||||
if len(regions) > 0 {
|
||||
info.Region = fetchExternalId(regions[0].ExternalId)
|
||||
}
|
||||
rc, err := cloudprovider.GetClientRC(provider.Provider, info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1439,7 +1439,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230118073927-53e52d3127cb
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230128105426-c27a4f0c1075
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+2
-8
@@ -188,6 +188,7 @@ type SProviderInfo struct {
|
||||
Url string
|
||||
Account string
|
||||
Secret string
|
||||
Region string
|
||||
Options *jsonutils.JSONDict
|
||||
}
|
||||
|
||||
@@ -439,18 +440,11 @@ func GetProvider(cfg ProviderConfig) (ICloudProvider, error) {
|
||||
return driver.GetProvider(cfg)
|
||||
}
|
||||
|
||||
func GetClientRC(name, accessUrl, account, secret, provider string, options *jsonutils.JSONDict) (map[string]string, error) {
|
||||
func GetClientRC(provider string, info SProviderInfo) (map[string]string, error) {
|
||||
driver, err := GetProviderFactory(provider)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetProviderFactory")
|
||||
}
|
||||
info := SProviderInfo{
|
||||
Name: name,
|
||||
Url: accessUrl,
|
||||
Account: account,
|
||||
Secret: secret,
|
||||
Options: options,
|
||||
}
|
||||
return driver.GetClientRC(info)
|
||||
}
|
||||
|
||||
|
||||
+1
-8
@@ -139,19 +139,12 @@ func (self *SAzureProviderFactory) GetProvider(cfg cloudprovider.ProviderConfig)
|
||||
|
||||
func (self *SAzureProviderFactory) GetClientRC(info cloudprovider.SProviderInfo) (map[string]string, error) {
|
||||
tenantId, appId, appKey, subId := parseAccount(info.Account, info.Secret)
|
||||
defaultRegion := ""
|
||||
switch info.Url {
|
||||
case "AzurePublicCloud":
|
||||
defaultRegion = "eastus"
|
||||
case "AzureChinaCloud":
|
||||
defaultRegion = "chinaeast2"
|
||||
}
|
||||
return map[string]string{
|
||||
"AZURE_DIRECTORY_ID": tenantId,
|
||||
"AZURE_SUBSCRIPTION_ID": subId,
|
||||
"AZURE_APPLICATION_ID": appId,
|
||||
"AZURE_APPLICATION_KEY": appKey,
|
||||
"AZURE_REGION_ID": defaultRegion,
|
||||
"AZURE_REGION_ID": info.Region,
|
||||
"AZURE_CLOUD_ENV": info.Url,
|
||||
}, nil
|
||||
}
|
||||
|
||||
+3
-4
@@ -147,16 +147,15 @@ func (self *SHuaweiProviderFactory) GetProvider(cfg cloudprovider.ProviderConfig
|
||||
|
||||
func (self *SHuaweiProviderFactory) GetClientRC(info cloudprovider.SProviderInfo) (map[string]string, error) {
|
||||
accessKey, projectId := parseAccount(info.Account)
|
||||
region := huawei.HUAWEI_DEFAULT_REGION
|
||||
data := strings.Split(info.Name, "-")
|
||||
if len(data) >= 3 {
|
||||
region = strings.Join(data[len(data)-3:], "-")
|
||||
if len(info.Region) == 0 && len(data) >= 3 {
|
||||
info.Region = strings.Join(data[len(data)-3:], "-")
|
||||
}
|
||||
return map[string]string{
|
||||
"HUAWEI_CLOUD_ENV": info.Url,
|
||||
"HUAWEI_ACCESS_KEY": accessKey,
|
||||
"HUAWEI_SECRET": info.Secret,
|
||||
"HUAWEI_REGION": region,
|
||||
"HUAWEI_REGION": info.Region,
|
||||
"HUAWEI_PROJECT": projectId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user