first commit
This commit is contained in:
118
pkg/common/CmdTools/AliyunCloudClient.go
Normal file
118
pkg/common/CmdTools/AliyunCloudClient.go
Normal file
@ -0,0 +1,118 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/slb"
|
||||
)
|
||||
|
||||
// LTAI5tCB8SmJcwfO
|
||||
// dX4kgF4VcblsbCVdKvtCGCmvNbLkZK
|
||||
// ./AliyunCloudClient -t b -o update -key LTAI5tCB8SmJcwfO -sec dX4kgF4VcblsbCVdKvtCGCmvNbLkZK -reg cn-hangzhou -lb "[{"ServerId":"ServerId","Weight":"0"}]
|
||||
func main() {
|
||||
var target string
|
||||
flag.StringVar(&target, "t", "b", "target: b=backendServer")
|
||||
var operation string
|
||||
flag.StringVar(&operation, "o", "update", "operation: add、update、remove")
|
||||
var accessKeyId string
|
||||
flag.StringVar(&accessKeyId, "key", "accessKeyId", "accessKeyId")
|
||||
var accessSecret string
|
||||
flag.StringVar(&accessSecret, "sec", "accessSecret", "accessSecret")
|
||||
var regionId string
|
||||
flag.StringVar(®ionId, "reg", "regionId", "regionId: cn-hangzhou")
|
||||
var loadBalancerId string
|
||||
flag.StringVar(&loadBalancerId, "lb", "loadBalancerId", "loadBalancerId")
|
||||
var params string
|
||||
flag.StringVar(¶ms, "params", "", `SetBackendServers: [{"ServerId":"ServerId","Weight":"0"}]
|
||||
AddBackendServers: [{"ServerId":"ServerId","Weight":"100","Type":"eni","ServerIp":"192.168.11.1"}]
|
||||
RemoveBackendServers: [{"ServerId":"ServerId","Weight":"100"}]
|
||||
`)
|
||||
flag.Parse()
|
||||
flag.Usage()
|
||||
fmt.Printf("target=%s,operation=%s,accessKeyId=%s,accessSecret=%s,regionId=%s,loadBalancerId=%s,params=%s", target, operation, accessKeyId, accessSecret, regionId, loadBalancerId, params)
|
||||
if target == "b" {
|
||||
switch operation {
|
||||
case "update":
|
||||
SetBackendServers(regionId, accessKeyId, accessSecret, loadBalancerId, params)
|
||||
break
|
||||
case "add":
|
||||
AddBackendServers(regionId, accessKeyId, accessSecret, loadBalancerId, params)
|
||||
break
|
||||
case "remove":
|
||||
RemoveBackendServers(regionId, accessKeyId, accessSecret, loadBalancerId, params)
|
||||
break
|
||||
default:
|
||||
fmt.Println("operation: " + operation + " not support")
|
||||
}
|
||||
} else {
|
||||
fmt.Println("target: " + target + " not support")
|
||||
}
|
||||
}
|
||||
|
||||
func SetBackendServers(regionId, accessKeyId, accessSecret, loadBalancerId, params string) {
|
||||
// client, err := slb.NewClientWithAccessKey(regionId, accessKeyId, accessSecret)
|
||||
// if nil != err {
|
||||
// fmt.Println("get client error:")
|
||||
// fmt.Println(err.Error())
|
||||
// }
|
||||
|
||||
// request := slb.CreateSetBackendServersRequest()
|
||||
// request.Scheme = "https"
|
||||
|
||||
// request.LoadBalancerId = loadBalancerId
|
||||
// request.BackendServers = params
|
||||
|
||||
// if nil == client {
|
||||
// fmt.Println("error: client is nil")
|
||||
// return
|
||||
// }
|
||||
// response, err := client.SetBackendServers(request)
|
||||
// if err != nil {
|
||||
// fmt.Print(err.Error())
|
||||
// }
|
||||
// fmt.Printf("response is %#v\n", response)
|
||||
}
|
||||
|
||||
func AddBackendServers(regionId, accessKeyId, accessSecret, loadBalancerId, params string) {
|
||||
client, err := slb.NewClientWithAccessKey(regionId, accessKeyId, accessSecret)
|
||||
|
||||
request := slb.CreateAddBackendServersRequest()
|
||||
request.Scheme = "https"
|
||||
|
||||
request.LoadBalancerId = loadBalancerId
|
||||
request.BackendServers = params
|
||||
|
||||
if nil == client {
|
||||
fmt.Println("error: client is nil")
|
||||
return
|
||||
}
|
||||
|
||||
response, err := client.AddBackendServers(request)
|
||||
if err != nil {
|
||||
fmt.Print(err.Error())
|
||||
}
|
||||
fmt.Printf("response is %#v\n", response)
|
||||
}
|
||||
|
||||
func RemoveBackendServers(regionId, accessKeyId, accessSecret, loadBalancerId, params string) {
|
||||
|
||||
client, err := slb.NewClientWithAccessKey(regionId, accessKeyId, accessSecret)
|
||||
|
||||
request := slb.CreateRemoveBackendServersRequest()
|
||||
request.Scheme = "https"
|
||||
|
||||
request.LoadBalancerId = loadBalancerId
|
||||
request.BackendServers = params
|
||||
|
||||
if nil == client {
|
||||
fmt.Println("error: client is nil")
|
||||
return
|
||||
}
|
||||
|
||||
response, err := client.RemoveBackendServers(request)
|
||||
if err != nil {
|
||||
fmt.Print(err.Error())
|
||||
}
|
||||
fmt.Printf("response is %#v\n", response)
|
||||
}
|
||||
Reference in New Issue
Block a user