elb sync zone bugfix

This commit is contained in:
TangBin
2020-10-23 16:12:00 +08:00
parent 1f17dcf680
commit 94d3fa82af
10 changed files with 144 additions and 11 deletions
+1 -5
View File
@@ -98,11 +98,7 @@ type ZoneResourceInfoBase struct {
type Zone1ResourceInfoBase struct {
// 可用区名称
// example: 北京2区
Zone1 string `json:"zone_1"`
// 可用区ID
// example: cn-beijing-2
Zone1Id string `json:"zone_1_id"`
Zone1Name string `json:"zone_1_name"`
// 纳管云的zoneId
Zone1ExtId string `json:"zone_1_ext_id"`
+1
View File
@@ -511,6 +511,7 @@ type ICloudLoadbalancer interface {
GetNetworkIds() []string
GetVpcId() string
GetZoneId() string
GetZone1Id() string // first slave zone
GetLoadbalancerSpec() string
GetChargeType() string
GetEgressMbps() int
+25 -2
View File
@@ -657,8 +657,7 @@ func (lb *SLoadbalancerManager) FetchZone1ResourceInfos(ctx context.Context,
for i := range objs {
if zone, ok := zones[objs[i].(*SLoadbalancer).Zone1]; ok {
rows[i].Zone1 = zone.GetName()
rows[i].Zone1Id = zone.GetId()
rows[i].Zone1Name = zone.GetName()
rows[i].Zone1ExtId = zone.GetExternalId()
}
}
@@ -901,6 +900,12 @@ func (man *SLoadbalancerManager) newFromCloudLoadbalancer(ctx context.Context, u
}
}
if zoneId := extLb.GetZone1Id(); len(zoneId) > 0 {
if zone, err := db.FetchByExternalId(ZoneManager, zoneId); err == nil && zone != nil {
lb.Zone1 = zone.GetId()
}
}
if extLb.GetMetadata() != nil {
lb.LBInfo = extLb.GetMetadata()
}
@@ -1077,6 +1082,24 @@ func (lb *SLoadbalancer) SyncWithCloudLoadbalancer(ctx context.Context, userCred
}
}
if len(lb.ZoneId) == 0 {
extZoneId := extLb.GetZoneId()
if len(extZoneId) > 0 {
if zone, err := db.FetchByExternalId(ZoneManager, extZoneId); err == nil && zone != nil {
lb.ZoneId = zone.GetId()
}
}
}
if len(lb.Zone1) == 0 {
extZoneId := extLb.GetZone1Id()
if len(extZoneId) > 0 {
if zone, err := db.FetchByExternalId(ZoneManager, extZoneId); err == nil && zone != nil {
lb.Zone1 = zone.GetId()
}
}
}
return nil
})
+4
View File
@@ -141,6 +141,10 @@ func (lb *SLoadbalancer) GetZoneId() string {
return zone.GetGlobalId()
}
func (self *SLoadbalancer) GetZone1Id() string {
return ""
}
func (lb *SLoadbalancer) IsEmulated() bool {
return false
}
+15 -1
View File
@@ -170,7 +170,21 @@ func (self *SElb) GetZoneId() string {
}
sort.Strings(zones)
return zones[0]
if len(zones) > 0 {
z, err := self.region.getZoneById(zones[0])
if err != nil {
log.Infof("getZoneById %s %s", zones[0], err)
return ""
}
return z.GetGlobalId()
}
return ""
}
func (self *SElb) GetZone1Id() string {
return ""
}
func (self *SElb) GetLoadbalancerSpec() string {
+11 -1
View File
@@ -201,12 +201,22 @@ func (self *SLoadbalancer) GetVpcId() string {
func (self *SLoadbalancer) GetZoneId() string {
net := self.GetNetwork()
if net != nil {
return net.AvailabilityZone
z, err := self.region.getZoneById(net.AvailabilityZone)
if err != nil {
log.Infof("getZoneById %s %s", net.AvailabilityZone, err)
return ""
}
return z.GetGlobalId()
}
return ""
}
func (self *SLoadbalancer) GetZone1Id() string {
return ""
}
func (self *SLoadbalancer) GetLoadbalancerSpec() string {
return ""
}
+4
View File
@@ -200,6 +200,10 @@ func (lb *SLoadbalancer) GetZoneId() string {
return lb.AvailabilityZone
}
func (self *SLoadbalancer) GetZone1Id() string {
return ""
}
func (lb *SLoadbalancer) IsEmulated() bool {
return false
}
+49
View File
@@ -71,6 +71,14 @@ type SLoadbalancer struct {
CreateTime time.Time `json:"CreateTime"`
Isolation int64 `json:"Isolation"` // 0:表示未被隔离,1:表示被隔离。
SubnetId string `json:"SubnetId"`
BackupZoneSet []ZoneSet `json:"BackupZoneSet"`
MasterZone ZoneSet `json:"MasterZone"`
}
type ZoneSet struct {
Zone string `json:"Zone"`
ZoneID int64 `json:"ZoneId"`
ZoneName string `json:"ZoneName"`
}
func (self *SLoadbalancer) GetLoadbalancerSpec() string {
@@ -316,6 +324,47 @@ func (self *SLoadbalancer) GetVpcId() string {
}
func (self *SLoadbalancer) GetZoneId() string {
zoneId := ""
if len(self.MasterZone.Zone) > 0 {
zoneId = self.MasterZone.Zone
} else if len(self.SubnetId) > 0 {
net, err := self.region.GetNetwork(self.SubnetId)
if err != nil {
log.Warningf("GetNetwork %s %s", self.SubnetId, err)
return ""
}
zoneId = net.Zone
}
if len(zoneId) > 0 {
z, err := self.region.getZoneById(zoneId)
if err != nil {
log.Warningf("getZoneById %s %s", zoneId, err)
return ""
}
return z.GetGlobalId()
}
return ""
}
func (self *SLoadbalancer) GetZone1Id() string {
if self.BackupZoneSet == nil {
return ""
}
if len(self.BackupZoneSet) > 0 {
z, err := self.region.getZoneById(self.BackupZoneSet[0].Zone)
if err != nil {
log.Warningf("getZoneById %s %s", self.BackupZoneSet[0].Zone, err)
return ""
}
return z.GetGlobalId()
}
return ""
}
-2
View File
@@ -195,8 +195,6 @@ func (self *SRegion) CreateILoadBalancer(loadbalancer *cloudprovider.SLoadbalanc
if len(loadbalancer.ZoneID) > 0 {
if len(loadbalancer.SlaveZoneID) > 0 {
params["MasterZoneId"] = loadbalancer.ZoneID
} else {
params["ZoneId"] = loadbalancer.ZoneID
}
}
}
@@ -0,0 +1,34 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shell
import (
"yunion.io/x/onecloud/pkg/multicloud/qcloud"
"yunion.io/x/onecloud/pkg/util/shellutils"
)
func init() {
type LbListOptions struct {
}
shellutils.R(&LbListOptions{}, "lb-list", "List loadbalancers", func(cli *qcloud.SRegion, args *LbListOptions) error {
lbs, err := cli.GetILoadBalancers()
if err != nil {
return err
}
printList(lbs, 0, 0, 0, []string{})
return nil
})
}