-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,7 @@ var ( | |
var ( | ||
WithUpdateLB bool | ||
) | ||
|
||
var ( | ||
Loadbalancers string | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |