add azure region geographicinfo

This commit is contained in:
ioito
2019-06-19 17:17:39 +08:00
parent 5d7f7bc699
commit ba20c5fb7f
2 changed files with 29 additions and 4 deletions
+2
View File
@@ -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},
+27 -4
View File
@@ -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
}