From 6e71ef5d5070790acdf758e16ef1f6fe0201db04 Mon Sep 17 00:00:00 2001 From: ioito Date: Wed, 8 Dec 2021 18:56:41 +0800 Subject: [PATCH] fix(region): google sync fix --- pkg/multicloud/google/eip.go | 17 +++++++++++------ pkg/multicloud/google/instance.go | 13 ++++++++----- pkg/multicloud/google/latitude_and_longitude.go | 4 +++- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/pkg/multicloud/google/eip.go b/pkg/multicloud/google/eip.go index 40015c89c0..aca30333e8 100644 --- a/pkg/multicloud/google/eip.go +++ b/pkg/multicloud/google/eip.go @@ -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 "" } diff --git a/pkg/multicloud/google/instance.go b/pkg/multicloud/google/instance.go index 04e835046c..f1e28526e8 100644 --- a/pkg/multicloud/google/instance.go +++ b/pkg/multicloud/google/instance.go @@ -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") } diff --git a/pkg/multicloud/google/latitude_and_longitude.go b/pkg/multicloud/google/latitude_and_longitude.go index 83f1c67663..ddaee27de9 100644 --- a/pkg/multicloud/google/latitude_and_longitude.go +++ b/pkg/multicloud/google/latitude_and_longitude.go @@ -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": "俄勒冈州",