mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
fix(region): vender update
This commit is contained in:
@@ -84,7 +84,7 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221122080533-206029d5c6ae
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221122135203-3316ad5fc700
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
|
||||
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
|
||||
yunion.io/x/log v1.0.0
|
||||
|
||||
@@ -1176,8 +1176,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221122080533-206029d5c6ae h1:5ZtQgXE0pDq6Zb+8eiOdi2133yvQ99vcOvTTft8R6lc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221122080533-206029d5c6ae/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221122135203-3316ad5fc700 h1:qrzb/D3fktCw6Ovi4kgxJk60EAFVrWp0eSuUd7zM63c=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221122135203-3316ad5fc700/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656 h1:0zlZD5uhZoIHgLVAWCz2aHaYk2ZrNsACCYD7R6EIBII=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -355,14 +355,12 @@ func (lbbg *SLoadbalancerBackendGroup) RefCount() (int, error) {
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) refCount(man db.IModelManager) (int, error) {
|
||||
t := man.TableSpec().Instance()
|
||||
return t.Query().Equals("backend_group_id", lbbg.Id).CountWithError()
|
||||
return man.Query().Equals("backend_group_id", lbbg.Id).CountWithError()
|
||||
}
|
||||
|
||||
func lbbgRefManagers() []db.IModelManager {
|
||||
return []db.IModelManager{
|
||||
LoadbalancerListenerManager,
|
||||
LoadbalancerListenerRuleManager,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,34 +549,6 @@ func (lbbg *SLoadbalancerBackendGroup) GetListener() *SLoadbalancerListener {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) GetBackendGroupParams() (*cloudprovider.SLoadbalancerBackendGroup, error) {
|
||||
backends, err := lbbg.GetBackendsParams()
|
||||
if err != nil {
|
||||
return &cloudprovider.SLoadbalancerBackendGroup{}, err
|
||||
}
|
||||
|
||||
listener := lbbg.GetListener()
|
||||
listenerId := ""
|
||||
if listener != nil {
|
||||
listenerId = listener.ExternalId
|
||||
}
|
||||
|
||||
ret := &cloudprovider.SLoadbalancerBackendGroup{
|
||||
Name: lbbg.Name,
|
||||
GroupType: lbbg.Type,
|
||||
Backends: backends,
|
||||
ListenerID: listenerId,
|
||||
}
|
||||
|
||||
loadbalancer, _ := lbbg.GetLoadbalancer()
|
||||
if loadbalancer != nil {
|
||||
ret.VpcId = loadbalancer.VpcId
|
||||
ret.LoadbalancerID = loadbalancer.ExternalId
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) GetBackendsParams() ([]cloudprovider.SLoadbalancerBackend, error) {
|
||||
backends, err := lbbg.GetBackends()
|
||||
if err != nil {
|
||||
|
||||
@@ -87,6 +87,14 @@ func (self *SHuaWeiRegionDriver) ValidateCreateLoadbalancerData(ctx context.Cont
|
||||
return self.SManagedVirtualizationRegionDriver.ValidateCreateLoadbalancerData(ctx, userCred, ownerId, input)
|
||||
}
|
||||
|
||||
func (self *SHuaWeiRegionDriver) ValidateCreateLoadbalancerBackendGroupData(ctx context.Context, userCred mcclient.TokenCredential, lb *models.SLoadbalancer, input *api.LoadbalancerBackendGroupCreateInput) (*api.LoadbalancerBackendGroupCreateInput, error) {
|
||||
return self.SManagedVirtualizationRegionDriver.ValidateCreateLoadbalancerBackendGroupData(ctx, userCred, lb, input)
|
||||
}
|
||||
|
||||
func (self *SHuaWeiRegionDriver) RequestCreateLoadbalancerBackendGroup(ctx context.Context, userCred mcclient.TokenCredential, lbbg *models.SLoadbalancerBackendGroup, task taskman.ITask) error {
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SHuaWeiRegionDriver) ValidateCreateLoadbalancerBackendData(ctx context.Context, userCred mcclient.TokenCredential,
|
||||
lb *models.SLoadbalancer, lbbg *models.SLoadbalancerBackendGroup,
|
||||
input *api.LoadbalancerBackendCreateInput) (*api.LoadbalancerBackendCreateInput, error) {
|
||||
@@ -96,9 +104,164 @@ func (self *SHuaWeiRegionDriver) ValidateCreateLoadbalancerBackendData(ctx conte
|
||||
func (self *SHuaWeiRegionDriver) ValidateCreateLoadbalancerListenerData(ctx context.Context, userCred mcclient.TokenCredential,
|
||||
ownerId mcclient.IIdentityProvider, input *api.LoadbalancerListenerCreateInput,
|
||||
lb *models.SLoadbalancer, lbbg *models.SLoadbalancerBackendGroup) (*api.LoadbalancerListenerCreateInput, error) {
|
||||
if len(lbbg.ExternalId) > 0 {
|
||||
return input, httperrors.NewResourceBusyError("loadbalancer backend group %s has aleady used by other listener", lbbg.Name)
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SHuaWeiRegionDriver) RequestCreateLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lblis *models.SLoadbalancerListener, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
lbbg, err := lblis.GetLoadbalancerBackendGroup()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetLoadbalancerBackendGroup")
|
||||
}
|
||||
lb, err := lblis.GetLoadbalancer()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetLoadbalancer")
|
||||
}
|
||||
iLb, err := lb.GetILoadbalancer(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetILoadbalancer")
|
||||
}
|
||||
|
||||
if len(lbbg.ExternalId) == 0 {
|
||||
lbbgOpts := &cloudprovider.SLoadbalancerBackendGroup{
|
||||
Name: lbbg.Name,
|
||||
Scheduler: lblis.Scheduler,
|
||||
Protocol: lblis.ListenerType,
|
||||
}
|
||||
|
||||
iLbbg, err := iLb.CreateILoadBalancerBackendGroup(lbbgOpts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "CreateILoadBalancerBackendGroup")
|
||||
}
|
||||
err = db.SetExternalId(lbbg, userCred, iLbbg.GetGlobalId())
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "db.SetExternalId")
|
||||
}
|
||||
}
|
||||
|
||||
opts := &cloudprovider.SLoadbalancerListenerCreateOptions{
|
||||
Name: lblis.Name,
|
||||
Description: lblis.Description,
|
||||
ListenerType: lblis.ListenerType,
|
||||
ListenerPort: lblis.ListenerPort,
|
||||
Scheduler: lblis.Scheduler,
|
||||
EnableHTTP2: lblis.EnableHttp2,
|
||||
EgressMbps: lblis.EgressMbps,
|
||||
EstablishedTimeout: lblis.BackendConnectTimeout,
|
||||
AccessControlListStatus: lblis.AclStatus,
|
||||
BackendGroupId: lbbg.ExternalId,
|
||||
|
||||
ClientRequestTimeout: lblis.ClientRequestTimeout,
|
||||
ClientIdleTimeout: lblis.ClientIdleTimeout,
|
||||
BackendIdleTimeout: lblis.BackendIdleTimeout,
|
||||
BackendConnectTimeout: lblis.BackendConnectTimeout,
|
||||
|
||||
HealthCheckReq: lblis.HealthCheckReq,
|
||||
HealthCheckExp: lblis.HealthCheckExp,
|
||||
|
||||
HealthCheck: lblis.HealthCheck,
|
||||
HealthCheckType: lblis.HealthCheckType,
|
||||
HealthCheckTimeout: lblis.HealthCheckTimeout,
|
||||
HealthCheckDomain: lblis.HealthCheckDomain,
|
||||
HealthCheckHttpCode: lblis.HealthCheckHttpCode,
|
||||
HealthCheckURI: lblis.HealthCheckURI,
|
||||
HealthCheckInterval: lblis.HealthCheckInterval,
|
||||
|
||||
HealthCheckRise: lblis.HealthCheckRise,
|
||||
HealthCheckFail: lblis.HealthCheckFall,
|
||||
|
||||
StickySession: lblis.StickySession,
|
||||
StickySessionType: lblis.StickySessionType,
|
||||
StickySessionCookie: lblis.StickySessionCookie,
|
||||
StickySessionCookieTimeout: lblis.StickySessionCookieTimeout,
|
||||
|
||||
BackendServerPort: lblis.BackendServerPort,
|
||||
XForwardedFor: lblis.XForwardedFor,
|
||||
TLSCipherPolicy: lblis.TLSCipherPolicy,
|
||||
Gzip: lblis.Gzip,
|
||||
}
|
||||
iLis, err := iLb.CreateILoadBalancerListener(ctx, opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "CreateILoadBalancerListener")
|
||||
}
|
||||
err = db.SetExternalId(lbbg, userCred, iLis.GetGlobalId())
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "lbbg.SetExternalId")
|
||||
}
|
||||
err = db.SetExternalId(lblis, userCred, iLis.GetGlobalId())
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "lblis.SetExternalId")
|
||||
}
|
||||
backends, err := lbbg.GetBackends()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetBackends")
|
||||
}
|
||||
if len(backends) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
iLbbg, err := lbbg.GetICloudLoadbalancerBackendGroup(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetICloudLoadbalancerBackendGroup")
|
||||
}
|
||||
for i := range backends {
|
||||
_, err := iLbbg.AddBackendServer(backends[i].ExternalId, backends[i].Port, backends[i].Weight)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "AddBackendServer")
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHuaWeiRegionDriver) RequestDeleteLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lblis *models.SLoadbalancerListener, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
lbbg, err := lblis.GetLoadbalancerBackendGroup()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetLoadbalancerBackendGroup")
|
||||
}
|
||||
if len(lbbg.ExternalId) > 0 {
|
||||
iLbbg, err := lbbg.GetICloudLoadbalancerBackendGroup(ctx)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
return nil, db.SetExternalId(lbbg, userCred, "")
|
||||
}
|
||||
return nil, errors.Wrapf(err, "GetICloudLoadbalancerBackendGroup")
|
||||
}
|
||||
err = iLbbg.Delete(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "iLbbg.Delete")
|
||||
}
|
||||
return nil, db.SetExternalId(lbbg, userCred, "")
|
||||
}
|
||||
|
||||
if len(lblis.ExternalId) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
lb, err := lblis.GetLoadbalancer()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iLb, err := lb.GetILoadbalancer(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetILoadbalancer")
|
||||
}
|
||||
|
||||
iListener, err := iLb.GetILoadBalancerListenerById(lblis.ExternalId)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, errors.Wrapf(err, "GetILoadBalancerListenerById(%s)", lblis.ExternalId)
|
||||
}
|
||||
return nil, iListener.Delete(ctx)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHuaWeiRegionDriver) ValidateCreateLoadbalancerListenerRuleData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, input *api.LoadbalancerListenerRuleCreateInput) (*api.LoadbalancerListenerRuleCreateInput, error) {
|
||||
if input.Domain == "" && input.Path == "" {
|
||||
return input, fmt.Errorf("'domain' or 'path' should not be empty.")
|
||||
@@ -117,7 +280,7 @@ func (self *SHuaWeiRegionDriver) ValidateDeleteLoadbalancerBackendGroupCondition
|
||||
return err
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
if count >= 0 {
|
||||
return fmt.Errorf("backendgroup is binding with loadbalancer/listener/listenerrule.")
|
||||
}
|
||||
|
||||
@@ -151,13 +314,6 @@ func (self *SHuaWeiRegionDriver) RequestSyncLoadbalancerBackendGroup(ctx context
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHuaWeiRegionDriver) RequestCreateLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lblis *models.SLoadbalancerListener, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHuaWeiRegionDriver) RequestSyncLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lblis *models.SLoadbalancerListener, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
@@ -165,13 +321,6 @@ func (self *SHuaWeiRegionDriver) RequestSyncLoadbalancerListener(ctx context.Con
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHuaWeiRegionDriver) RequestDeleteLoadbalancerBackendGroup(ctx context.Context, userCred mcclient.TokenCredential, lbbg *models.SLoadbalancerBackendGroup, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHuaWeiRegionDriver) RequestDeleteLoadbalancerBackend(ctx context.Context, userCred mcclient.TokenCredential, lbb *models.SLoadbalancerBackend, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
|
||||
@@ -162,6 +162,15 @@ func (self *SManagedVirtualizationRegionDriver) RequestCreateLoadbalancerInstanc
|
||||
}
|
||||
params.Tags, _ = lb.GetAllUserMetadata()
|
||||
|
||||
if len(input.EipId) > 0 {
|
||||
eipObj, err := models.ElasticipManager.FetchById(input.EipId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "eip.FetchById(%s)", input.EipId)
|
||||
}
|
||||
eip := eipObj.(*models.SElasticip)
|
||||
params.EipId = eip.ExternalId
|
||||
}
|
||||
|
||||
if len(lb.ZoneId) > 0 {
|
||||
zone, err := lb.GetZone()
|
||||
if err != nil {
|
||||
|
||||
Vendored
+1
-1
@@ -1439,7 +1439,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221122080533-206029d5c6ae
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221122135203-3316ad5fc700
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+4
-7
@@ -19,13 +19,10 @@ type SLoadbalancerBackendGroup struct {
|
||||
GroupType string
|
||||
Backends []SLoadbalancerBackend
|
||||
|
||||
// huawei only
|
||||
LoadbalancerID string // 负载均衡ID
|
||||
ListenerID string // 监听器ID
|
||||
ListenType string // 后端服务器组监听类型
|
||||
Scheduler string
|
||||
StickySession *SLoadbalancerStickySession
|
||||
HealthCheck *SLoadbalancerHealthCheck
|
||||
// huawei
|
||||
Scheduler string
|
||||
Protocol string
|
||||
|
||||
// aws
|
||||
ListenPort int // 后端端口
|
||||
VpcId string // vpc id
|
||||
|
||||
+5
-30
@@ -421,38 +421,13 @@ func ToOnecloudHealthCode(s string) string {
|
||||
}
|
||||
|
||||
// 目前只支持target type :instance
|
||||
func (self *SRegion) CreateElbBackendgroup(group *cloudprovider.SLoadbalancerBackendGroup) (*SElbBackendGroup, error) {
|
||||
func (self *SRegion) CreateElbBackendgroup(opts *cloudprovider.SLoadbalancerBackendGroup) (*SElbBackendGroup, error) {
|
||||
params := &elbv2.CreateTargetGroupInput{}
|
||||
params.SetProtocol(strings.ToUpper(group.ListenType))
|
||||
params.SetPort(int64(group.ListenPort))
|
||||
params.SetVpcId(group.VpcId)
|
||||
params.SetName(group.Name)
|
||||
params.SetProtocol(strings.ToUpper(opts.Protocol))
|
||||
params.SetPort(int64(opts.ListenPort))
|
||||
params.SetVpcId(opts.VpcId)
|
||||
params.SetName(opts.Name)
|
||||
params.SetTargetType("instance")
|
||||
if group.HealthCheck != nil {
|
||||
params.SetHealthCheckPort("traffic-port")
|
||||
params.SetHealthCheckProtocol(strings.ToUpper(group.HealthCheck.HealthCheckType))
|
||||
params.SetHealthCheckIntervalSeconds(int64(group.HealthCheck.HealthCheckInterval))
|
||||
params.SetHealthyThresholdCount(int64(group.HealthCheck.HealthCheckRise))
|
||||
|
||||
if len(group.HealthCheck.HealthCheckURI) > 0 {
|
||||
params.SetHealthCheckPath(group.HealthCheck.HealthCheckURI)
|
||||
}
|
||||
|
||||
if utils.IsInStringArray(group.ListenType, []string{api.LB_HEALTH_CHECK_HTTP, api.LB_HEALTH_CHECK_HTTPS}) {
|
||||
params.SetHealthCheckTimeoutSeconds(int64(group.HealthCheck.HealthCheckTimeout))
|
||||
params.SetUnhealthyThresholdCount(int64(group.HealthCheck.HealthCheckFail))
|
||||
|
||||
codes := ToAwsHealthCode(group.HealthCheck.HealthCheckHttpCode)
|
||||
if len(codes) > 0 {
|
||||
matcher := &elbv2.Matcher{}
|
||||
matcher.SetHttpCode(codes)
|
||||
params.SetMatcher(matcher)
|
||||
}
|
||||
} else {
|
||||
// tcp & udp 健康检查阈值与不健康阈值需相同
|
||||
params.SetUnhealthyThresholdCount(int64(group.HealthCheck.HealthCheckRise))
|
||||
}
|
||||
}
|
||||
|
||||
client, err := self.GetElbV2Client()
|
||||
if err != nil {
|
||||
|
||||
+1
-16
@@ -227,7 +227,7 @@ func (self *SElbBackendGroup) Delete(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (self *SElbBackendGroup) Sync(ctx context.Context, group *cloudprovider.SLoadbalancerBackendGroup) error {
|
||||
return self.region.SyncELbBackendGroup(self.GetId(), group)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetELbBackends(backendgroupId string) ([]SElbBackend, error) {
|
||||
@@ -377,21 +377,6 @@ func (self *SRegion) DeleteElbBackendGroup(backendgroupId string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SRegion) SyncELbBackendGroup(backendgroupId string, group *cloudprovider.SLoadbalancerBackendGroup) error {
|
||||
err := self.modifyELbBackendGroup(backendgroupId, group.HealthCheck)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "modifyELbBackendGroup")
|
||||
}
|
||||
|
||||
err = self.RemoveElbBackends(backendgroupId)
|
||||
if err != nil {
|
||||
log.Errorf("RemoveElbBackends %s: %s", backendgroupId, err)
|
||||
return errors.Wrap(err, "RemoveElbBackends")
|
||||
}
|
||||
|
||||
return self.AddElbBackends(backendgroupId, group.Backends)
|
||||
}
|
||||
|
||||
func (self *SRegion) modifyELbBackendGroup(backendgroupId string, healthCheck *cloudprovider.SLoadbalancerHealthCheck) error {
|
||||
client, err := self.GetElbV2Client()
|
||||
if err != nil {
|
||||
|
||||
+78
-72
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -36,13 +37,6 @@ var LB_ALGORITHM_MAP = map[string]string{
|
||||
api.LB_SCHEDULER_SCH: "SOURCE_IP",
|
||||
}
|
||||
|
||||
var LB_PROTOCOL_MAP = map[string]string{
|
||||
api.LB_LISTENER_TYPE_HTTP: "HTTP",
|
||||
api.LB_LISTENER_TYPE_HTTPS: "TERMINATED_HTTPS",
|
||||
api.LB_LISTENER_TYPE_UDP: "UDP",
|
||||
api.LB_LISTENER_TYPE_TCP: "TCP",
|
||||
}
|
||||
|
||||
var LBBG_PROTOCOL_MAP = map[string]string{
|
||||
api.LB_LISTENER_TYPE_HTTP: "HTTP",
|
||||
api.LB_LISTENER_TYPE_HTTPS: "HTTP",
|
||||
@@ -237,6 +231,39 @@ func (self *SLoadbalancer) GetEgressMbps() int {
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0141008275.html
|
||||
func (self *SLoadbalancer) Delete(ctx context.Context) error {
|
||||
for _, res := range self.Pools {
|
||||
backends, err := self.region.getLoadBalancerBackends(res.Id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "get backend group %s backends", res.Id)
|
||||
}
|
||||
for _, backend := range backends {
|
||||
err := self.region.RemoveLoadBalancerBackend(res.Id, backend.Id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "RemoveLoadBalancerBackend")
|
||||
}
|
||||
}
|
||||
pool, err := self.region.GetLoadBalancerBackendGroup(res.Id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetLoadBalancerBackendGroup")
|
||||
}
|
||||
if len(pool.HealthMonitorId) > 0 {
|
||||
err = self.region.DeleteLoadbalancerHealthCheck(pool.HealthMonitorId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "delete health check")
|
||||
}
|
||||
}
|
||||
err = self.region.DeleteLoadBalancerBackendGroup(res.Id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "delete backend group %s", res.Id)
|
||||
}
|
||||
}
|
||||
for _, lis := range self.Listeners {
|
||||
err := self.region.DeleteElbListener(lis.Id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "delete listener %s", lis.Id)
|
||||
}
|
||||
}
|
||||
|
||||
return self.region.DeleteLoadBalancer(self.GetId())
|
||||
}
|
||||
|
||||
@@ -282,10 +309,13 @@ func (self *SLoadbalancer) GetILoadBalancerBackendGroups() ([]cloudprovider.IClo
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561549.html
|
||||
func (self *SLoadbalancer) CreateILoadBalancerBackendGroup(group *cloudprovider.SLoadbalancerBackendGroup) (cloudprovider.ICloudLoadbalancerBackendGroup, error) {
|
||||
ret, err := self.region.CreateLoadBalancerBackendGroup(group)
|
||||
func (self *SLoadbalancer) CreateILoadBalancerBackendGroup(opts *cloudprovider.SLoadbalancerBackendGroup) (cloudprovider.ICloudLoadbalancerBackendGroup, error) {
|
||||
ret, err := self.region.CreateLoadBalancerBackendGroup(self.Id, opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "CreateLoadBalancerBackendGroup")
|
||||
}
|
||||
ret.lb = self
|
||||
return &ret, err
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561563.html
|
||||
@@ -305,9 +335,8 @@ func (self *SLoadbalancer) CreateILoadBalancerListener(ctx context.Context, list
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret.lb = self
|
||||
return &ret, nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetILoadBalancerListenerById(listenerId string) (cloudprovider.ICloudLoadbalancerListener, error) {
|
||||
@@ -334,15 +363,24 @@ func (self *SRegion) GetLoadBalancerListeners(lbId string) ([]SElbListener, erro
|
||||
return ret, self.lbList("lbaas/listeners", params, &ret)
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateLoadBalancerListener(lbId string, listener *cloudprovider.SLoadbalancerListenerCreateOptions) (SElbListener, error) {
|
||||
func (self *SRegion) CreateLoadBalancerListener(lbId string, listener *cloudprovider.SLoadbalancerListenerCreateOptions) (*SElbListener, error) {
|
||||
params := map[string]interface{}{
|
||||
"name": listener.Name,
|
||||
"description": listener.Description,
|
||||
"protocol": LB_PROTOCOL_MAP[listener.ListenerType],
|
||||
"protocol_port": listener.ListenerPort,
|
||||
"loadbalancer_id": lbId,
|
||||
"http2_enable": listener.EnableHTTP2,
|
||||
}
|
||||
|
||||
switch listener.ListenerType {
|
||||
case api.LB_LISTENER_TYPE_TCP, api.LB_LISTENER_TYPE_UDP, api.LB_LISTENER_TYPE_HTTP:
|
||||
params["protocol"] = strings.ToUpper(listener.ListenerType)
|
||||
case api.LB_LISTENER_TYPE_HTTPS:
|
||||
params["protocol"] = "TERMINATED_HTTPS"
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotSupported, "protocol %s", listener.ListenerType)
|
||||
}
|
||||
|
||||
if len(listener.BackendGroupId) > 0 {
|
||||
params["default_pool_id"] = listener.BackendGroupId
|
||||
}
|
||||
@@ -357,10 +395,10 @@ func (self *SRegion) CreateLoadBalancerListener(lbId string, listener *cloudprov
|
||||
}
|
||||
}
|
||||
|
||||
ret := SElbListener{}
|
||||
err := self.lbCreate("lbaas/listeners", map[string]interface{}{"listener": params}, &ret)
|
||||
ret := &SElbListener{}
|
||||
err := self.lbCreate("lbaas/listeners", map[string]interface{}{"listener": params}, ret)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
return nil, err
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
@@ -377,68 +415,36 @@ func (self *SRegion) GetLoadBalancerBackendGroups(elbId string) ([]SElbBackendGr
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561547.html
|
||||
func (self *SRegion) CreateLoadBalancerBackendGroup(group *cloudprovider.SLoadbalancerBackendGroup) (SElbBackendGroup, error) {
|
||||
ret := SElbBackendGroup{region: self}
|
||||
var protocol, scheduler string
|
||||
if s, ok := LB_ALGORITHM_MAP[group.Scheduler]; !ok {
|
||||
return ret, fmt.Errorf("CreateILoadBalancerBackendGroup unsupported scheduler %s", group.Scheduler)
|
||||
} else {
|
||||
scheduler = s
|
||||
}
|
||||
|
||||
if t, ok := LBBG_PROTOCOL_MAP[group.ListenType]; !ok {
|
||||
return ret, fmt.Errorf("CreateILoadBalancerBackendGroup unsupported listener type %s", group.ListenType)
|
||||
} else {
|
||||
protocol = t
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateLoadBalancerBackendGroup(lbId string, opts *cloudprovider.SLoadbalancerBackendGroup) (*SElbBackendGroup, error) {
|
||||
params := map[string]interface{}{
|
||||
"project_id": self.client.projectId,
|
||||
"name": group.Name,
|
||||
"protocol": protocol,
|
||||
"lb_algorithm": scheduler,
|
||||
"name": opts.Name,
|
||||
"loadbalancer_id": lbId,
|
||||
}
|
||||
|
||||
if len(group.ListenerID) > 0 {
|
||||
params["listener_id"] = group.ListenerID
|
||||
} else if len(group.LoadbalancerID) > 0 {
|
||||
params["loadbalancer_id"] = group.LoadbalancerID
|
||||
} else {
|
||||
return ret, fmt.Errorf("CreateLoadBalancerBackendGroup one of listener id / loadbalancer id must be specified")
|
||||
switch opts.Scheduler {
|
||||
case api.LB_SCHEDULER_WRR:
|
||||
params["lb_algorithm"] = "ROUND_ROBIN"
|
||||
case api.LB_SCHEDULER_WLC:
|
||||
params["lb_algorithm"] = "LEAST_CONNECTIONS"
|
||||
case api.LB_SCHEDULER_SCH:
|
||||
params["lb_algorithm"] = "SOURCE_IP"
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotSupported, "invalid scheduler %s", opts.Scheduler)
|
||||
}
|
||||
switch opts.Protocol {
|
||||
case api.LB_LISTENER_TYPE_TCP, api.LB_LISTENER_TYPE_UDP:
|
||||
params["protocol"] = strings.ToUpper(opts.Protocol)
|
||||
case api.LB_LISTENER_TYPE_HTTP, api.LB_LISTENER_TYPE_HTTPS:
|
||||
params["protocol"] = "HTTP"
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotSupported, "invalid protocol %s", opts.Protocol)
|
||||
}
|
||||
|
||||
if group.StickySession != nil {
|
||||
s := map[string]interface{}{}
|
||||
timeout := int64(group.StickySession.StickySessionCookieTimeout / 60)
|
||||
if group.ListenType == api.LB_LISTENER_TYPE_UDP || group.ListenType == api.LB_LISTENER_TYPE_TCP {
|
||||
s["type"] = "SOURCE_IP"
|
||||
if timeout > 0 {
|
||||
s["persistence_timeout"] = timeout
|
||||
}
|
||||
} else {
|
||||
s["type"] = LB_STICKY_SESSION_MAP[group.StickySession.StickySessionType]
|
||||
if len(group.StickySession.StickySessionCookie) > 0 {
|
||||
s["cookie_name"] = group.StickySession.StickySessionCookie
|
||||
} else {
|
||||
if timeout > 0 {
|
||||
s["persistence_timeout"] = timeout
|
||||
}
|
||||
}
|
||||
}
|
||||
params["session_persistence"] = s
|
||||
}
|
||||
err := self.lbCreate("lbaas/pools", map[string]interface{}{"pool": params}, &ret)
|
||||
ret := &SElbBackendGroup{region: self}
|
||||
err := self.lbCreate("lbaas/pools", map[string]interface{}{"pool": params}, ret)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if group.HealthCheck != nil {
|
||||
_, err := self.CreateLoadBalancerHealthCheck(ret.GetId(), group.HealthCheck)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
|
||||
+3
-78
@@ -195,7 +195,7 @@ func (self *SElbBackendGroup) GetStatus() string {
|
||||
}
|
||||
|
||||
func (self *SElbBackendGroup) Refresh() error {
|
||||
ret, err := self.lb.region.GetLoadBalancerBackendGroupId(self.GetId())
|
||||
ret, err := self.lb.region.GetLoadBalancerBackendGroup(self.GetId())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -339,90 +339,15 @@ func (self *SElbBackendGroup) Delete(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (self *SElbBackendGroup) Sync(ctx context.Context, group *cloudprovider.SLoadbalancerBackendGroup) error {
|
||||
if group == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := self.region.UpdateLoadBalancerBackendGroup(self.GetId(), group)
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetLoadBalancerBackendGroupId(backendGroupId string) (*SElbBackendGroup, error) {
|
||||
func (self *SRegion) GetLoadBalancerBackendGroup(backendGroupId string) (*SElbBackendGroup, error) {
|
||||
ret := &SElbBackendGroup{region: self}
|
||||
res := fmt.Sprintf("lbaas/pools/" + backendGroupId)
|
||||
return ret, self.lbGet(res, ret)
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561550.html
|
||||
func (self *SRegion) UpdateLoadBalancerBackendGroup(backendGroupId string, group *cloudprovider.SLoadbalancerBackendGroup) (*SElbBackendGroup, error) {
|
||||
params := map[string]interface{}{
|
||||
"name": group.Name,
|
||||
}
|
||||
var scheduler string
|
||||
if s, ok := LB_ALGORITHM_MAP[group.Scheduler]; !ok {
|
||||
return nil, fmt.Errorf("UpdateLoadBalancerBackendGroup unsupported scheduler %s", group.Scheduler)
|
||||
} else {
|
||||
scheduler = s
|
||||
}
|
||||
params["lb_algorithm"] = scheduler
|
||||
|
||||
if group.StickySession == nil || group.StickySession.StickySession == api.LB_BOOL_OFF {
|
||||
params["session_persistence"] = jsonutils.JSONNull
|
||||
} else {
|
||||
s := map[string]interface{}{}
|
||||
timeout := int64(group.StickySession.StickySessionCookieTimeout / 60)
|
||||
if group.ListenType == api.LB_LISTENER_TYPE_UDP || group.ListenType == api.LB_LISTENER_TYPE_TCP {
|
||||
s["type"] = "SOURCE_IP"
|
||||
if timeout > 0 {
|
||||
s["persistence_timeout"] = timeout
|
||||
}
|
||||
} else {
|
||||
s["type"] = LB_STICKY_SESSION_MAP[group.StickySession.StickySessionType]
|
||||
if len(group.StickySession.StickySessionCookie) > 0 {
|
||||
s["cookie_name"] = group.StickySession.StickySessionCookie
|
||||
} else {
|
||||
if timeout > 0 {
|
||||
s["persistence_timeout"] = timeout
|
||||
}
|
||||
}
|
||||
}
|
||||
params["session_persistence"] = s
|
||||
}
|
||||
err := self.lbUpdate("lbaas/pools/"+backendGroupId, map[string]interface{}{"pool": params})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret, err := self.GetLoadBalancerBackendGroupId(backendGroupId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if group.HealthCheck == nil && len(ret.HealthMonitorId) > 0 {
|
||||
err := self.DeleteLoadbalancerHealthCheck(ret.HealthMonitorId)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "DeleteLoadbalancerHealthCheck")
|
||||
}
|
||||
}
|
||||
|
||||
if group.HealthCheck != nil {
|
||||
if len(ret.HealthMonitorId) == 0 {
|
||||
_, err := self.CreateLoadBalancerHealthCheck(ret.GetId(), group.HealthCheck)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "CreateLoadBalancerHealthCheck")
|
||||
}
|
||||
} else {
|
||||
_, err := self.UpdateLoadBalancerHealthCheck(ret.HealthMonitorId, group.HealthCheck)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "UpdateLoadBalancerHealthCheck")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret.region = self
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561551.html
|
||||
func (self *SRegion) DeleteLoadBalancerBackendGroup(id string) error {
|
||||
return self.lbDelete("lbaas/pools/" + id)
|
||||
|
||||
+5
-1
@@ -552,7 +552,11 @@ func (self *SElbListener) Sync(ctx context.Context, listener *cloudprovider.SLoa
|
||||
}
|
||||
|
||||
func (self *SElbListener) Delete(ctx context.Context) error {
|
||||
return self.lb.region.lbDelete("lbaas/listeners/" + self.GetId())
|
||||
return self.lb.region.DeleteElbListener(self.Id)
|
||||
}
|
||||
|
||||
func (self *SRegion) DeleteElbListener(id string) error {
|
||||
return self.lbDelete("lbaas/listeners/" + id)
|
||||
}
|
||||
|
||||
func (self *SRegion) UpdateLoadBalancerListener(listenerId string, listener *cloudprovider.SLoadbalancerListenerCreateOptions) error {
|
||||
|
||||
+93
-88
@@ -16,11 +16,12 @@ package hcso
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
@@ -34,13 +35,6 @@ var LB_ALGORITHM_MAP = map[string]string{
|
||||
api.LB_SCHEDULER_SCH: "SOURCE_IP",
|
||||
}
|
||||
|
||||
var LB_PROTOCOL_MAP = map[string]string{
|
||||
api.LB_LISTENER_TYPE_HTTP: "HTTP",
|
||||
api.LB_LISTENER_TYPE_HTTPS: "TERMINATED_HTTPS",
|
||||
api.LB_LISTENER_TYPE_UDP: "UDP",
|
||||
api.LB_LISTENER_TYPE_TCP: "TCP",
|
||||
}
|
||||
|
||||
var LBBG_PROTOCOL_MAP = map[string]string{
|
||||
api.LB_LISTENER_TYPE_HTTP: "HTTP",
|
||||
api.LB_LISTENER_TYPE_HTTPS: "HTTP",
|
||||
@@ -239,6 +233,38 @@ func (self *SLoadbalancer) GetEgressMbps() int {
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0141008275.html
|
||||
func (self *SLoadbalancer) Delete(ctx context.Context) error {
|
||||
for _, res := range self.Pools {
|
||||
backends, err := self.region.getLoadBalancerBackends(res.ID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "get backend group %s backends", res.ID)
|
||||
}
|
||||
for _, backend := range backends {
|
||||
err := self.region.RemoveLoadBalancerBackend(res.ID, backend.ID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "RemoveLoadBalancerBackend")
|
||||
}
|
||||
}
|
||||
pool, err := self.region.GetLoadBalancerBackendGroup(res.ID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetLoadBalancerBackendGroup")
|
||||
}
|
||||
if len(pool.HealthMonitorID) > 0 {
|
||||
err = self.region.DeleteLoadbalancerHealthCheck(pool.HealthMonitorID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "delete health check")
|
||||
}
|
||||
}
|
||||
err = self.region.DeleteLoadBalancerBackendGroup(res.ID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "delete backend group %s", res.ID)
|
||||
}
|
||||
}
|
||||
for _, lis := range self.Listeners {
|
||||
err := self.region.DeleteElbListener(lis.ID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "delete listener %s", lis.ID)
|
||||
}
|
||||
}
|
||||
return self.region.DeleteLoadBalancer(self.GetId())
|
||||
}
|
||||
|
||||
@@ -283,10 +309,13 @@ func (self *SLoadbalancer) GetILoadBalancerBackendGroups() ([]cloudprovider.IClo
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561549.html
|
||||
func (self *SLoadbalancer) CreateILoadBalancerBackendGroup(group *cloudprovider.SLoadbalancerBackendGroup) (cloudprovider.ICloudLoadbalancerBackendGroup, error) {
|
||||
ret, err := self.region.CreateLoadBalancerBackendGroup(group)
|
||||
func (self *SLoadbalancer) CreateILoadBalancerBackendGroup(opts *cloudprovider.SLoadbalancerBackendGroup) (cloudprovider.ICloudLoadbalancerBackendGroup, error) {
|
||||
ret, err := self.region.CreateLoadBalancerBackendGroup(self.ID, opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "CreateLoadBalancerBackendGroup")
|
||||
}
|
||||
ret.lb = self
|
||||
return &ret, err
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561563.html
|
||||
@@ -313,9 +342,8 @@ func (self *SLoadbalancer) CreateILoadBalancerListener(ctx context.Context, list
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret.lb = self
|
||||
return &ret, nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetILoadBalancerListenerById(listenerId string) (cloudprovider.ICloudLoadbalancerListener, error) {
|
||||
@@ -358,35 +386,43 @@ func (self *SRegion) GetLoadBalancerListeners(lbId string) ([]SElbListener, erro
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateLoadBalancerListener(lbId string, listener *cloudprovider.SLoadbalancerListenerCreateOptions) (SElbListener, error) {
|
||||
func (self *SRegion) CreateLoadBalancerListener(lbId string, opts *cloudprovider.SLoadbalancerListenerCreateOptions) (*SElbListener, error) {
|
||||
params := jsonutils.NewDict()
|
||||
listenerObj := jsonutils.NewDict()
|
||||
listenerObj.Set("name", jsonutils.NewString(listener.Name))
|
||||
listenerObj.Set("description", jsonutils.NewString(listener.Description))
|
||||
listenerObj.Set("protocol", jsonutils.NewString(LB_PROTOCOL_MAP[listener.ListenerType]))
|
||||
listenerObj.Set("protocol_port", jsonutils.NewInt(int64(listener.ListenerPort)))
|
||||
listenerObj.Set("name", jsonutils.NewString(opts.Name))
|
||||
listenerObj.Set("description", jsonutils.NewString(opts.Description))
|
||||
switch opts.ListenerType {
|
||||
case api.LB_LISTENER_TYPE_TCP, api.LB_LISTENER_TYPE_UDP, api.LB_LISTENER_TYPE_HTTP:
|
||||
opts.ListenerType = strings.ToUpper(opts.ListenerType)
|
||||
case api.LB_LISTENER_TYPE_HTTPS:
|
||||
opts.ListenerType = "TERMINATED_HTTPS"
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotSupported, "protocol %s", opts.ListenerType)
|
||||
}
|
||||
|
||||
listenerObj.Set("protocol", jsonutils.NewString(opts.ListenerType))
|
||||
listenerObj.Set("protocol_port", jsonutils.NewInt(int64(opts.ListenerPort)))
|
||||
listenerObj.Set("loadbalancer_id", jsonutils.NewString(lbId))
|
||||
listenerObj.Set("http2_enable", jsonutils.NewBool(listener.EnableHTTP2))
|
||||
if len(listener.BackendGroupId) > 0 {
|
||||
listenerObj.Set("default_pool_id", jsonutils.NewString(listener.BackendGroupId))
|
||||
listenerObj.Set("http2_enable", jsonutils.NewBool(opts.EnableHTTP2))
|
||||
if len(opts.BackendGroupId) > 0 {
|
||||
listenerObj.Set("default_pool_id", jsonutils.NewString(opts.BackendGroupId))
|
||||
}
|
||||
|
||||
if listener.ListenerType == api.LB_LISTENER_TYPE_HTTPS {
|
||||
listenerObj.Set("default_tls_container_ref", jsonutils.NewString(listener.CertificateId))
|
||||
if opts.ListenerType == api.LB_LISTENER_TYPE_HTTPS {
|
||||
listenerObj.Set("default_tls_container_ref", jsonutils.NewString(opts.CertificateId))
|
||||
}
|
||||
|
||||
if listener.XForwardedFor {
|
||||
if opts.XForwardedFor {
|
||||
insertObj := jsonutils.NewDict()
|
||||
insertObj.Set("X-Forwarded-ELB-IP", jsonutils.NewBool(listener.XForwardedFor))
|
||||
insertObj.Set("X-Forwarded-ELB-IP", jsonutils.NewBool(opts.XForwardedFor))
|
||||
listenerObj.Set("insert_headers", insertObj)
|
||||
}
|
||||
params.Set("listener", listenerObj)
|
||||
ret := SElbListener{}
|
||||
err := DoCreate(self.ecsClient.ElbListeners.Create, params, &ret)
|
||||
ret := &SElbListener{}
|
||||
err := DoCreate(self.ecsClient.ElbListeners.Create, params, ret)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
@@ -411,71 +447,40 @@ func (self *SRegion) GetLoadBalancerBackendGroups(elbId string) ([]SElbBackendGr
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561547.html
|
||||
func (self *SRegion) CreateLoadBalancerBackendGroup(group *cloudprovider.SLoadbalancerBackendGroup) (SElbBackendGroup, error) {
|
||||
ret := SElbBackendGroup{}
|
||||
var protocol, scheduler string
|
||||
if s, ok := LB_ALGORITHM_MAP[group.Scheduler]; !ok {
|
||||
return ret, fmt.Errorf("CreateILoadBalancerBackendGroup unsupported scheduler %s", group.Scheduler)
|
||||
} else {
|
||||
scheduler = s
|
||||
}
|
||||
|
||||
if t, ok := LBBG_PROTOCOL_MAP[group.ListenType]; !ok {
|
||||
return ret, fmt.Errorf("CreateILoadBalancerBackendGroup unsupported listener type %s", group.ListenType)
|
||||
} else {
|
||||
protocol = t
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateLoadBalancerBackendGroup(lbId string, opts *cloudprovider.SLoadbalancerBackendGroup) (*SElbBackendGroup, error) {
|
||||
params := jsonutils.NewDict()
|
||||
poolObj := jsonutils.NewDict()
|
||||
switch opts.Scheduler {
|
||||
case api.LB_SCHEDULER_WRR:
|
||||
opts.Scheduler = "ROUND_ROBIN"
|
||||
case api.LB_SCHEDULER_WLC:
|
||||
opts.Scheduler = "LEAST_CONNECTIONS"
|
||||
case api.LB_SCHEDULER_SCH:
|
||||
opts.Scheduler = "SOURCE_IP"
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotSupported, "invalid scheduler %s", opts.Scheduler)
|
||||
}
|
||||
switch opts.Protocol {
|
||||
case api.LB_LISTENER_TYPE_TCP, api.LB_LISTENER_TYPE_UDP:
|
||||
opts.Protocol = strings.ToUpper(opts.Protocol)
|
||||
case api.LB_LISTENER_TYPE_HTTP, api.LB_LISTENER_TYPE_HTTPS:
|
||||
opts.Protocol = "HTTP"
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotSupported, "invalid protocol %s", opts.Protocol)
|
||||
}
|
||||
|
||||
poolObj.Set("project_id", jsonutils.NewString(self.client.projectId))
|
||||
poolObj.Set("name", jsonutils.NewString(group.Name))
|
||||
poolObj.Set("protocol", jsonutils.NewString(protocol))
|
||||
poolObj.Set("lb_algorithm", jsonutils.NewString(scheduler))
|
||||
|
||||
if len(group.ListenerID) > 0 {
|
||||
poolObj.Set("listener_id", jsonutils.NewString(group.ListenerID))
|
||||
} else if len(group.LoadbalancerID) > 0 {
|
||||
poolObj.Set("loadbalancer_id", jsonutils.NewString(group.LoadbalancerID))
|
||||
} else {
|
||||
return ret, fmt.Errorf("CreateLoadBalancerBackendGroup one of listener id / loadbalancer id must be specified")
|
||||
}
|
||||
|
||||
if group.StickySession != nil {
|
||||
s := jsonutils.NewDict()
|
||||
timeout := int64(group.StickySession.StickySessionCookieTimeout / 60)
|
||||
if group.ListenType == api.LB_LISTENER_TYPE_UDP || group.ListenType == api.LB_LISTENER_TYPE_TCP {
|
||||
s.Set("type", jsonutils.NewString("SOURCE_IP"))
|
||||
if timeout > 0 {
|
||||
s.Set("persistence_timeout", jsonutils.NewInt(timeout))
|
||||
}
|
||||
} else {
|
||||
s.Set("type", jsonutils.NewString(LB_STICKY_SESSION_MAP[group.StickySession.StickySessionType]))
|
||||
if len(group.StickySession.StickySessionCookie) > 0 {
|
||||
s.Set("cookie_name", jsonutils.NewString(group.StickySession.StickySessionCookie))
|
||||
} else {
|
||||
if timeout > 0 {
|
||||
s.Set("persistence_timeout", jsonutils.NewInt(timeout))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
poolObj.Set("session_persistence", s)
|
||||
}
|
||||
poolObj.Set("name", jsonutils.NewString(opts.Name))
|
||||
poolObj.Set("protocol", jsonutils.NewString(opts.Protocol))
|
||||
poolObj.Set("lb_algorithm", jsonutils.NewString(opts.Scheduler))
|
||||
poolObj.Set("loadbalancer_id", jsonutils.NewString(lbId))
|
||||
params.Set("pool", poolObj)
|
||||
err := DoCreate(self.ecsClient.ElbBackendGroup.Create, params, &ret)
|
||||
|
||||
ret := &SElbBackendGroup{region: self}
|
||||
err := DoCreate(self.ecsClient.ElbBackendGroup.Create, params, ret)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if group.HealthCheck != nil {
|
||||
_, err := self.CreateLoadBalancerHealthCheck(ret.GetId(), group.HealthCheck)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
}
|
||||
|
||||
ret.region = self
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
|
||||
+3
-77
@@ -194,7 +194,7 @@ func (self *SElbBackendGroup) GetStatus() string {
|
||||
}
|
||||
|
||||
func (self *SElbBackendGroup) Refresh() error {
|
||||
ret, err := self.lb.region.GetLoadBalancerBackendGroupId(self.GetId())
|
||||
ret, err := self.lb.region.GetLoadBalancerBackendGroup(self.GetId())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -346,15 +346,10 @@ func (self *SElbBackendGroup) Delete(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (self *SElbBackendGroup) Sync(ctx context.Context, group *cloudprovider.SLoadbalancerBackendGroup) error {
|
||||
if group == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := self.region.UpdateLoadBalancerBackendGroup(self.GetId(), group)
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetLoadBalancerBackendGroupId(backendGroupId string) (SElbBackendGroup, error) {
|
||||
func (self *SRegion) GetLoadBalancerBackendGroup(backendGroupId string) (SElbBackendGroup, error) {
|
||||
ret := SElbBackendGroup{}
|
||||
err := DoGet(self.ecsClient.ElbBackendGroup.Get, backendGroupId, nil, &ret)
|
||||
if err != nil {
|
||||
@@ -365,75 +360,6 @@ func (self *SRegion) GetLoadBalancerBackendGroupId(backendGroupId string) (SElbB
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561550.html
|
||||
func (self *SRegion) UpdateLoadBalancerBackendGroup(backendGroupID string, group *cloudprovider.SLoadbalancerBackendGroup) (SElbBackendGroup, error) {
|
||||
params := jsonutils.NewDict()
|
||||
poolObj := jsonutils.NewDict()
|
||||
poolObj.Set("name", jsonutils.NewString(group.Name))
|
||||
var scheduler string
|
||||
if s, ok := LB_ALGORITHM_MAP[group.Scheduler]; !ok {
|
||||
return SElbBackendGroup{}, fmt.Errorf("UpdateLoadBalancerBackendGroup unsupported scheduler %s", group.Scheduler)
|
||||
} else {
|
||||
scheduler = s
|
||||
}
|
||||
poolObj.Set("lb_algorithm", jsonutils.NewString(scheduler))
|
||||
|
||||
if group.StickySession == nil || group.StickySession.StickySession == api.LB_BOOL_OFF {
|
||||
poolObj.Set("session_persistence", jsonutils.JSONNull)
|
||||
} else {
|
||||
s := jsonutils.NewDict()
|
||||
timeout := int64(group.StickySession.StickySessionCookieTimeout / 60)
|
||||
if group.ListenType == api.LB_LISTENER_TYPE_UDP || group.ListenType == api.LB_LISTENER_TYPE_TCP {
|
||||
s.Set("type", jsonutils.NewString("SOURCE_IP"))
|
||||
if timeout > 0 {
|
||||
s.Set("persistence_timeout", jsonutils.NewInt(timeout))
|
||||
}
|
||||
} else {
|
||||
s.Set("type", jsonutils.NewString(LB_STICKY_SESSION_MAP[group.StickySession.StickySessionType]))
|
||||
if len(group.StickySession.StickySessionCookie) > 0 {
|
||||
s.Set("cookie_name", jsonutils.NewString(group.StickySession.StickySessionCookie))
|
||||
} else {
|
||||
if timeout > 0 {
|
||||
s.Set("persistence_timeout", jsonutils.NewInt(timeout))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
poolObj.Set("session_persistence", s)
|
||||
}
|
||||
params.Set("pool", poolObj)
|
||||
|
||||
ret := SElbBackendGroup{}
|
||||
err := DoUpdate(self.ecsClient.ElbBackendGroup.Update, backendGroupID, params, &ret)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "ElbBackendGroup.Update")
|
||||
}
|
||||
|
||||
if group.HealthCheck == nil && len(ret.HealthMonitorID) > 0 {
|
||||
err := self.DeleteLoadbalancerHealthCheck(ret.HealthMonitorID)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "DeleteLoadbalancerHealthCheck")
|
||||
}
|
||||
}
|
||||
|
||||
if group.HealthCheck != nil {
|
||||
if len(ret.HealthMonitorID) == 0 {
|
||||
_, err := self.CreateLoadBalancerHealthCheck(ret.GetId(), group.HealthCheck)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "CreateLoadBalancerHealthCheck")
|
||||
}
|
||||
} else {
|
||||
_, err := self.UpdateLoadBalancerHealthCheck(ret.HealthMonitorID, group.HealthCheck)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "UpdateLoadBalancerHealthCheck")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret.region = self
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561551.html
|
||||
func (self *SRegion) DeleteLoadBalancerBackendGroup(backendGroupID string) error {
|
||||
return DoDelete(self.ecsClient.ElbBackendGroup.Delete, backendGroupID, nil, nil)
|
||||
|
||||
+4
-5
@@ -557,12 +557,11 @@ func (self *SElbListener) Sync(ctx context.Context, listener *cloudprovider.SLoa
|
||||
}
|
||||
|
||||
func (self *SElbListener) Delete(ctx context.Context) error {
|
||||
err := DoDelete(self.lb.region.ecsClient.ElbListeners.Delete, self.GetId(), nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return self.lb.region.DeleteElbListener(self.ID)
|
||||
}
|
||||
|
||||
return nil
|
||||
func (self *SRegion) DeleteElbListener(id string) error {
|
||||
return DoDelete(self.ecsClient.ElbListeners.Delete, id, nil, nil)
|
||||
}
|
||||
|
||||
func (self *SRegion) UpdateLoadBalancerListener(listenerId string, listener *cloudprovider.SLoadbalancerListenerCreateOptions) error {
|
||||
|
||||
+97
-96
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -35,13 +36,6 @@ var LB_ALGORITHM_MAP = map[string]string{
|
||||
api.LB_SCHEDULER_SCH: "SOURCE_IP",
|
||||
}
|
||||
|
||||
var LB_PROTOCOL_MAP = map[string]string{
|
||||
api.LB_LISTENER_TYPE_HTTP: "HTTP",
|
||||
api.LB_LISTENER_TYPE_HTTPS: "TERMINATED_HTTPS",
|
||||
api.LB_LISTENER_TYPE_UDP: "UDP",
|
||||
api.LB_LISTENER_TYPE_TCP: "TCP",
|
||||
}
|
||||
|
||||
var LBBG_PROTOCOL_MAP = map[string]string{
|
||||
api.LB_LISTENER_TYPE_HTTP: "HTTP",
|
||||
api.LB_LISTENER_TYPE_HTTPS: "HTTP",
|
||||
@@ -69,28 +63,28 @@ type SLoadbalancer struct {
|
||||
|
||||
Description string `json:"description"`
|
||||
ProvisioningStatus string `json:"provisioning_status"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
ProjectID string `json:"project_id"`
|
||||
TenantId string `json:"tenant_id"`
|
||||
ProjectId string `json:"project_id"`
|
||||
AdminStateUp bool `json:"admin_state_up"`
|
||||
Provider string `json:"provider"`
|
||||
Pools []Pool `json:"pools"`
|
||||
Listeners []Listener `json:"listeners"`
|
||||
VipPortID string `json:"vip_port_id"`
|
||||
VipPortId string `json:"vip_port_id"`
|
||||
OperatingStatus string `json:"operating_status"`
|
||||
VipAddress string `json:"vip_address"`
|
||||
VipSubnetID string `json:"vip_subnet_id"`
|
||||
ID string `json:"id"`
|
||||
VipSubnetId string `json:"vip_subnet_id"`
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
ID string `json:"id"`
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type Pool struct {
|
||||
ID string `json:"id"`
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
@@ -102,7 +96,7 @@ func (self *SLoadbalancer) GetIEIP() (cloudprovider.ICloudEIP, error) {
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetId() string {
|
||||
return self.ID
|
||||
return self.Id
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetName() string {
|
||||
@@ -110,7 +104,7 @@ func (self *SLoadbalancer) GetName() string {
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetGlobalId() string {
|
||||
return self.ID
|
||||
return self.Id
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetStatus() string {
|
||||
@@ -131,7 +125,7 @@ func (self *SLoadbalancer) IsEmulated() bool {
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetProjectId() string {
|
||||
return self.ProjectID
|
||||
return self.ProjectId
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetAddress() string {
|
||||
@@ -158,7 +152,7 @@ func (self *SLoadbalancer) GetNetworkIds() []string {
|
||||
|
||||
func (self *SLoadbalancer) GetNetwork() *SNetwork {
|
||||
if self.subnet == nil {
|
||||
port, err := self.region.GetPort(self.VipPortID)
|
||||
port, err := self.region.GetPort(self.VipPortId)
|
||||
if err == nil {
|
||||
net, err := self.region.getNetwork(port.NetworkID)
|
||||
if err == nil {
|
||||
@@ -176,7 +170,7 @@ func (self *SLoadbalancer) GetNetwork() *SNetwork {
|
||||
|
||||
func (self *SLoadbalancer) GetEip() *SEipAddress {
|
||||
if self.eip == nil {
|
||||
eips, _ := self.region.GetEips(self.VipPortID, nil)
|
||||
eips, _ := self.region.GetEips(self.VipPortId, nil)
|
||||
for i := range eips {
|
||||
self.eip = &eips[i]
|
||||
}
|
||||
@@ -236,6 +230,38 @@ func (self *SLoadbalancer) GetEgressMbps() int {
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0141008275.html
|
||||
func (self *SLoadbalancer) Delete(ctx context.Context) error {
|
||||
for _, res := range self.Pools {
|
||||
backends, err := self.region.getLoadBalancerBackends(res.Id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "get backend group %s backends", res.Id)
|
||||
}
|
||||
for _, backend := range backends {
|
||||
err := self.region.RemoveLoadBalancerBackend(res.Id, backend.ID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "RemoveLoadBalancerBackend")
|
||||
}
|
||||
}
|
||||
pool, err := self.region.GetLoadBalancerBackendGroup(res.Id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetLoadBalancerBackendGroup")
|
||||
}
|
||||
if len(pool.HealthMonitorID) > 0 {
|
||||
err = self.region.DeleteLoadbalancerHealthCheck(pool.HealthMonitorID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "delete health check")
|
||||
}
|
||||
}
|
||||
err = self.region.DeleteLoadBalancerBackendGroup(res.Id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "delete backend group %s", res.Id)
|
||||
}
|
||||
}
|
||||
for _, lis := range self.Listeners {
|
||||
err := self.region.DeleteElbListener(lis.Id)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "delete listener %s", lis.Id)
|
||||
}
|
||||
}
|
||||
return self.region.DeleteLoadBalancer(self.GetId())
|
||||
}
|
||||
|
||||
@@ -281,10 +307,13 @@ func (self *SLoadbalancer) GetILoadBalancerBackendGroups() ([]cloudprovider.IClo
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561549.html
|
||||
func (self *SLoadbalancer) CreateILoadBalancerBackendGroup(group *cloudprovider.SLoadbalancerBackendGroup) (cloudprovider.ICloudLoadbalancerBackendGroup, error) {
|
||||
ret, err := self.region.CreateLoadBalancerBackendGroup(group)
|
||||
func (self *SLoadbalancer) CreateILoadBalancerBackendGroup(opts *cloudprovider.SLoadbalancerBackendGroup) (cloudprovider.ICloudLoadbalancerBackendGroup, error) {
|
||||
ret, err := self.region.CreateLoadBalancerBackendGroup(self.Id, opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "CreateLoadBalancerBackendGroup")
|
||||
}
|
||||
ret.lb = self
|
||||
return &ret, err
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561563.html
|
||||
@@ -304,13 +333,12 @@ func (self *SLoadbalancer) GetILoadBalancerBackendGroupById(groupId string) (clo
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) CreateILoadBalancerListener(ctx context.Context, listener *cloudprovider.SLoadbalancerListenerCreateOptions) (cloudprovider.ICloudLoadbalancerListener, error) {
|
||||
ret, err := self.region.CreateLoadBalancerListener(listener, self.ID)
|
||||
ret, err := self.region.CreateLoadBalancerListener(listener, self.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret.lb = self
|
||||
return &ret, nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetILoadBalancerListenerById(listenerId string) (cloudprovider.ICloudLoadbalancerListener, error) {
|
||||
@@ -346,15 +374,22 @@ func (self *SRegion) GetLoadBalancerListeners(lbId string) ([]SElbListener, erro
|
||||
return ret, self.lbListAll("elb/listeners", params, "listeners", &ret)
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateLoadBalancerListener(listener *cloudprovider.SLoadbalancerListenerCreateOptions, lbId string) (SElbListener, error) {
|
||||
func (self *SRegion) CreateLoadBalancerListener(listener *cloudprovider.SLoadbalancerListenerCreateOptions, lbId string) (*SElbListener, error) {
|
||||
params := map[string]interface{}{
|
||||
"name": listener.Name,
|
||||
"description": listener.Description,
|
||||
"protocol": LB_PROTOCOL_MAP[listener.ListenerType],
|
||||
"protocol_port": listener.ListenerPort,
|
||||
"loadbalancer_id": lbId,
|
||||
"http2_enable": listener.EnableHTTP2,
|
||||
}
|
||||
switch listener.ListenerType {
|
||||
case api.LB_LISTENER_TYPE_TCP, api.LB_LISTENER_TYPE_UDP, api.LB_LISTENER_TYPE_HTTP:
|
||||
params["protocol"] = strings.ToUpper(listener.ListenerType)
|
||||
case api.LB_LISTENER_TYPE_HTTPS:
|
||||
params["protocol"] = "TERMINATED_HTTPS"
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotSupported, "protocol %s", listener.ListenerType)
|
||||
}
|
||||
if len(listener.BackendGroupId) > 0 {
|
||||
params["default_pool_id"] = listener.BackendGroupId
|
||||
}
|
||||
@@ -369,10 +404,10 @@ func (self *SRegion) CreateLoadBalancerListener(listener *cloudprovider.SLoadbal
|
||||
}
|
||||
}
|
||||
|
||||
ret := SElbListener{}
|
||||
resp, err := self.lbCreate("lb/listeners", map[string]interface{}{"listener": params})
|
||||
ret := &SElbListener{}
|
||||
resp, err := self.lbCreate("elb/listeners", map[string]interface{}{"listener": params})
|
||||
if err != nil {
|
||||
return ret, err
|
||||
return nil, err
|
||||
}
|
||||
return ret, resp.Unmarshal(&ret, "listener")
|
||||
}
|
||||
@@ -388,81 +423,47 @@ func (self *SRegion) GetLoadBalancerBackendGroups(elbId string) ([]SElbBackendGr
|
||||
return ret, self.lbListAll("elb/pools", query, "pools", &ret)
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561547.html
|
||||
func (self *SRegion) CreateLoadBalancerBackendGroup(group *cloudprovider.SLoadbalancerBackendGroup) (SElbBackendGroup, error) {
|
||||
ret := SElbBackendGroup{region: self}
|
||||
var protocol, scheduler string
|
||||
if s, ok := LB_ALGORITHM_MAP[group.Scheduler]; !ok {
|
||||
return ret, fmt.Errorf("CreateILoadBalancerBackendGroup unsupported scheduler %s", group.Scheduler)
|
||||
} else {
|
||||
scheduler = s
|
||||
}
|
||||
|
||||
if t, ok := LBBG_PROTOCOL_MAP[group.ListenType]; !ok {
|
||||
return ret, fmt.Errorf("CreateILoadBalancerBackendGroup unsupported listener type %s", group.ListenType)
|
||||
} else {
|
||||
protocol = t
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateLoadBalancerBackendGroup(lbId string, opts *cloudprovider.SLoadbalancerBackendGroup) (*SElbBackendGroup, error) {
|
||||
params := map[string]interface{}{
|
||||
"project_id": self.client.projectId,
|
||||
"name": group.Name,
|
||||
"protocol": protocol,
|
||||
"lb_algorithm": scheduler,
|
||||
"name": opts.Name,
|
||||
"loadbalancer_id": lbId,
|
||||
}
|
||||
switch opts.Scheduler {
|
||||
case api.LB_SCHEDULER_WRR:
|
||||
params["lb_algorithm"] = "ROUND_ROBIN"
|
||||
case api.LB_SCHEDULER_WLC:
|
||||
params["lb_algorithm"] = "LEAST_CONNECTIONS"
|
||||
case api.LB_SCHEDULER_SCH:
|
||||
params["lb_algorithm"] = "SOURCE_IP"
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotSupported, "invalid scheduler %s", opts.Scheduler)
|
||||
}
|
||||
switch opts.Protocol {
|
||||
case api.LB_LISTENER_TYPE_TCP, api.LB_LISTENER_TYPE_UDP:
|
||||
params["protocol"] = strings.ToUpper(opts.Protocol)
|
||||
case api.LB_LISTENER_TYPE_HTTP, api.LB_LISTENER_TYPE_HTTPS:
|
||||
params["protocol"] = "HTTP"
|
||||
default:
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotSupported, "invalid protocol %s", opts.Protocol)
|
||||
}
|
||||
|
||||
if len(group.ListenerID) > 0 {
|
||||
params["listener_id"] = group.ListenerID
|
||||
} else if len(group.LoadbalancerID) > 0 {
|
||||
params["loadbalancer_id"] = group.LoadbalancerID
|
||||
} else {
|
||||
return ret, fmt.Errorf("CreateLoadBalancerBackendGroup one of listener id / loadbalancer id must be specified")
|
||||
}
|
||||
|
||||
if group.StickySession != nil {
|
||||
s := map[string]interface{}{}
|
||||
timeout := int64(group.StickySession.StickySessionCookieTimeout / 60)
|
||||
if group.ListenType == api.LB_LISTENER_TYPE_UDP || group.ListenType == api.LB_LISTENER_TYPE_TCP {
|
||||
s["type"] = "SOURCE_IP"
|
||||
if timeout > 0 {
|
||||
s["persistence_timeout"] = timeout
|
||||
}
|
||||
} else {
|
||||
s["type"] = LB_STICKY_SESSION_MAP[group.StickySession.StickySessionType]
|
||||
if len(group.StickySession.StickySessionCookie) > 0 {
|
||||
s["cookie_name"] = group.StickySession.StickySessionCookie
|
||||
} else {
|
||||
if timeout > 0 {
|
||||
s["persistence_timeout"] = timeout
|
||||
}
|
||||
}
|
||||
}
|
||||
params["session_persistence"] = s
|
||||
}
|
||||
resp, err := self.lbCreate("elb/pools", map[string]interface{}{"pool": params})
|
||||
if err != nil {
|
||||
return ret, err
|
||||
return nil, err
|
||||
}
|
||||
err = resp.Unmarshal(&ret, "pool")
|
||||
ret := &SElbBackendGroup{region: self}
|
||||
err = resp.Unmarshal(ret, "pool")
|
||||
if err != nil {
|
||||
return ret, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if group.HealthCheck != nil {
|
||||
_, err := self.CreateLoadBalancerHealthCheck(ret.GetId(), group.HealthCheck)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateLoadBalancerHealthCheck(backendGroupID string, healthCheck *cloudprovider.SLoadbalancerHealthCheck) (SElbHealthCheck, error) {
|
||||
func (self *SRegion) CreateLoadBalancerHealthCheck(backendGroupId string, healthCheck *cloudprovider.SLoadbalancerHealthCheck) (SElbHealthCheck, error) {
|
||||
params := map[string]interface{}{
|
||||
"delay": healthCheck.HealthCheckInterval,
|
||||
"max_retries": healthCheck.HealthCheckRise,
|
||||
"pool_id": backendGroupID,
|
||||
"pool_id": backendGroupId,
|
||||
"timeout": healthCheck.HealthCheckTimeout,
|
||||
"type": LB_HEALTHCHECK_TYPE_MAP[healthCheck.HealthCheckType],
|
||||
}
|
||||
@@ -490,7 +491,7 @@ func (self *SRegion) CreateLoadBalancerHealthCheck(backendGroupID string, health
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561564.html
|
||||
func (self *SRegion) UpdateLoadBalancerHealthCheck(healthCheckID string, healthCheck *cloudprovider.SLoadbalancerHealthCheck) (SElbHealthCheck, error) {
|
||||
func (self *SRegion) UpdateLoadBalancerHealthCheck(healthCheckId string, healthCheck *cloudprovider.SLoadbalancerHealthCheck) (SElbHealthCheck, error) {
|
||||
params := map[string]interface{}{
|
||||
"delay": healthCheck.HealthCheckInterval,
|
||||
"max_retries": healthCheck.HealthCheckRise,
|
||||
@@ -511,7 +512,7 @@ func (self *SRegion) UpdateLoadBalancerHealthCheck(healthCheckID string, healthC
|
||||
}
|
||||
|
||||
ret := SElbHealthCheck{region: self}
|
||||
resp, err := self.lbUpdate("elb/healthmonitors/"+healthCheckID, map[string]interface{}{"healthmonitor": params})
|
||||
resp, err := self.lbUpdate("elb/healthmonitors/"+healthCheckId, map[string]interface{}{"healthmonitor": params})
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
@@ -519,8 +520,8 @@ func (self *SRegion) UpdateLoadBalancerHealthCheck(healthCheckID string, healthC
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561565.html
|
||||
func (self *SRegion) DeleteLoadbalancerHealthCheck(healthCheckID string) error {
|
||||
_, err := self.lbDelete("elb/healthmonitors/" + healthCheckID)
|
||||
func (self *SRegion) DeleteLoadbalancerHealthCheck(healthCheckId string) error {
|
||||
_, err := self.lbDelete("elb/healthmonitors/" + healthCheckId)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -616,7 +617,7 @@ func (self *SRegion) CreateLoadBalancer(loadbalancer *cloudprovider.SLoadbalance
|
||||
|
||||
// 创建公网类型ELB
|
||||
if len(loadbalancer.EipId) > 0 {
|
||||
err := self.AssociateEipWithPortId(loadbalancer.EipId, ret.VipPortID)
|
||||
err := self.AssociateEipWithPortId(loadbalancer.EipId, ret.VipPortId)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "SRegion.CreateLoadBalancer.AssociateEipWithPortId")
|
||||
}
|
||||
|
||||
+15
-91
@@ -35,18 +35,18 @@ type SElbBackendGroup struct {
|
||||
lb *SLoadbalancer
|
||||
region *SRegion
|
||||
|
||||
LBAlgorithm string `json:"lb_algorithm"`
|
||||
Protocol string `json:"protocol"`
|
||||
Description string `json:"description"`
|
||||
AdminStateUp bool `json:"admin_state_up"`
|
||||
Loadbalancers []Listener `json:"loadbalancers"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
ProjectID string `json:"project_id"`
|
||||
Listeners []Listener `json:"listeners"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
HealthMonitorID string `json:"healthmonitor_id"`
|
||||
SessionPersistence StickySession `json:"session_persistence"`
|
||||
LBAlgorithm string `json:"lb_algorithm"`
|
||||
Protocol string `json:"protocol"`
|
||||
Description string `json:"description"`
|
||||
AdminStateUp bool `json:"admin_state_up"`
|
||||
Loadbalancers []Loadbalancer `json:"loadbalancers"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
ProjectID string `json:"project_id"`
|
||||
Listeners []Listener `json:"listeners"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
HealthMonitorID string `json:"healthmonitor_id"`
|
||||
SessionPersistence StickySession `json:"session_persistence"`
|
||||
}
|
||||
|
||||
func (self *SElbBackendGroup) GetLoadbalancerId() string {
|
||||
@@ -194,7 +194,7 @@ func (self *SElbBackendGroup) GetStatus() string {
|
||||
}
|
||||
|
||||
func (self *SElbBackendGroup) Refresh() error {
|
||||
ret, err := self.lb.region.GetLoadBalancerBackendGroupId(self.GetId())
|
||||
ret, err := self.lb.region.GetLoadBalancerBackendGroup(self.GetId())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -338,15 +338,10 @@ func (self *SElbBackendGroup) Delete(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (self *SElbBackendGroup) Sync(ctx context.Context, group *cloudprovider.SLoadbalancerBackendGroup) error {
|
||||
if group == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := self.region.UpdateLoadBalancerBackendGroup(self.GetId(), group)
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetLoadBalancerBackendGroupId(backendGroupId string) (*SElbBackendGroup, error) {
|
||||
func (self *SRegion) GetLoadBalancerBackendGroup(backendGroupId string) (*SElbBackendGroup, error) {
|
||||
ret := &SElbBackendGroup{region: self}
|
||||
res := fmt.Sprintf("elb/pools/" + backendGroupId)
|
||||
resp, err := self.lbGet(res)
|
||||
@@ -356,77 +351,6 @@ func (self *SRegion) GetLoadBalancerBackendGroupId(backendGroupId string) (*SElb
|
||||
return ret, resp.Unmarshal(ret, "pool")
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561550.html
|
||||
func (self *SRegion) UpdateLoadBalancerBackendGroup(backendGroupID string, group *cloudprovider.SLoadbalancerBackendGroup) (*SElbBackendGroup, error) {
|
||||
params := map[string]interface{}{
|
||||
"name": group.Name,
|
||||
}
|
||||
var scheduler string
|
||||
if s, ok := LB_ALGORITHM_MAP[group.Scheduler]; !ok {
|
||||
return nil, fmt.Errorf("UpdateLoadBalancerBackendGroup unsupported scheduler %s", group.Scheduler)
|
||||
} else {
|
||||
scheduler = s
|
||||
}
|
||||
params["lb_algorithm"] = scheduler
|
||||
|
||||
if group.StickySession == nil || group.StickySession.StickySession == api.LB_BOOL_OFF {
|
||||
params["session_persistence"] = jsonutils.JSONNull
|
||||
} else {
|
||||
s := map[string]interface{}{}
|
||||
timeout := int64(group.StickySession.StickySessionCookieTimeout / 60)
|
||||
if group.ListenType == api.LB_LISTENER_TYPE_UDP || group.ListenType == api.LB_LISTENER_TYPE_TCP {
|
||||
s["type"] = "SOURCE_IP"
|
||||
if timeout > 0 {
|
||||
s["persistence_timeout"] = timeout
|
||||
}
|
||||
} else {
|
||||
s["type"] = LB_STICKY_SESSION_MAP[group.StickySession.StickySessionType]
|
||||
if len(group.StickySession.StickySessionCookie) > 0 {
|
||||
s["cookie_name"] = group.StickySession.StickySessionCookie
|
||||
} else {
|
||||
if timeout > 0 {
|
||||
s["persistence_timeout"] = timeout
|
||||
}
|
||||
}
|
||||
}
|
||||
params["session_persistence"] = s
|
||||
}
|
||||
resp, err := self.lbUpdate("elb/pools/"+backendGroupID, map[string]interface{}{"pool": params})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := &SElbBackendGroup{}
|
||||
err = resp.Unmarshal(ret, "pool")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "resp.Unmarshal")
|
||||
}
|
||||
|
||||
if group.HealthCheck == nil && len(ret.HealthMonitorID) > 0 {
|
||||
err := self.DeleteLoadbalancerHealthCheck(ret.HealthMonitorID)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "DeleteLoadbalancerHealthCheck")
|
||||
}
|
||||
}
|
||||
|
||||
if group.HealthCheck != nil {
|
||||
if len(ret.HealthMonitorID) == 0 {
|
||||
_, err := self.CreateLoadBalancerHealthCheck(ret.GetId(), group.HealthCheck)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "CreateLoadBalancerHealthCheck")
|
||||
}
|
||||
} else {
|
||||
_, err := self.UpdateLoadBalancerHealthCheck(ret.HealthMonitorID, group.HealthCheck)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "UpdateLoadBalancerHealthCheck")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret.region = self
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561551.html
|
||||
func (self *SRegion) DeleteLoadBalancerBackendGroup(id string) error {
|
||||
_, err := self.lbDelete("elb/pools/" + id)
|
||||
|
||||
+5
-1
@@ -555,7 +555,11 @@ func (self *SElbListener) Sync(ctx context.Context, listener *cloudprovider.SLoa
|
||||
}
|
||||
|
||||
func (self *SElbListener) Delete(ctx context.Context) error {
|
||||
_, err := self.lb.region.lbDelete("elb/listeners/" + self.GetId())
|
||||
return self.lb.region.DeleteElbListener(self.ID)
|
||||
}
|
||||
|
||||
func (self *SRegion) DeleteElbListener(id string) error {
|
||||
_, err := self.lbDelete("elb/listeners/" + id)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
+6
-131
@@ -320,27 +320,18 @@ func (region *SRegion) GetLoadbalancerPoolById(poolId string) (*SLoadbalancerPoo
|
||||
return &pool, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateLoadbalancerPool(group *cloudprovider.SLoadbalancerBackendGroup) (*SLoadbalancerPool, error) {
|
||||
func (region *SRegion) CreateLoadbalancerPool(lbId string, opts *cloudprovider.SLoadbalancerBackendGroup) (*SLoadbalancerPool, error) {
|
||||
type CreateParams struct {
|
||||
Pool SLoadbalancerPoolCreateParams `json:"pool"`
|
||||
}
|
||||
params := CreateParams{}
|
||||
params.Pool.AdminStateUp = true
|
||||
params.Pool.LbAlgorithm = LB_ALGORITHM_MAP[group.Scheduler]
|
||||
params.Pool.Name = group.Name
|
||||
params.Pool.LoadbalancerID = group.LoadbalancerID
|
||||
params.Pool.LbAlgorithm = opts.Scheduler
|
||||
params.Pool.Name = opts.Name
|
||||
params.Pool.LoadbalancerID = lbId
|
||||
// 绑定规则时不能指定listener
|
||||
params.Pool.ListenerID = group.ListenerID
|
||||
params.Pool.Protocol = LB_PROTOCOL_MAP[group.ListenType]
|
||||
params.Pool.Protocol = opts.Protocol
|
||||
params.Pool.SessionPersistence = nil
|
||||
if group.StickySession != nil {
|
||||
session := SSessionPersistence{}
|
||||
session.Type = LB_STICKY_SESSION_MAP[group.StickySession.StickySessionType]
|
||||
if session.Type == "APP_COOKIE" {
|
||||
session.CookieName = group.StickySession.StickySessionCookie
|
||||
}
|
||||
params.Pool.SessionPersistence = &session
|
||||
}
|
||||
body, err := region.lbPost("/v2/lbaas/pools", jsonutils.Marshal(params))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "region.lbPost(/v2/lbaas/pools)")
|
||||
@@ -403,123 +394,7 @@ func (pool *SLoadbalancerPool) GetILoadbalancerBackendById(memberId string) (clo
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "GetILoadbalancerBackendById(%s)", memberId)
|
||||
}
|
||||
|
||||
func (region *SRegion) UpdateLoadBalancerPool(poolId string, group *cloudprovider.SLoadbalancerBackendGroup) error {
|
||||
type UpdateParams struct {
|
||||
Pool SLoadbalancerPoolUpdateParams `json:"pool"`
|
||||
}
|
||||
params := UpdateParams{}
|
||||
params.Pool.AdminStateUp = true
|
||||
params.Pool.LbAlgorithm = LB_ALGORITHM_MAP[group.Scheduler]
|
||||
params.Pool.Name = group.Name
|
||||
if group.StickySession != nil {
|
||||
session := SSessionPersistence{}
|
||||
session.Type = LB_STICKY_SESSION_MAP[group.StickySession.StickySessionType]
|
||||
if session.Type == "APP_COOKIE" {
|
||||
session.CookieName = group.StickySession.StickySessionCookie
|
||||
}
|
||||
params.Pool.SessionPersistence = &session
|
||||
}
|
||||
_, err := region.lbUpdate(fmt.Sprintf("/v2/lbaas/pools/%s", poolId), jsonutils.Marshal(params))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, `region.lbUpdate("/v2/lbaas/pools/%s", jsonutils.Marshal(params))`, poolId)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pool *SLoadbalancerPool) Sync(ctx context.Context, group *cloudprovider.SLoadbalancerBackendGroup) error {
|
||||
lb, err := pool.region.GetLoadbalancerbyId(pool.GetLoadbalancerId())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "pool.region.GetLoadbalancerbyId(pool.GetLoadbalancerId())")
|
||||
}
|
||||
// ensure loadbalancer status
|
||||
err = waitLbResStatus(lb, 10*time.Second, 8*time.Minute)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, `waitLbResStatus(lb, 10*time.Second, 8*time.Minute)`)
|
||||
}
|
||||
// ensure pool status
|
||||
err = waitLbResStatus(pool, 10*time.Second, 8*time.Minute)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, `waitLbResStatus(pool, 10*time.Second, 8*time.Minute)`)
|
||||
}
|
||||
// sync healthmonitor
|
||||
healthmonitor := SLoadbalancerHealthmonitor{}
|
||||
if len(pool.HealthmonitorID) > 0 {
|
||||
oldhealthmonitor, err := pool.region.GetLoadbalancerHealthmonitorById(pool.HealthmonitorID)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "pool.region.GetLoadbalancerHealthmonitorById(pool.HealthmonitorID)")
|
||||
}
|
||||
// 不能更新健康检查类型,需要删除重建
|
||||
var sHealthCheckType string
|
||||
switch oldhealthmonitor.Type {
|
||||
case "HTTP":
|
||||
sHealthCheckType = api.LB_HEALTH_CHECK_HTTP
|
||||
case "HTTPS":
|
||||
sHealthCheckType = api.LB_HEALTH_CHECK_HTTPS
|
||||
case "TCP":
|
||||
sHealthCheckType = api.LB_HEALTH_CHECK_TCP
|
||||
case "UDP-CONNECT":
|
||||
sHealthCheckType = api.LB_HEALTH_CHECK_UDP
|
||||
default:
|
||||
sHealthCheckType = ""
|
||||
}
|
||||
|
||||
if sHealthCheckType != group.HealthCheck.HealthCheckType {
|
||||
err := pool.region.DeleteLoadbalancerHealthmonitor(pool.HealthmonitorID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "pool.region.DeleteLoadbalancerHealthmonitor(%s)", pool.HealthmonitorID)
|
||||
}
|
||||
// 等待删除结束
|
||||
err = waitLbResStatus(lb, 10*time.Second, 8*time.Minute)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, `waitLbResStatus(lb, 10*time.Second, 8*time.Minute)`)
|
||||
}
|
||||
|
||||
newhealthmonitor, err := pool.region.CreateLoadbalancerHealthmonitor(pool.ID, group.HealthCheck)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "pool.region.CreateLoadbalancerHealthmonitor(%s,group.HealthCheck)", pool.ID)
|
||||
}
|
||||
healthmonitor = *newhealthmonitor
|
||||
} else {
|
||||
// ensure healthmonitor status
|
||||
err = waitLbResStatus(oldhealthmonitor, 10*time.Second, 8*time.Minute)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, `waitLbResStatus(oldhealthmonitor, 10*time.Second, 8*time.Minute)`)
|
||||
}
|
||||
oldhealthmonitor, err = pool.region.UpdateLoadbalancerHealthmonitor(pool.HealthmonitorID, group.HealthCheck)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, `pool.region.UpdateLoadbalancerHealthmonitor(%s, group.HealthCheck)`, pool.HealthmonitorID)
|
||||
}
|
||||
healthmonitor = *oldhealthmonitor
|
||||
}
|
||||
} else {
|
||||
newhealthmonitor, err := pool.region.CreateLoadbalancerHealthmonitor(pool.ID, group.HealthCheck)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "pool.region.CreateLoadbalancerHealthmonitor(%s, group.HealthCheck)", pool.ID)
|
||||
}
|
||||
healthmonitor = *newhealthmonitor
|
||||
}
|
||||
|
||||
// ensure pool status
|
||||
err = waitLbResStatus(pool, 10*time.Second, 8*time.Minute)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, `waitLbResStatus(pool, 10*time.Second, 8*time.Minute)`)
|
||||
}
|
||||
// sync pool
|
||||
err = pool.region.UpdateLoadBalancerPool(pool.ID, group)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, `pool.region.UpdateLoadBalancerPool(%s, group)`, pool.ID)
|
||||
}
|
||||
|
||||
// wait healthmonitor status
|
||||
err = waitLbResStatus(&healthmonitor, 10*time.Second, 8*time.Minute)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, `waitLbResStatus(&healthmonitor, 10*time.Second, 8*time.Minute)`)
|
||||
}
|
||||
// wait pool status
|
||||
err = waitLbResStatus(pool, 10*time.Second, 8*time.Minute)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, `waitLbResStatus(pool, 10*time.Second, 8*time.Minute)`)
|
||||
}
|
||||
func (pool *SLoadbalancerPool) Sync(ctx context.Context, opts *cloudprovider.SLoadbalancerBackendGroup) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+1
-17
@@ -338,7 +338,7 @@ func (lb *SLoadbalancer) CreateILoadBalancerBackendGroup(group *cloudprovider.SL
|
||||
return nil, errors.Wrap(err, "waitLbResStatus(lb, api.LB_STATUS_ENABLED, 10*time.Second, 8*time.Minute)")
|
||||
}
|
||||
// create pool
|
||||
spool, err := lb.region.CreateLoadbalancerPool(group)
|
||||
spool, err := lb.region.CreateLoadbalancerPool(lb.ID, group)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "lb.region.CreateLoadbalancerPool")
|
||||
}
|
||||
@@ -347,22 +347,6 @@ func (lb *SLoadbalancer) CreateILoadBalancerBackendGroup(group *cloudprovider.SL
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "waitLbResStatus(spool, 10*time.Second, 8*time.Minute)")
|
||||
}
|
||||
// create healthmonitor
|
||||
if group.HealthCheck != nil {
|
||||
|
||||
healthmonitor, err := lb.region.CreateLoadbalancerHealthmonitor(spool.ID, group.HealthCheck)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "region.CreateLoadbalancerHealthmonitor(%s, group.HealthCheck)", spool.ID)
|
||||
}
|
||||
spool.healthmonitor = healthmonitor
|
||||
}
|
||||
// wait health monitor
|
||||
if spool.healthmonitor != nil {
|
||||
err = waitLbResStatus(spool.healthmonitor, 10*time.Second, 8*time.Minute)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "waitLbResStatus(spool.healthmonitor, 10*time.Second, 8*time.Minute)")
|
||||
}
|
||||
}
|
||||
return spool, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user