mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
add azure region geographicinfo
This commit is contained in:
@@ -52,6 +52,8 @@ var AzureGeographicInfo = map[string]cloudprovider.SGeographicInfo{
|
||||
"westeurope": {City: api.CITY_HOLLAND, CountryCode: api.COUNTRY_CODE_NL}, //荷兰
|
||||
"canadaeast": {City: api.CITY_QUEBEC, CountryCode: api.COUNTRY_CODE_CA}, //加拿大 魁北克市
|
||||
"southindia": {City: api.CITY_KANCHIPURAM, CountryCode: api.COUNTRY_CODE_IN}, //印度 甘吉布勒姆
|
||||
"uaenorth": {City: api.CITY_DUBAI, CountryCode: api.COUNTRY_CODE_AE},
|
||||
"uaecentral": {City: api.CITY_DUBAI, CountryCode: api.COUNTRY_CODE_AE},
|
||||
|
||||
"chinaeast": {City: api.CITY_SHANG_HAI, CountryCode: api.COUNTRY_CODE_CN},
|
||||
"chinaeast2": {City: api.CITY_SHANG_HAI, CountryCode: api.COUNTRY_CODE_CN},
|
||||
|
||||
@@ -16,6 +16,8 @@ package azure
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -50,8 +52,8 @@ type SRegion struct {
|
||||
SubscriptionID string
|
||||
Name string
|
||||
DisplayName string
|
||||
Latitude float32
|
||||
Longitude float32
|
||||
Latitude string
|
||||
Longitude string
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -134,13 +136,34 @@ func (self *SRegion) GetProvider() string {
|
||||
return CLOUD_PROVIDER_AZURE
|
||||
}
|
||||
|
||||
func (self *SRegion) trimGeographicString(geographic string) string {
|
||||
return strings.TrimFunc(geographic, func(r rune) bool {
|
||||
return !((r >= '0' && r <= '9') || r == '.' || r == '-')
|
||||
})
|
||||
}
|
||||
|
||||
func (self *SRegion) GetGeographicInfo() cloudprovider.SGeographicInfo {
|
||||
info := cloudprovider.SGeographicInfo{}
|
||||
if geographicInfo, ok := AzureGeographicInfo[self.Name]; ok {
|
||||
info = geographicInfo
|
||||
}
|
||||
info.Latitude = self.Latitude
|
||||
info.Longitude = self.Longitude
|
||||
|
||||
self.Latitude = self.trimGeographicString(self.Latitude)
|
||||
self.Longitude = self.trimGeographicString(self.Longitude)
|
||||
|
||||
latitude, err := strconv.ParseFloat(self.Latitude, 32)
|
||||
if err != nil {
|
||||
log.Errorf("Parse azure region %s latitude %s error: %v", self.Name, self.Latitude, err)
|
||||
} else {
|
||||
info.Latitude = float32(latitude)
|
||||
}
|
||||
|
||||
longitude, err := strconv.ParseFloat(self.Longitude, 32)
|
||||
if err != nil {
|
||||
log.Errorf("Parse azure region %s longitude %s error: %v", self.Name, self.Longitude, err)
|
||||
} else {
|
||||
info.Latitude = float32(longitude)
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user