mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #8449 from tb365/bugfix/tb-bugfix-201023
Bugfix/tb bugfix 201023
This commit is contained in:
@@ -174,6 +174,7 @@ type LoadbalancerDetails struct {
|
||||
|
||||
VpcResourceInfoBase
|
||||
ZoneResourceInfoBase
|
||||
Zone1ResourceInfoBase
|
||||
NetworkResourceInfoBase
|
||||
|
||||
SLoadbalancer
|
||||
|
||||
@@ -88,13 +88,22 @@ type ZoneDetails struct {
|
||||
|
||||
type ZoneResourceInfoBase struct {
|
||||
// 可用区名称
|
||||
// example: zone1
|
||||
// example: 北京一区
|
||||
Zone string `json:"zone"`
|
||||
|
||||
// 纳管云的zoneId
|
||||
ZoneExtId string `json:"zone_ext_id"`
|
||||
}
|
||||
|
||||
type Zone1ResourceInfoBase struct {
|
||||
// 可用区名称
|
||||
// example: 北京2区
|
||||
Zone1Name string `json:"zone_1_name"`
|
||||
|
||||
// 纳管云的zoneId
|
||||
Zone1ExtId string `json:"zone_1_ext_id"`
|
||||
}
|
||||
|
||||
type ZoneResourceInfo struct {
|
||||
ZoneResourceInfoBase
|
||||
|
||||
|
||||
@@ -511,6 +511,7 @@ type ICloudLoadbalancer interface {
|
||||
GetNetworkIds() []string
|
||||
GetVpcId() string
|
||||
GetZoneId() string
|
||||
GetZone1Id() string // first slave zone
|
||||
GetLoadbalancerSpec() string
|
||||
GetChargeType() string
|
||||
GetEgressMbps() int
|
||||
|
||||
@@ -614,6 +614,7 @@ func (man *SLoadbalancerManager) FetchCustomizeColumns(
|
||||
regRows := man.SCloudregionResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
vpcRows := man.SVpcResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
zoneRows := man.SZoneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
zone1Rows := man.FetchZone1ResourceInfos(ctx, userCred, query, objs)
|
||||
netRows := man.SNetworkResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
|
||||
for i := range rows {
|
||||
@@ -625,6 +626,7 @@ func (man *SLoadbalancerManager) FetchCustomizeColumns(
|
||||
CloudregionResourceInfo: regRows[i],
|
||||
VpcResourceInfoBase: vpcRows[i].VpcResourceInfoBase,
|
||||
ZoneResourceInfoBase: zoneRows[i].ZoneResourceInfoBase,
|
||||
Zone1ResourceInfoBase: zone1Rows[i],
|
||||
NetworkResourceInfoBase: netRows[i].NetworkResourceInfoBase,
|
||||
}
|
||||
rows[i], _ = objs[i].(*SLoadbalancer).getMoreDetails(rows[i])
|
||||
@@ -632,6 +634,37 @@ func (man *SLoadbalancerManager) FetchCustomizeColumns(
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancerManager) FetchZone1ResourceInfos(ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
objs []interface{}) []api.Zone1ResourceInfoBase {
|
||||
rows := make([]api.Zone1ResourceInfoBase, len(objs))
|
||||
zoneIds := []string{}
|
||||
for i := range objs {
|
||||
zone1 := objs[i].(*SLoadbalancer).Zone1
|
||||
if len(zone1) > 0 {
|
||||
zoneIds = append(zoneIds, zone1)
|
||||
}
|
||||
}
|
||||
|
||||
zones := make(map[string]SZone)
|
||||
err := db.FetchStandaloneObjectsByIds(ZoneManager, zoneIds, &zones)
|
||||
if err != nil {
|
||||
log.Errorf("FetchStandaloneObjectsByIds fail %s", err)
|
||||
return rows
|
||||
}
|
||||
|
||||
for i := range objs {
|
||||
if zone, ok := zones[objs[i].(*SLoadbalancer).Zone1]; ok {
|
||||
rows[i].Zone1Name = zone.GetName()
|
||||
rows[i].Zone1ExtId = fetchExternalId(zone.GetExternalId())
|
||||
}
|
||||
}
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetExtraDetails(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
@@ -867,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()
|
||||
}
|
||||
@@ -1043,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
|
||||
})
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 ""
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 ""
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user