Merge pull request #377 in YUNIONIO/onecloud from ~ZHOUYOUSONG/onecloud:bugfix/yousong-lb to release/2.3.0

* commit '264e9dea6d61c33a82f640d585c19f7fb8b49a1e':
  loadbalancers: show backend group name on detailed list
  lbagent: add symlink to generated telegraf.conf
  lbagent: remove requirement on nmap-ncap
This commit is contained in:
邱剑
2018-10-31 11:26:50 +08:00
5 changed files with 68 additions and 4 deletions
-1
View File
@@ -1,7 +1,6 @@
DESCRIPTION="Yunion Loadbalancer Agent"
REQUIRES=(
nmap-ncat
"keepalived >= 2.0.0"
"haproxy >= 1.8.0"
"gobetween >= 0.7.0"
@@ -5,6 +5,7 @@ import (
"fmt"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/sqlchemy"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
@@ -133,6 +134,27 @@ func (lbr *SLoadbalancerListenerRule) ValidateUpdateData(ctx context.Context, us
return lbr.SVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, data)
}
func (lbr *SLoadbalancerListenerRule) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
extra := lbr.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query)
if lbr.BackendGroupId == "" {
log.Errorf("loadbalancer listener rule %s(%s): empty backend group field", lbr.Name, lbr.Id)
return extra
}
lbbg, err := LoadbalancerBackendGroupManager.FetchById(lbr.BackendGroupId)
if err != nil {
log.Errorf("loadbalancer listener rule %s(%s): fetch backend group (%s) error: %s",
lbr.Name, lbr.Id, lbr.BackendGroupId, err)
return extra
}
extra.Set("backend_group", jsonutils.NewString(lbbg.GetName()))
return extra
}
func (lbr *SLoadbalancerListenerRule) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
extra := lbr.GetCustomizeColumns(ctx, userCred, query)
return extra
}
func (lbr *SLoadbalancerListenerRule) PreDelete(ctx context.Context, userCred mcclient.TokenCredential) {
lbr.SetStatus(userCred, LB_STATUS_DISABLED, "preDelete")
lbr.DoPendingDelete(ctx, userCred)
@@ -6,6 +6,7 @@ import (
"regexp"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/sqlchemy"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
@@ -339,6 +340,26 @@ func (lblis *SLoadbalancerListener) ValidateUpdateData(ctx context.Context, user
return lblis.SVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, data)
}
func (lblis *SLoadbalancerListener) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
extra := lblis.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query)
if lblis.BackendGroupId == "" {
return extra
}
lbbg, err := LoadbalancerBackendGroupManager.FetchById(lblis.BackendGroupId)
if err != nil {
log.Errorf("loadbalancer listener %s(%s): fetch backend group (%s) error: %s",
lblis.Name, lblis.Id, lblis.BackendGroupId, err)
return extra
}
extra.Set("backend_group", jsonutils.NewString(lbbg.GetName()))
return extra
}
func (lblis *SLoadbalancerListener) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
extra := lblis.GetCustomizeColumns(ctx, userCred, query)
return extra
}
func (lblis *SLoadbalancerListener) PreDelete(ctx context.Context, userCred mcclient.TokenCredential) {
lblis.SetStatus(userCred, LB_STATUS_DISABLED, "preDelete")
lblis.DoPendingDelete(ctx, userCred)
+20
View File
@@ -176,6 +176,26 @@ func (lb *SLoadbalancer) ValidateUpdateData(ctx context.Context, userCred mcclie
return lb.SVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, data)
}
func (lb *SLoadbalancer) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
extra := lb.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query)
if lb.BackendGroupId == "" {
return extra
}
lbbg, err := LoadbalancerBackendGroupManager.FetchById(lb.BackendGroupId)
if err != nil {
log.Errorf("loadbalancer %s(%s): fetch backend group (%s) error: %s",
lb.Name, lb.Id, lb.BackendGroupId, err)
return extra
}
extra.Set("backend_group", jsonutils.NewString(lbbg.GetName()))
return extra
}
func (lb *SLoadbalancer) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
extra := lb.GetCustomizeColumns(ctx, userCred, query)
return extra
}
func (lb *SLoadbalancer) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
if len(lb.Address) > 0 {
// TODO reserve support
+5 -3
View File
@@ -190,13 +190,15 @@ func (h *HaproxyHelper) useConfigs(ctx context.Context, d string) error {
err = os.Symlink(old, new)
return err
}
keepalivedConf := filepath.Join(h.opts.haproxyConfigDir, "keepalived.conf")
gobetweenJson := filepath.Join(h.opts.haproxyConfigDir, "gobetween.json")
haproxyConfD := h.haproxyConfD()
gobetweenJson := filepath.Join(h.opts.haproxyConfigDir, "gobetween.json")
keepalivedConf := filepath.Join(h.opts.haproxyConfigDir, "keepalived.conf")
telegrafConf := filepath.Join(h.opts.haproxyConfigDir, "telegraf.conf")
dirMap := map[string]string{
keepalivedConf: filepath.Join(d, "keepalived.conf"),
haproxyConfD: d,
gobetweenJson: filepath.Join(d, "gobetween.json"),
keepalivedConf: filepath.Join(d, "keepalived.conf"),
telegrafConf: filepath.Join(d, "telegraf.conf"),
}
for new, old := range dirMap {
err := lnF(old, new)