mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #931 in YUNIONIO/onecloud from ~ZHOUYOUSONG/onecloud:bugfix/yousong-lb to release/2.4.0
* commit '4adae9bd8867c9f0249cb91f9212574656650aa9':
lbagent: fix typo in log
lbagent: use encoding/json for {,de}serialization
lbagent: 改正cloudcommon.CommonOptions使用
lbagent: 改正isempty()使用
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ func main() {
|
||||
consts.SetServiceType("lbagent")
|
||||
|
||||
opts := &lbagent.Options{}
|
||||
commonOpts := &opts.CommonOpts
|
||||
commonOpts := &opts.CommonOptions
|
||||
{
|
||||
cloudcommon.ParseOptions(opts, commonOpts, os.Args, "lbagent.conf")
|
||||
cloudcommon.InitAuth(commonOpts, func() {
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ func (h *ApiHelper) Run(ctx context.Context) {
|
||||
}
|
||||
|
||||
func (h *ApiHelper) adminClientSession(ctx context.Context) *mcclient.ClientSession {
|
||||
region := h.opts.CommonOpts.Region
|
||||
region := h.opts.CommonOptions.Region
|
||||
apiVersion := "v2"
|
||||
s := auth.GetAdminSession(ctx, region, apiVersion)
|
||||
return s
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
@@ -11,7 +12,12 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
const (
|
||||
CORPUS_VERSION = "v1"
|
||||
)
|
||||
|
||||
type LoadbalancerCorpus struct {
|
||||
CorpusVersion string
|
||||
*ModelSets
|
||||
ModelSetsMaxUpdatedAt *ModelSetsMaxUpdatedAt
|
||||
}
|
||||
@@ -50,10 +56,12 @@ func (b *LoadbalancerCorpus) MaxSeenUpdatedAtParams() *jsonutils.JSONDict {
|
||||
}
|
||||
|
||||
func (b *LoadbalancerCorpus) SaveDir(dir string) error {
|
||||
j := jsonutils.Marshal(b)
|
||||
d := j.String()
|
||||
d, err := json.Marshal(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p := filepath.Join(dir, "corpus")
|
||||
err := ioutil.WriteFile(p, []byte(d), agentutils.FileModeFileSensitive)
|
||||
err = ioutil.WriteFile(p, d, agentutils.FileModeFileSensitive)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -63,13 +71,14 @@ func (b *LoadbalancerCorpus) LoadDir(dir string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jd, err := jsonutils.Parse(d)
|
||||
err = json.Unmarshal(d, b)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: json parse failed: %s", p, err)
|
||||
return err
|
||||
}
|
||||
err = jd.Unmarshal(b)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: json unmarshal failed: %s", p, err)
|
||||
// version for updating
|
||||
if ver := b.CorpusVersion; ver != CORPUS_VERSION {
|
||||
b.Reset()
|
||||
return fmt.Errorf("%s: corpus version %s != %s", p, ver, CORPUS_VERSION)
|
||||
}
|
||||
correct := b.join()
|
||||
if !correct {
|
||||
@@ -77,3 +86,8 @@ func (b *LoadbalancerCorpus) LoadDir(dir string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *LoadbalancerCorpus) Reset() {
|
||||
bb := NewEmptyLoadbalancerCorpus()
|
||||
*b = *bb
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ func (ms LoadbalancerListeners) JoinCertificates(subEntries LoadbalancerCertific
|
||||
if m.CertificateId != "" {
|
||||
subEntry, ok := subEntries[m.CertificateId]
|
||||
if !ok {
|
||||
log.Warningf("loadbalancer m id %s: cannot find certificate id %s",
|
||||
log.Warningf("loadbalancerlistener id %s: cannot find certificate id %s",
|
||||
m.Id, m.CertificateId)
|
||||
correct = false
|
||||
continue
|
||||
|
||||
@@ -90,7 +90,7 @@ func GetModels(opts *GetModelsOptions) error {
|
||||
Details: options.Bool(true),
|
||||
Filter: []string{
|
||||
minUpdatedAtFilter(minUpdatedAt), // order matters, filter.0
|
||||
"isempty(manager_id)", // len(manager_id) > 0 is for pubcloud objects
|
||||
"manager_id.isnull()", // len(manager_id) > 0 is for pubcloud objects
|
||||
},
|
||||
OrderBy: []string{"updated_at", "id"},
|
||||
Order: "asc",
|
||||
|
||||
@@ -31,7 +31,7 @@ type LbagentOptions struct {
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
CommonOpts cloudcommon.CommonOptions
|
||||
cloudcommon.CommonOptions
|
||||
|
||||
LbagentOptions
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user