Skip to content

Commit

Permalink
feat: add lb update
Browse files Browse the repository at this point in the history
  • Loading branch information
tangx committed Nov 23, 2020
1 parent f2f6708 commit 5f94948
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cmd/lb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cmd

import (
"os"

"github.com/spf13/cobra"
"github.com/tangx/qingclix/global"
"github.com/tangx/qingclix/modules"
)

// certCmd represents the cert command
var lbCmd = &cobra.Command{
Use: "lb",
Short: "负载均衡",
Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("cert called")
_ = cmd.Help()
},
}

func init() {
rootCmd.AddCommand(lbCmd)
}

var lbCmdUpdate = &cobra.Command{
Use: "update",
Short: "更新负载均衡配置",
Run: func(cmd *cobra.Command, args []string) {
if global.Loadbalancers == "" {
_ = cmd.Help()
os.Exit(1)
}
modules.UpdateLoadBalancers(global.Loadbalancers)
},
}

func init() {
lbCmd.AddCommand(lbCmdUpdate)
lbCmdUpdate.Flags().StringVarP(&global.Loadbalancers, "lb", "", "", "Loadbalances , split with comma (ex lb-123,lb-223)")
}
4 changes: 4 additions & 0 deletions global/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ var (
var (
WithUpdateLB bool
)

var (
Loadbalancers string
)
27 changes: 27 additions & 0 deletions modules/lb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package modules

import (
"strings"

"github.com/sirupsen/logrus"
"github.com/tangx/qingclix/global"
"github.com/tangx/qingyun-sdk-go/qingyun"
)

func UpdateLoadBalancers(lbIDs string) bool {
lbs := strings.Split(lbIDs, ",")
params := qingyun.UpdateLoadBalancersRequest{
Loadbalancers: lbs,
}
resp, err := global.QingClix.UpdateLoadBalancers(params)
if err != nil {
logrus.Fatalf("retcode: %d, msg: %s", resp.RetCode, err.Error())
}

if resp.RetCode == 0 {
logrus.Infof("update lb request is accepted, job_id is %s", resp.JobID)
return true
}

return false
}

0 comments on commit 5f94948

Please sign in to comment.