add latitude & longitude info

This commit is contained in:
TangBin
2018-11-14 15:45:14 +08:00
parent 5f5a0e2fb7
commit 74c024c52e
5 changed files with 75 additions and 9 deletions
+5 -5
View File
@@ -369,7 +369,7 @@ func (self *SRegion) resetDisk(diskId, snapshotId string) error {
// 这里实际是回滚快照
disk, err := self.GetDisk(diskId)
if err != nil {
log.Debugf("resetDisk %s:%s",diskId, err.Error())
log.Debugf("resetDisk %s:%s", diskId, err.Error())
return err
}
@@ -378,11 +378,11 @@ func (self *SRegion) resetDisk(diskId, snapshotId string) error {
params.SetSize(int64(disk.Size))
params.SetVolumeType(disk.Category)
params.SetAvailabilityZone(disk.ZoneId)
tags,_ := disk.Tags.GetTagSpecifications()
tags, _ := disk.Tags.GetTagSpecifications()
params.SetTagSpecifications([]*ec2.TagSpecification{tags})
ret, err := self.ec2Client.CreateVolume(params)
if err != nil {
log.Debugf("resetDisk %s: %s",params.String(), err.Error())
log.Debugf("resetDisk %s: %s", params.String(), err.Error())
return err
}
@@ -394,7 +394,7 @@ func (self *SRegion) resetDisk(diskId, snapshotId string) error {
return err
}
err = self.ec2Client.WaitUntilVolumeAvailable(&ec2.DescribeVolumesInput{VolumeIds:[]*string{&diskId}})
err = self.ec2Client.WaitUntilVolumeAvailable(&ec2.DescribeVolumesInput{VolumeIds: []*string{&diskId}})
if err != nil {
log.Debugf("resetDisk :%s", err.Error())
return err
@@ -403,7 +403,7 @@ func (self *SRegion) resetDisk(diskId, snapshotId string) error {
err = self.AttachDisk(disk.InstanceId, *ret.VolumeId, disk.Device)
if err != nil {
log.Debugf("resetDisk %s %s %s: %s",disk.InstanceId, *ret.VolumeId, disk.Device, err.Error())
log.Debugf("resetDisk %s %s %s: %s", disk.InstanceId, *ret.VolumeId, disk.Device, err.Error())
return err
}
+23
View File
@@ -0,0 +1,23 @@
package aws
var LatitudeAndLongitude = map[string]map[string]float32{
"ap-south-1": {"latitude": 19.0759837, "longitude": 72.8776559},
"ap-northeast-3": {"latitude": 34.6937378, "longitude": 135.5021651},
"us-east-1": {"latitude": 37.4315734, "longitude": -78.6568942},
"us-east-2": {"latitude": 40.4172871, "longitude": -82.90712300000001},
"ap-southeast-2": {"latitude": -33.8688197, "longitude": 151.2092955},
"cn-northwest-1": {"latitude": 37.198731, "longitude": 106.1580937},
"eu-west-1": {"latitude": 53.41291, "longitude": -8.24389},
"eu-central-1": {"latitude": 50.1109221, "longitude": 8.6821267},
"sa-east-1": {"latitude": -23.5505199, "longitude": -46.63330939999999},
"ap-southeast-1": {"latitude": 1.352083, "longitude": 103.819836},
"ca-central-1": {"latitude": 56.130366, "longitude": -106.346771},
"ap-northeast-2": {"latitude": 37.566535, "longitude": 126.9779692},
"us-west-2": {"latitude": 43.8041334, "longitude": -120.5542012},
"us-gov-west-1": {"latitude": 37.09024, "longitude": -95.712891},
"us-west-1": {"latitude": 38.8375215, "longitude": -120.8958242},
"cn-north-1": {"latitude": 39.90419989999999, "longitude": 116.4073963},
"ap-northeast-1": {"latitude": 35.7090259, "longitude": 139.7319925},
"eu-west-2": {"latitude": 51.5073509, "longitude": -0.1277583},
"eu-west-3": {"latitude": 48.856614, "longitude": 2.3522219},
}
+45 -2
View File
@@ -2,6 +2,7 @@ package aws
import (
"fmt"
sdk "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
@@ -14,6 +15,28 @@ import (
"yunion.io/x/onecloud/pkg/compute/models"
)
var RegionLocations map[string]string = map[string]string{
"us-east-2": "美国东部(俄亥俄州)",
"us-east-1": "美国东部(弗吉尼亚北部)",
"us-west-1": "美国西部(加利福尼亚北部)",
"us-west-2": "美国西部(俄勒冈)",
"ap-south-1": "亚太地区(孟买)",
"ap-northeast-2": "亚太区域(首尔)",
"ap-northeast-3": "亚太区域(大阪)",
"ap-southeast-1": "亚太区域(新加坡)",
"ap-southeast-2": "亚太区域(悉尼)",
"ap-northeast-1": "亚太区域(东京)",
"ca-central-1": "加拿大(中部)",
"cn-north-1": "中国(北京)",
"cn-northwest-1": "中国(宁夏)",
"eu-central-1": "欧洲(法兰克福)",
"eu-west-1": "欧洲(爱尔兰)",
"eu-west-2": "欧洲(伦敦)",
"eu-west-3": "欧洲(巴黎)",
"sa-east-1": "南美洲(圣保罗)",
"us-gov-west-1": "AWS GovCloud(美国)",
}
type SRegion struct {
client *SAwsClient
ec2Client *ec2.EC2
@@ -164,6 +187,10 @@ func (self *SRegion) GetId() string {
}
func (self *SRegion) GetName() string {
if localName, ok := RegionLocations[self.RegionId]; ok {
return fmt.Sprintf("%s %s", CLOUD_PROVIDER_AWS_CN, localName)
}
return fmt.Sprintf("%s %s", CLOUD_PROVIDER_AWS_CN, self.RegionId)
}
@@ -188,11 +215,27 @@ func (self *SRegion) GetMetadata() *jsonutils.JSONDict {
}
func (self *SRegion) GetLatitude() float32 {
return 0.0
if data, ok := LatitudeAndLongitude[self.RegionId]; !ok {
log.Debugf("Region %s not found in LatitudeAndLongitude", self.RegionId)
return 0.0
} else if lat, ok := data["latitude"]; !ok {
log.Debugf("Region %s's latitude not found in LatitudeAndLongitude", self.RegionId)
return 0.0
} else {
return lat
}
}
func (self *SRegion) GetLongitude() float32 {
return 0.0
if data, ok := LatitudeAndLongitude[self.RegionId]; !ok {
log.Debugf("Region %s not found in LatitudeAndLongitude", self.RegionId)
return 0.0
} else if lat, ok := data["longitude"]; !ok {
log.Debugf("Region %s's latitude not found in LatitudeAndLongitude", self.RegionId)
return 0.0
} else {
return lat
}
}
func (self *SRegion) GetIZones() ([]cloudprovider.ICloudZone, error) {
+1 -1
View File
@@ -96,7 +96,7 @@ func (self *SSnapshot) Delete() error {
func (self *SSnapshot) GetRegionId() string {
// 这里特别注意:aws没有有uuid形式的region id
return self.region.Get
return self.region.GetId()
}
func (self *SRegion) GetSnapshots(instanceId string, diskId string, snapshotName string, snapshotIds []string, offset int, limit int) ([]SSnapshot, int, error) {
+1 -1
View File
@@ -309,7 +309,7 @@ func YunionSecRuleToAws(rule secrules.SecurityRule) ([]*ec2.IpPermission, error)
}
description := ""
if match, err := regexp.MatchString("^[\\sa-zA-Z0-9. _:/()#,@\\]\\[+=&;{}!$*-]+$", rule.Description);err == nil && match {
if match, err := regexp.MatchString("^[\\sa-zA-Z0-9. _:/()#,@\\]\\[+=&;{}!$*-]+$", rule.Description); err == nil && match {
description = rule.Description
}
ipranges := []*ec2.IpRange{}