mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #8430 from tb365/feature/tb-qcloud-elb-support-multi-zones
Feature/tb qcloud elb support multi zones
This commit is contained in:
@@ -252,6 +252,10 @@ type LoadbalancerCreateInput struct {
|
||||
// LB的其他配置信息
|
||||
LBInfo jsonutils.JSONObject `json:"lb_info"`
|
||||
|
||||
// 从可用区1
|
||||
// required: false
|
||||
Zone1 string `json:"zone_1"`
|
||||
|
||||
// SLoadbalancer
|
||||
|
||||
VpcResourceInput
|
||||
|
||||
@@ -19,6 +19,7 @@ import "yunion.io/x/onecloud/pkg/util/billing"
|
||||
type SLoadbalancer struct {
|
||||
Name string
|
||||
ZoneID string
|
||||
SlaveZoneID string
|
||||
VpcID string
|
||||
NetworkIDs []string
|
||||
EipID string // eip id
|
||||
|
||||
@@ -96,6 +96,9 @@ type SLoadbalancer struct {
|
||||
|
||||
SLoadbalancerRateLimiter
|
||||
|
||||
// 备可用区
|
||||
Zone1 string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional" update:"user" json:"zone_1"`
|
||||
|
||||
// IP地址
|
||||
Address string `width:"128" charset:"ascii" nullable:"true" list:"user" create:"optional" json:"address"`
|
||||
// 地址类型
|
||||
@@ -463,6 +466,19 @@ func (lb *SLoadbalancer) GetCreateLoadbalancerParams(iRegion cloudprovider.IClou
|
||||
}
|
||||
params.ZoneID = iZone.GetId()
|
||||
}
|
||||
|
||||
if len(lb.Zone1) > 0 {
|
||||
z1 := ZoneManager.FetchZoneById(lb.Zone1)
|
||||
if z1 == nil {
|
||||
return nil, fmt.Errorf("failed to find zone 1 for lb %s", lb.Name)
|
||||
}
|
||||
iZone, err := iRegion.GetIZoneById(z1.ExternalId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetIZoneById")
|
||||
}
|
||||
params.SlaveZoneID = iZone.GetId()
|
||||
}
|
||||
|
||||
if lb.ChargeType == api.LB_CHARGE_TYPE_BY_BANDWIDTH {
|
||||
params.EgressMbps = lb.EgressMbps
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ func (self *SQcloudRegionDriver) GetProvider() string {
|
||||
|
||||
func (self *SQcloudRegionDriver) ValidateCreateLoadbalancerData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
zoneV := validators.NewModelIdOrNameValidator("zone", "zone", ownerId)
|
||||
zone1V := validators.NewModelIdOrNameValidator("zone_1", "zone", ownerId)
|
||||
vpcV := validators.NewModelIdOrNameValidator("vpc", "vpc", ownerId)
|
||||
managerIdV := validators.NewModelIdOrNameValidator("manager", "cloudprovider", ownerId)
|
||||
addressTypeV := validators.NewStringChoicesValidator("address_type", api.LB_ADDR_TYPES)
|
||||
@@ -81,6 +82,7 @@ func (self *SQcloudRegionDriver) ValidateCreateLoadbalancerData(ctx context.Cont
|
||||
"address_type": addressTypeV.Default(api.LB_ADDR_TYPE_INTRANET),
|
||||
"vpc": vpcV,
|
||||
"zone": zoneV,
|
||||
"zone_1": zone1V.Optional(true),
|
||||
"manager": managerIdV,
|
||||
}
|
||||
|
||||
@@ -111,6 +113,9 @@ func (self *SQcloudRegionDriver) ValidateCreateLoadbalancerData(ctx context.Cont
|
||||
return nil, fmt.Errorf("getting region failed")
|
||||
}
|
||||
|
||||
if zone1V.Model != nil && len(zone1V.Model.GetId()) > 0 && addressTypeV.Value == api.LB_ADDR_TYPE_INTERNET {
|
||||
data.Set("zone_1", jsonutils.NewString(zone1V.Model.GetId()))
|
||||
}
|
||||
data.Set("network_type", jsonutils.NewString(api.LB_NETWORK_TYPE_VPC))
|
||||
data.Set("cloudregion_id", jsonutils.NewString(region.GetId()))
|
||||
return self.SManagedVirtualizationRegionDriver.ValidateCreateLoadbalancerData(ctx, userCred, ownerId, data)
|
||||
|
||||
@@ -23,6 +23,7 @@ type LoadbalancerCreateOptions struct {
|
||||
ChargeType string `choices:"traffic|bandwidth"`
|
||||
Bandwidth int
|
||||
Zone string
|
||||
Zone1 string `json:"zone_1" help:"slave zone 1"`
|
||||
Cluster string `json:"cluster_id"`
|
||||
Manager string
|
||||
}
|
||||
|
||||
@@ -176,6 +176,7 @@ func (self *SRegion) CreateILoadBalancer(loadbalancer *cloudprovider.SLoadbalanc
|
||||
LoadBalancerType := "INTERNAL"
|
||||
if loadbalancer.AddressType == api.LB_ADDR_TYPE_INTERNET {
|
||||
LoadBalancerType = "OPEN"
|
||||
|
||||
}
|
||||
params := map[string]string{
|
||||
"LoadBalancerType": LoadBalancerType,
|
||||
@@ -189,6 +190,15 @@ func (self *SRegion) CreateILoadBalancer(loadbalancer *cloudprovider.SLoadbalanc
|
||||
|
||||
if loadbalancer.AddressType != api.LB_ADDR_TYPE_INTERNET {
|
||||
params["SubnetId"] = loadbalancer.NetworkIDs[0]
|
||||
} else {
|
||||
// 公网类型ELB可支持多可用区
|
||||
if len(loadbalancer.ZoneID) > 0 {
|
||||
if len(loadbalancer.SlaveZoneID) > 0 {
|
||||
params["MasterZoneId"] = loadbalancer.ZoneID
|
||||
} else {
|
||||
params["ZoneId"] = loadbalancer.ZoneID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := self.clbRequest("CreateLoadBalancer", params)
|
||||
|
||||
Reference in New Issue
Block a user