fix(region): google sync fix

This commit is contained in:
ioito
2021-12-08 18:56:41 +08:00
parent 2c69ed60b8
commit 6e71ef5d50
3 changed files with 22 additions and 12 deletions
+11 -6
View File
@@ -16,7 +16,6 @@ package google
import (
"fmt"
"strings"
"time"
"yunion.io/x/jsonutils"
@@ -34,6 +33,7 @@ type SAddress struct {
SResourceBase
multicloud.SEipBase
multicloud.GoogleTags
instanceId string
CreationTimestamp time.Time
Description string
@@ -80,10 +80,7 @@ func (addr *SAddress) GetProjectId() string {
}
func (addr *SAddress) IsEmulated() bool {
if addr.Id == addr.SelfLink {
return true
}
return false
return len(addr.instanceId) > 0
}
func (addr *SAddress) GetCreatedAt() time.Time {
@@ -129,8 +126,16 @@ func (addr *SAddress) GetAssociationType() string {
}
func (addr *SAddress) GetAssociationExternalId() string {
if len(addr.instanceId) > 0 {
return addr.instanceId
}
if len(addr.Users) > 0 {
return strings.TrimPrefix(addr.Users[0], fmt.Sprintf("%s/%s/", GOOGLE_COMPUTE_DOMAIN, GOOGLE_API_VERSION))
res := &SResourceBase{}
err := addr.region.GetBySelfId(addr.Users[0], res)
if err != nil {
return ""
}
return res.GetGlobalId()
}
return ""
}
+8 -5
View File
@@ -136,7 +136,8 @@ func (instance *SInstance) fetchMachineType() error {
if instance.guestCpus > 0 || instance.memoryMb > 0 || len(instance.machineType) > 0 {
return nil
}
machinetype, err := instance.host.zone.region.GetMachineType(instance.MachineType)
machinetype := SMachineType{}
err := instance.host.zone.region.GetBySelfId(instance.MachineType, &machinetype)
if err != nil {
return err
}
@@ -251,9 +252,10 @@ func (instance *SInstance) GetIEIP() (cloudprovider.ICloudEIP, error) {
return &eips[0], nil
}
eip := &SAddress{
region: instance.host.zone.region,
Status: "IN_USE",
Address: conf.NatIP,
region: instance.host.zone.region,
Status: "IN_USE",
Address: conf.NatIP,
instanceId: instance.Id,
}
eip.Id = instance.Id
eip.SelfLink = instance.SelfLink
@@ -353,7 +355,8 @@ func (instance *SInstance) GetSecurityGroupIds() ([]string, error) {
secgroupIds := []string{}
isecgroups := []cloudprovider.ICloudSecurityGroup{}
for _, networkinterface := range instance.NetworkInterfaces {
vpc, err := instance.host.zone.region.GetVpc(networkinterface.Subnetwork)
vpc := SVpc{region: instance.host.zone.region}
err := instance.host.zone.region.GetBySelfId(networkinterface.Subnetwork, &vpc)
if err != nil {
return nil, errors.Wrap(err, "GetGlobalNetwork")
}
@@ -50,6 +50,7 @@ var LatitudeAndLongitude = map[string]cloudprovider.SGeographicInfo{
"us-west2": api.RegionLosAngeles,
"us-west3": api.RegionSaltLakeCity,
"us-west4": api.RegionLasVegas,
"southamerica-west1": api.RegionSantiago,
}
var RegionNames = map[string]string{
@@ -76,7 +77,8 @@ var RegionNames = map[string]string{
"northamerica-northeast1": "蒙特利尔",
"northamerica-northeast2": "多伦多",
"southamerica-east1": "圣保罗",
"us-central1": "艾奥瓦",
"southamerica-west1": "圣地亚哥",
"us-central1": "爱荷华",
"us-east1": "南卡罗来纳州",
"us-east4": "北弗吉尼亚",
"us-west1": "俄勒冈州",