implement LoadBalancer task for ALICloud

This commit is contained in:
LilyFaFa 2018-05-25 10:39:41 +08:00 committed by LilyFaFa
parent 263a01c899
commit a8f91dc3ff
23 changed files with 2543 additions and 0 deletions

1
Gopkg.lock generated
View File

@ -228,6 +228,7 @@
"common",
"ecs",
"oss",
"slb",
"util"
]
revision = "2581e433b270014481c9ec66a91368661533febb"

View File

@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"api_loadbalancer.go",
"context.go",
"convenience.go",
"network.go",
@ -10,8 +11,11 @@ go_library(
importpath = "k8s.io/kops/pkg/model/alimodel",
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/kops:go_default_library",
"//pkg/dns:go_default_library",
"//pkg/model:go_default_library",
"//upup/pkg/fi:go_default_library",
"//upup/pkg/fi/cloudup/alitasks:go_default_library",
"//upup/pkg/fi/fitasks:go_default_library",
],
)

View File

@ -0,0 +1,139 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package alimodel
import (
"errors"
"fmt"
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/dns"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/alitasks"
"k8s.io/kops/upup/pkg/fi/fitasks"
)
const LoadBalancerListenerStatus = "running"
const LoadBalancerListenerBandwidth = -1
// APILoadBalancerModelBuilder builds a LoadBalancer for accessing the API
type APILoadBalancerModelBuilder struct {
*ALIModelContext
Lifecycle *fi.Lifecycle
}
var _ fi.ModelBuilder = &APILoadBalancerModelBuilder{}
func (b *APILoadBalancerModelBuilder) Build(c *fi.ModelBuilderContext) error {
// Configuration where an ELB fronts the API
if !b.UseLoadBalancerForAPI() {
return nil
}
lbSpec := b.Cluster.Spec.API.LoadBalancer
if lbSpec == nil {
// Skipping API ELB creation; not requested in Spec
return nil
}
switch lbSpec.Type {
case kops.LoadBalancerTypeInternal:
// OK
case kops.LoadBalancerTypePublic:
// OK
default:
return fmt.Errorf("unhandled LoadBalancer type %q", lbSpec.Type)
}
// Create LoadBalancer for API ELB
var loadbalancer *alitasks.LoadBalancer
{
loadbalancer = &alitasks.LoadBalancer{
Name: s(b.GetNameForLoadBalancer()),
Lifecycle: b.Lifecycle,
}
switch lbSpec.Type {
case kops.LoadBalancerTypeInternal:
return errors.New("internal LoadBalancers are not yet supported by kops on ALI")
//loadbalancer.AddressType = s("intranet")
case kops.LoadBalancerTypePublic:
loadbalancer.AddressType = s("internet")
default:
return fmt.Errorf("unknown loadbalancer Type: %q", lbSpec.Type)
}
c.AddTask(loadbalancer)
}
// Create LoadBalancerListener for API ELB
// TODO: Health check
var loadbalancerlistener *alitasks.LoadBalancerListener
{
loadBalancerListenerStatus := LoadBalancerListenerStatus
loadBalancerListenerBandwidth := LoadBalancerListenerBandwidth
loadbalancerlistener = &alitasks.LoadBalancerListener{
Name: s("api." + b.ClusterName()),
Lifecycle: b.Lifecycle,
LoadBalancer: loadbalancer,
ListenerStatus: s(loadBalancerListenerStatus),
ListenerPort: i(443),
BackendServerPort: i(443),
Bandwidth: i(loadBalancerListenerBandwidth),
}
c.AddTask(loadbalancerlistener)
}
// Create LoadBalancerWhiteList for API ELB
var loadbalancerwhiteList *alitasks.LoadBalancerWhiteList
{
sourceItems := ""
for _, cidr := range b.Cluster.Spec.KubernetesAPIAccess {
if cidr != "0.0.0.0" && cidr != "0.0.0.0/0" {
sourceItems = sourceItems + cidr + ","
}
}
loadbalancerwhiteList = &alitasks.LoadBalancerWhiteList{
Name: s("api." + b.ClusterName()),
Lifecycle: b.Lifecycle,
LoadBalancer: loadbalancer,
LoadBalancerListener: loadbalancerlistener,
SourceItems: s(sourceItems),
}
c.AddTask(loadbalancerwhiteList)
}
// Temporarily do not know the role of the following function
if dns.IsGossipHostname(b.Cluster.Name) || b.UsePrivateDNS() {
// Ensure the ELB hostname is included in the TLS certificate,
// if we're not going to use an alias for it
// TODO: I don't love this technique for finding the task by name & modifying it
masterKeypairTask, found := c.Tasks["Keypair/master"]
if !found {
return errors.New("keypair/master task not found")
}
masterKeypair := masterKeypairTask.(*fitasks.Keypair)
masterKeypair.AlternateNameTasks = append(masterKeypair.AlternateNameTasks, loadbalancer)
}
return nil
}

View File

@ -37,3 +37,7 @@ func (c *ALIModelContext) GetNameForVPC() string {
func (c *ALIModelContext) GetNameForVSwitch(subnetName string) string {
return subnetName + "." + c.ClusterName()
}
func (c *ALIModelContext) GetNameForLoadBalancer() string {
return "api." + c.ClusterName()
}

View File

@ -5,6 +5,12 @@ go_library(
srcs = [
"disk.go",
"disk_fitask.go",
"loadbalancer.go",
"loadbalancer_fitask.go",
"loadbalancerlistener.go",
"loadbalancerlistener_fitask.go",
"loadbalancerwhitelist.go",
"loadbalancerwhitelist_fitask.go",
"sshkey.go",
"sshkey_fitask.go",
"vpc.go",
@ -20,6 +26,7 @@ go_library(
"//upup/pkg/fi/cloudup/terraform:go_default_library",
"//vendor/github.com/denverdino/aliyungo/common:go_default_library",
"//vendor/github.com/denverdino/aliyungo/ecs:go_default_library",
"//vendor/github.com/denverdino/aliyungo/slb:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
],
)

View File

@ -0,0 +1,257 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package alitasks
import (
"encoding/json"
"fmt"
"github.com/denverdino/aliyungo/common"
"github.com/denverdino/aliyungo/slb"
"github.com/golang/glog"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
)
// LoadBalancer represents a ALI Cloud LoadBalancer
//go:generate fitask -type=LoadBalancer
type LoadBalancer struct {
Name *string
LoadbalancerId *string
AddressType *string
LoadBalancerAddress *string
Lifecycle *fi.Lifecycle
Tags map[string]string
}
var _ fi.CompareWithID = &LoadBalancer{}
var _ fi.HasAddress = &LoadBalancer{}
func (l *LoadBalancer) CompareWithID() *string {
return l.LoadbalancerId
}
func (l *LoadBalancer) Find(c *fi.Context) (*LoadBalancer, error) {
cloud := c.Cloud.(aliup.ALICloud)
// TODO:Get loadbalancer with LoadBalancerName, hope to support finding with tags
describeLoadBalancersArgs := &slb.DescribeLoadBalancersArgs{
RegionId: common.Region(cloud.Region()),
LoadBalancerName: fi.StringValue(l.Name),
AddressType: slb.AddressType(fi.StringValue(l.AddressType)),
}
responseLoadBalancers, err := cloud.SlbClient().DescribeLoadBalancers(describeLoadBalancersArgs)
if err != nil {
return nil, fmt.Errorf("error finding LoadBalancers: %v", err)
}
// Don't exist loadbalancer with specified ClusterTags or Name.
if len(responseLoadBalancers) == 0 {
return nil, nil
}
if len(responseLoadBalancers) > 1 {
glog.V(4).Info("The number of specified loadbalancer whith the same name exceeds 1, loadbalancerName:%q", *l.Name)
}
glog.V(2).Infof("found matching LoadBalancer: %q", *l.Name)
actual := &LoadBalancer{}
actual.Name = fi.String(responseLoadBalancers[0].LoadBalancerName)
actual.AddressType = fi.String(string(responseLoadBalancers[0].AddressType))
actual.LoadbalancerId = fi.String(responseLoadBalancers[0].LoadBalancerId)
actual.LoadBalancerAddress = fi.String(responseLoadBalancers[0].Address)
describeTagsArgs := &slb.DescribeTagsArgs{
RegionId: common.Region(cloud.Region()),
LoadBalancerID: fi.StringValue(actual.LoadbalancerId),
}
tags, _, err := cloud.SlbClient().DescribeTags(describeTagsArgs)
if err != nil {
glog.V(4).Info("Error getting tags on loadbalancerID:%q", *actual.LoadbalancerId)
}
if len(tags) != 0 {
actual.Tags = make(map[string]string)
for _, tag := range tags {
key := tag.TagKey
value := tag.TagValue
actual.Tags[key] = value
}
}
// Ignore "system" fields
l.LoadbalancerId = actual.LoadbalancerId
actual.Lifecycle = l.Lifecycle
return actual, nil
}
func (l *LoadBalancer) FindIPAddress(context *fi.Context) (*string, error) {
cloud := context.Cloud.(aliup.ALICloud)
// TODO:Get loadbalancer with LoadBalancerName, hope to support finding with tags
describeLoadBalancersArgs := &slb.DescribeLoadBalancersArgs{
RegionId: common.Region(cloud.Region()),
LoadBalancerName: fi.StringValue(l.Name),
AddressType: slb.AddressType(fi.StringValue(l.AddressType)),
}
responseLoadBalancers, err := cloud.SlbClient().DescribeLoadBalancers(describeLoadBalancersArgs)
if err != nil {
return nil, fmt.Errorf("error finding LoadBalancers: %v", err)
}
// Don't exist loadbalancer with specified ClusterTags or Name.
if len(responseLoadBalancers) == 0 {
return nil, nil
}
if len(responseLoadBalancers) > 1 {
glog.V(4).Info("The number of specified loadbalancer whith the same name exceeds 1, loadbalancerName:%q", *l.Name)
}
address := responseLoadBalancers[0].Address
return &address, nil
}
func (l *LoadBalancer) Run(c *fi.Context) error {
if l.Tags == nil {
l.Tags = make(map[string]string)
}
c.Cloud.(aliup.ALICloud).AddClusterTags(l.Tags)
return fi.DefaultDeltaRunMethod(l, c)
}
func (_ *LoadBalancer) CheckChanges(a, e, changes *LoadBalancer) error {
if a == nil {
if e.Name == nil {
return fi.RequiredField("Name")
}
if e.AddressType == nil {
return fi.RequiredField("AddressType")
}
} else {
if changes.AddressType != nil {
return fi.CannotChangeField("AddressType")
}
if changes.Name != nil {
return fi.CannotChangeField("Name")
}
}
return nil
}
//LoadBalancer can only modify tags.
func (_ *LoadBalancer) RenderALI(t *aliup.ALIAPITarget, a, e, changes *LoadBalancer) error {
if a == nil {
glog.V(2).Infof("Creating LoadBalancer with Name:%q", fi.StringValue(e.Name))
createLoadBalancerArgs := &slb.CreateLoadBalancerArgs{
RegionId: common.Region(t.Cloud.Region()),
LoadBalancerName: fi.StringValue(e.Name),
AddressType: slb.AddressType(fi.StringValue(e.AddressType)),
}
response, err := t.Cloud.SlbClient().CreateLoadBalancer(createLoadBalancerArgs)
if err != nil {
return fmt.Errorf("error creating loadbalancer: %v", err)
}
e.LoadbalancerId = fi.String(response.LoadBalancerId)
e.LoadBalancerAddress = fi.String(response.Address)
}
if changes != nil && changes.Tags != nil {
tagItems := e.jsonMarshalTags(e.Tags)
addTagsArgs := &slb.AddTagsArgs{
RegionId: common.Region(t.Cloud.Region()),
LoadBalancerID: fi.StringValue(e.LoadbalancerId),
Tags: string(tagItems),
}
err := t.Cloud.SlbClient().AddTags(addTagsArgs)
if err != nil {
return fmt.Errorf("error adding Tags to Loadbalancer: %v", err)
}
}
if a != nil && (len(a.Tags) > 0) {
glog.V(2).Infof("Modifing LoadBalancer with Name:%q, update LoadBalancer tags", fi.StringValue(e.Name))
tagsToDelete := e.getLoadBalancerTagsToDelete(a.Tags)
if len(tagsToDelete) > 0 {
tagItems := e.jsonMarshalTags(tagsToDelete)
removeTagsArgs := &slb.RemoveTagsArgs{
RegionId: common.Beijing,
LoadBalancerID: fi.StringValue(a.LoadbalancerId),
Tags: string(tagItems),
}
if err := t.Cloud.SlbClient().RemoveTags(removeTagsArgs); err != nil {
return fmt.Errorf("error removing Tags from LoadBalancer: %v", err)
}
}
}
return nil
}
// getDiskTagsToDelete loops through the currently set tags and builds a list of tags to be deleted from the specificated disk
func (l *LoadBalancer) getLoadBalancerTagsToDelete(currentTags map[string]string) map[string]string {
tagsToDelete := map[string]string{}
for k, v := range currentTags {
if _, ok := l.Tags[k]; !ok {
tagsToDelete[k] = v
}
}
return tagsToDelete
}
func (l *LoadBalancer) jsonMarshalTags(tags map[string]string) string {
tagItemArr := []slb.TagItem{}
tagItem := slb.TagItem{}
for key, value := range tags {
tagItem.TagKey = key
tagItem.TagValue = value
tagItemArr = append(tagItemArr, tagItem)
}
tagItems, _ := json.Marshal(tagItemArr)
return string(tagItems)
}
type terraformLoadBalancer struct {
Name *string `json:"name,omitempty"`
Internet *bool `json:"internet,omitempty"`
}
func (_ *LoadBalancer) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *LoadBalancer) error {
tf := &terraformLoadBalancer{
Name: e.Name,
}
if slb.AddressType(fi.StringValue(e.AddressType)) == slb.InternetAddressType {
internet := true
tf.Internet = &internet
} else {
internet := false
tf.Internet = &internet
}
return t.RenderResource("alicloud_slb", *e.Name, tf)
}
func (l *LoadBalancer) TerraformLink() *terraform.Literal {
return terraform.LiteralProperty("alicloud_slb", *l.Name, "id")
}

View File

@ -0,0 +1,75 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by ""fitask" -type=LoadBalancer"; DO NOT EDIT
package alitasks
import (
"encoding/json"
"k8s.io/kops/upup/pkg/fi"
)
// LoadBalancer
// JSON marshalling boilerplate
type realLoadBalancer LoadBalancer
// UnmarshalJSON implements conversion to JSON, supporitng an alternate specification of the object as a string
func (o *LoadBalancer) UnmarshalJSON(data []byte) error {
var jsonName string
if err := json.Unmarshal(data, &jsonName); err == nil {
o.Name = &jsonName
return nil
}
var r realLoadBalancer
if err := json.Unmarshal(data, &r); err != nil {
return err
}
*o = LoadBalancer(r)
return nil
}
var _ fi.HasLifecycle = &LoadBalancer{}
// GetLifecycle returns the Lifecycle of the object, implementing fi.HasLifecycle
func (o *LoadBalancer) GetLifecycle() *fi.Lifecycle {
return o.Lifecycle
}
// SetLifecycle sets the Lifecycle of the object, implementing fi.SetLifecycle
func (o *LoadBalancer) SetLifecycle(lifecycle fi.Lifecycle) {
o.Lifecycle = &lifecycle
}
var _ fi.HasName = &LoadBalancer{}
// GetName returns the Name of the object, implementing fi.HasName
func (o *LoadBalancer) GetName() *string {
return o.Name
}
// SetName sets the Name of the object, implementing fi.SetName
func (o *LoadBalancer) SetName(name string) {
o.Name = &name
}
// String is the stringer function for the task, producing readable output using fi.TaskAsString
func (o *LoadBalancer) String() string {
return fi.TaskAsString(o)
}

View File

@ -0,0 +1,173 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package alitasks
import (
"fmt"
"strconv"
"github.com/golang/glog"
"github.com/denverdino/aliyungo/slb"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
)
const ListenerRunningStatus = "running"
//go:generate fitask -type=LoadBalancerListener
type LoadBalancerListener struct {
LoadBalancer *LoadBalancer
Name *string
ListenerPort *int
BackendServerPort *int
Lifecycle *fi.Lifecycle
ListenerStatus *string
Bandwidth *int
}
var _ fi.CompareWithID = &LoadBalancerListener{}
func (l *LoadBalancerListener) CompareWithID() *string {
listenertPort := strconv.Itoa(fi.IntValue(l.ListenerPort))
return fi.String(listenertPort)
}
func (l *LoadBalancerListener) Find(c *fi.Context) (*LoadBalancerListener, error) {
if l.LoadBalancer == nil || l.LoadBalancer.LoadbalancerId == nil {
glog.V(4).Infof("LoadBalancer / LoadbalancerId not found for %s, skipping Find", fi.StringValue(l.Name))
return nil, nil
}
cloud := c.Cloud.(aliup.ALICloud)
loadBalancerId := fi.StringValue(l.LoadBalancer.LoadbalancerId)
listenertPort := fi.IntValue(l.ListenerPort)
//TODO: should sort errors?
response, err := cloud.SlbClient().DescribeLoadBalancerTCPListenerAttribute(loadBalancerId, listenertPort)
if err != nil {
return nil, nil
}
glog.V(2).Infof("found matching LoadBalancerListener with ListenerPort: %q", *l.ListenerPort)
actual := &LoadBalancerListener{}
actual.BackendServerPort = fi.Int(response.BackendServerPort)
actual.ListenerPort = fi.Int(response.ListenerPort)
actual.ListenerStatus = fi.String(string(response.Status))
actual.Bandwidth = fi.Int(response.Bandwidth)
// Ignore "system" fields
actual.LoadBalancer = l.LoadBalancer
actual.Lifecycle = l.Lifecycle
actual.Name = l.Name
return actual, nil
}
func (l *LoadBalancerListener) Run(c *fi.Context) error {
return fi.DefaultDeltaRunMethod(l, c)
}
func (_ *LoadBalancerListener) CheckChanges(a, e, changes *LoadBalancerListener) error {
if a == nil {
if e.Name == nil {
return fi.RequiredField("Name")
}
if e.ListenerPort == nil {
return fi.RequiredField("ListenerPort")
}
if e.BackendServerPort == nil {
return fi.RequiredField("BackendServerPort")
}
} else {
if changes.BackendServerPort != nil {
return fi.CannotChangeField("BackendServerPort")
}
if changes.Name != nil {
return fi.CannotChangeField("Name")
}
}
return nil
}
//LoadBalancer can only modify tags.
func (_ *LoadBalancerListener) RenderALI(t *aliup.ALIAPITarget, a, e, changes *LoadBalancerListener) error {
loadBalancerId := fi.StringValue(e.LoadBalancer.LoadbalancerId)
listenertPort := fi.IntValue(e.ListenerPort)
if a == nil {
glog.V(2).Infof("Creating LoadBalancerListener with ListenerPort: %q", *e.ListenerPort)
createLoadBalancerTCPListenerArgs := &slb.CreateLoadBalancerTCPListenerArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: listenertPort,
BackendServerPort: fi.IntValue(e.BackendServerPort),
Bandwidth: fi.IntValue(e.Bandwidth),
}
err := t.Cloud.SlbClient().CreateLoadBalancerTCPListener(createLoadBalancerTCPListenerArgs)
if err != nil {
return fmt.Errorf("error creating LoadBalancerlistener: %v", err)
}
}
if fi.StringValue(e.ListenerStatus) == ListenerRunningStatus {
glog.V(2).Infof("Starting LoadBalancerListener with ListenerPort: %q", *e.ListenerPort)
err := t.Cloud.SlbClient().StartLoadBalancerListener(loadBalancerId, listenertPort)
if err != nil {
return fmt.Errorf("error starting LoadBalancerListener: %v", err)
}
} else {
glog.V(2).Infof("Stopping LoadBalancerListener with ListenerPort: %q", *e.ListenerPort)
err := t.Cloud.SlbClient().StopLoadBalancerListener(loadBalancerId, listenertPort)
if err != nil {
return fmt.Errorf("error stopping LoadBalancerListener: %v", err)
}
}
glog.V(2).Infof("Waiting LoadBalancerListener with ListenerPort: %q", *e.ListenerPort)
_, err := t.Cloud.SlbClient().WaitForListener(loadBalancerId, listenertPort, slb.TCP)
if err != nil {
return fmt.Errorf("error waitting LoadBalancerListener: %v", err)
}
return nil
}
type terraformLoadBalancerListener struct {
ListenerPort *int `json:"frontend_port,omitempty"`
BackendServerPort *int `json:"backend_port,omitempty"`
Protocol *string `json:"protocol,omitempty"`
LoadBalancerId *terraform.Literal `json:"load_balancer_id,omitempty"`
}
func (_ *LoadBalancerListener) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *LoadBalancerListener) error {
protocol := "tcp"
tf := &terraformLoadBalancerListener{
ListenerPort: e.ListenerPort,
BackendServerPort: e.BackendServerPort,
Protocol: &protocol,
LoadBalancerId: e.LoadBalancer.TerraformLink(),
}
return t.RenderResource("alicloud_slb_listener", *e.Name, tf)
}
func (s *LoadBalancerListener) TerraformLink() *terraform.Literal {
return terraform.LiteralProperty("alicloud_slb_listener", *s.Name, "frontend_port")
}

View File

@ -0,0 +1,75 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by ""fitask" -type=LoadBalancerListener"; DO NOT EDIT
package alitasks
import (
"encoding/json"
"k8s.io/kops/upup/pkg/fi"
)
// LoadBalancerListener
// JSON marshalling boilerplate
type realLoadBalancerListener LoadBalancerListener
// UnmarshalJSON implements conversion to JSON, supporitng an alternate specification of the object as a string
func (o *LoadBalancerListener) UnmarshalJSON(data []byte) error {
var jsonName string
if err := json.Unmarshal(data, &jsonName); err == nil {
o.Name = &jsonName
return nil
}
var r realLoadBalancerListener
if err := json.Unmarshal(data, &r); err != nil {
return err
}
*o = LoadBalancerListener(r)
return nil
}
var _ fi.HasLifecycle = &LoadBalancerListener{}
// GetLifecycle returns the Lifecycle of the object, implementing fi.HasLifecycle
func (o *LoadBalancerListener) GetLifecycle() *fi.Lifecycle {
return o.Lifecycle
}
// SetLifecycle sets the Lifecycle of the object, implementing fi.SetLifecycle
func (o *LoadBalancerListener) SetLifecycle(lifecycle fi.Lifecycle) {
o.Lifecycle = &lifecycle
}
var _ fi.HasName = &LoadBalancerListener{}
// GetName returns the Name of the object, implementing fi.HasName
func (o *LoadBalancerListener) GetName() *string {
return o.Name
}
// SetName sets the Name of the object, implementing fi.SetName
func (o *LoadBalancerListener) SetName(name string) {
o.Name = &name
}
// String is the stringer function for the task, producing readable output using fi.TaskAsString
func (o *LoadBalancerListener) String() string {
return fi.TaskAsString(o)
}

View File

@ -0,0 +1,141 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package alitasks
import (
"fmt"
"strings"
"github.com/golang/glog"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
)
//go:generate fitask -type=LoadBalancerWhiteList
type LoadBalancerWhiteList struct {
LoadBalancer *LoadBalancer
LoadBalancerListener *LoadBalancerListener
Name *string
SourceItems *string
Lifecycle *fi.Lifecycle
}
var _ fi.CompareWithID = &LoadBalancerWhiteList{}
func (l *LoadBalancerWhiteList) CompareWithID() *string {
return l.Name
}
func (l *LoadBalancerWhiteList) Find(c *fi.Context) (*LoadBalancerWhiteList, error) {
if l.LoadBalancer == nil || l.LoadBalancer.LoadbalancerId == nil {
glog.V(4).Infof("LoadBalancer / LoadbalancerId not found for %s, skipping Find", fi.StringValue(l.Name))
return nil, nil
}
if l.LoadBalancerListener == nil || l.LoadBalancerListener.ListenerPort == nil {
glog.V(4).Infof("LoadBalancerListener / LoadbalancerListenerPort not found for %s, skipping Find", fi.StringValue(l.Name))
return nil, nil
}
cloud := c.Cloud.(aliup.ALICloud)
loadBalancerId := fi.StringValue(l.LoadBalancer.LoadbalancerId)
listenertPort := fi.IntValue(l.LoadBalancerListener.ListenerPort)
response, err := cloud.SlbClient().DescribeListenerAccessControlAttribute(loadBalancerId, listenertPort)
if err != nil {
return nil, fmt.Errorf("error finding LoadBalancerWhiteList: %v", err)
}
if response.SourceItems == "" {
return nil, nil
}
glog.V(2).Infof("found matching LoadBalancerWhiteList of ListenerPort: %q", *l.LoadBalancerListener.ListenerPort)
actual := &LoadBalancerWhiteList{}
actual.SourceItems = fi.String(response.SourceItems)
// Ignore "system" fields
actual.LoadBalancer = l.LoadBalancer
actual.LoadBalancerListener = l.LoadBalancerListener
actual.Lifecycle = l.Lifecycle
return actual, nil
}
func (l *LoadBalancerWhiteList) Run(c *fi.Context) error {
return fi.DefaultDeltaRunMethod(l, c)
}
func (_ *LoadBalancerWhiteList) CheckChanges(a, e, changes *LoadBalancerWhiteList) error {
if a == nil {
if e.Name == nil {
return fi.RequiredField("Name")
}
}
return nil
}
func (_ *LoadBalancerWhiteList) RenderALI(t *aliup.ALIAPITarget, a, e, changes *LoadBalancerWhiteList) error {
glog.V(2).Infof("Updating LoadBalancerWhiteList of ListenerPort: %q", *e.LoadBalancerListener.ListenerPort)
loadBalancerId := fi.StringValue(e.LoadBalancer.LoadbalancerId)
listenertPort := fi.IntValue(e.LoadBalancerListener.ListenerPort)
sourceItems := fi.StringValue(e.SourceItems)
if sourceItems != "" {
err := t.Cloud.SlbClient().AddListenerWhiteListItem(loadBalancerId, listenertPort, sourceItems)
if err != nil {
return fmt.Errorf("error adding LoadBalancerWhiteListItems: %v", err)
}
}
if a != nil && changes.SourceItems != nil {
itemsToDelete := e.getWhiteItemsToDelete(fi.StringValue(a.SourceItems))
if itemsToDelete != "" {
err := t.Cloud.SlbClient().RemoveListenerWhiteListItem(loadBalancerId, listenertPort, itemsToDelete)
if err != nil {
return fmt.Errorf("error removing LoadBalancerWhiteListItems: %v", err)
}
}
}
return nil
}
func (l *LoadBalancerWhiteList) getWhiteItemsToDelete(currentWhiteItems string) string {
currentWhiteItemsList := strings.Split(currentWhiteItems, ",")
expectedWhiteItemsList := strings.Split(fi.StringValue(l.SourceItems), ",")
itemsToDelete := ""
for _, currentItem := range currentWhiteItemsList {
expected := false
if currentItem == "" {
continue
}
for _, expectedItem := range expectedWhiteItemsList {
if currentItem == expectedItem {
expected = true
}
}
if expected == false {
itemsToDelete = itemsToDelete + "," + currentItem
}
}
return itemsToDelete
}
func (_ *LoadBalancerWhiteList) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *LoadBalancerWhiteList) error {
glog.Warningf("terraform does not support LoadBalancerWhiteList on ALI cloud")
return nil
}

View File

@ -0,0 +1,75 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by ""fitask" -type=LoadBalancerWhiteList"; DO NOT EDIT
package alitasks
import (
"encoding/json"
"k8s.io/kops/upup/pkg/fi"
)
// LoadBalancerWhiteList
// JSON marshalling boilerplate
type realLoadBalancerWhiteList LoadBalancerWhiteList
// UnmarshalJSON implements conversion to JSON, supporitng an alternate specification of the object as a string
func (o *LoadBalancerWhiteList) UnmarshalJSON(data []byte) error {
var jsonName string
if err := json.Unmarshal(data, &jsonName); err == nil {
o.Name = &jsonName
return nil
}
var r realLoadBalancerWhiteList
if err := json.Unmarshal(data, &r); err != nil {
return err
}
*o = LoadBalancerWhiteList(r)
return nil
}
var _ fi.HasLifecycle = &LoadBalancerWhiteList{}
// GetLifecycle returns the Lifecycle of the object, implementing fi.HasLifecycle
func (o *LoadBalancerWhiteList) GetLifecycle() *fi.Lifecycle {
return o.Lifecycle
}
// SetLifecycle sets the Lifecycle of the object, implementing fi.SetLifecycle
func (o *LoadBalancerWhiteList) SetLifecycle(lifecycle fi.Lifecycle) {
o.Lifecycle = &lifecycle
}
var _ fi.HasName = &LoadBalancerWhiteList{}
// GetName returns the Name of the object, implementing fi.HasName
func (o *LoadBalancerWhiteList) GetName() *string {
return o.Name
}
// SetName sets the Name of the object, implementing fi.SetName
func (o *LoadBalancerWhiteList) SetName(name string) {
o.Name = &name
}
// String is the stringer function for the task, producing readable output using fi.TaskAsString
func (o *LoadBalancerWhiteList) String() string {
return fi.TaskAsString(o)
}

View File

@ -17,6 +17,7 @@ go_library(
"//upup/pkg/fi:go_default_library",
"//vendor/github.com/denverdino/aliyungo/common:go_default_library",
"//vendor/github.com/denverdino/aliyungo/ecs:go_default_library",
"//vendor/github.com/denverdino/aliyungo/slb:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
],

View File

@ -25,6 +25,7 @@ import (
"github.com/denverdino/aliyungo/common"
"github.com/denverdino/aliyungo/ecs"
"github.com/denverdino/aliyungo/slb"
"k8s.io/api/core/v1"
prj "k8s.io/kops"
@ -43,6 +44,7 @@ type ALICloud interface {
fi.Cloud
EcsClient() *ecs.Client
SlbClient() *slb.Client
Region() string
AddClusterTags(tags map[string]string)
GetTags(resourceId string, resourceType string) (map[string]string, error)
@ -53,6 +55,7 @@ type ALICloud interface {
type aliCloudImplementation struct {
ecsClient *ecs.Client
slbClient *slb.Client
region string
tags map[string]string
@ -86,6 +89,10 @@ func (c *aliCloudImplementation) EcsClient() *ecs.Client {
return c.ecsClient
}
func (c *aliCloudImplementation) SlbClient() *slb.Client {
return c.slbClient
}
func (c *aliCloudImplementation) Region() string {
return c.region
}

23
vendor/github.com/denverdino/aliyungo/slb/BUILD.bazel generated vendored Normal file
View File

@ -0,0 +1,23 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"certificates.go",
"client.go",
"listeners.go",
"loadbalancers.go",
"regions.go",
"rules.go",
"servers.go",
"tags.go",
"vserver_group.go",
],
importmap = "vendor/github.com/denverdino/aliyungo/slb",
importpath = "github.com/denverdino/aliyungo/slb",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/denverdino/aliyungo/common:go_default_library",
"//vendor/github.com/denverdino/aliyungo/util:go_default_library",
],
)

View File

@ -0,0 +1,108 @@
package slb
import "github.com/denverdino/aliyungo/common"
type UploadServerCertificateArgs struct {
RegionId common.Region
ServerCertificate string
ServerCertificateName string
PrivateKey string
}
type UploadServerCertificateResponse struct {
common.Response
ServerCertificateId string
ServerCertificateName string
Fingerprint string
}
// UploadServerCertificate Upload server certificate
//
// You can read doc at http://docs.aliyun.com/#pub/slb/api-reference/api-servercertificate&UploadServerCertificate
func (client *Client) UploadServerCertificate(args *UploadServerCertificateArgs) (response *UploadServerCertificateResponse, err error) {
response = &UploadServerCertificateResponse{}
err = client.Invoke("UploadServerCertificate", args, response)
if err != nil {
return nil, err
}
return response, err
}
type DeleteServerCertificateArgs struct {
RegionId common.Region
ServerCertificateId string
}
type DeleteServerCertificateResponse struct {
common.Response
}
// DeleteServerCertificate Delete server certificate
//
// You can read doc at http://docs.aliyun.com/#pub/slb/api-reference/api-servercertificate&DeleteServerCertificate
func (client *Client) DeleteServerCertificate(regionId common.Region, serverCertificateId string) (err error) {
args := &DeleteServerCertificateArgs{
RegionId: regionId,
ServerCertificateId: serverCertificateId,
}
response := &DeleteServerCertificateResponse{}
return client.Invoke("DeleteServerCertificate", args, response)
}
type SetServerCertificateNameArgs struct {
RegionId common.Region
ServerCertificateId string
ServerCertificateName string
}
type SetServerCertificateNameResponse struct {
common.Response
}
// SetServerCertificateName Set name of server certificate
//
// You can read doc at http://docs.aliyun.com/#pub/slb/api-reference/api-servercertificate&SetServerCertificateName
func (client *Client) SetServerCertificateName(regionId common.Region, serverCertificateId string, name string) (err error) {
args := &SetServerCertificateNameArgs{
RegionId: regionId,
ServerCertificateId: serverCertificateId,
ServerCertificateName: name,
}
response := &SetServerCertificateNameResponse{}
return client.Invoke("SetServerCertificateName", args, response)
}
type DescribeServerCertificatesArgs struct {
RegionId common.Region
ServerCertificateId string
}
type ServerCertificateType struct {
RegionId common.Region
ServerCertificateId string
ServerCertificateName string
Fingerprint string
}
type DescribeServerCertificatesResponse struct {
common.Response
ServerCertificates struct {
ServerCertificate []ServerCertificateType
}
}
// DescribeServerCertificates Describe server certificates
//
// You can read doc at http://docs.aliyun.com/#pub/slb/api-reference/api-servercertificate&DescribeServerCertificates
func (client *Client) DescribeServerCertificatesArgs(regionId common.Region, serverCertificateId string) (serverCertificates []ServerCertificateType, err error) {
args := &DescribeServerCertificatesArgs{
RegionId: regionId,
ServerCertificateId: serverCertificateId,
}
response := &DescribeServerCertificatesResponse{}
err = client.Invoke("DescribeServerCertificates", args, response)
if err != nil {
return nil, err
}
return response.ServerCertificates.ServerCertificate, err
}

71
vendor/github.com/denverdino/aliyungo/slb/client.go generated vendored Normal file
View File

@ -0,0 +1,71 @@
package slb
import (
"os"
"github.com/denverdino/aliyungo/common"
)
type Client struct {
common.Client
}
const (
// SLBDefaultEndpoint is the default API endpoint of SLB services
SLBDefaultEndpoint = "https://slb.aliyuncs.com"
SLBAPIVersion = "2014-05-15"
SLBServiceCode = "slb"
)
// NewClient creates a new instance of ECS client
func NewClient(accessKeyId, accessKeySecret string) *Client {
endpoint := os.Getenv("SLB_ENDPOINT")
if endpoint == "" {
endpoint = SLBDefaultEndpoint
}
return NewClientWithEndpoint(endpoint, accessKeyId, accessKeySecret)
}
func NewClientWithEndpoint(endpoint string, accessKeyId, accessKeySecret string) *Client {
client := &Client{}
client.Init(endpoint, SLBAPIVersion, accessKeyId, accessKeySecret)
return client
}
func NewSLBClient(accessKeyId, accessKeySecret string, regionID common.Region) *Client {
endpoint := os.Getenv("SLB_ENDPOINT")
if endpoint == "" {
endpoint = SLBDefaultEndpoint
}
return NewClientWithRegion(endpoint, accessKeyId, accessKeySecret, regionID)
}
func NewClientWithRegion(endpoint string, accessKeyId, accessKeySecret string, regionID common.Region) *Client {
client := &Client{}
client.NewInit(endpoint, SLBAPIVersion, accessKeyId, accessKeySecret, SLBServiceCode, regionID)
return client
}
func NewSLBClientWithSecurityToken(accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client {
endpoint := os.Getenv("SLB_ENDPOINT")
if endpoint == "" {
endpoint = SLBDefaultEndpoint
}
return NewSLBClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, securityToken, regionID)
}
func NewSLBClientWithEndpointAndSecurityToken(endpoint string, accessKeyId string, accessKeySecret string, securityToken string, regionID common.Region) *Client {
client := &Client{}
client.WithEndpoint(endpoint).
WithVersion(SLBAPIVersion).
WithAccessKeyId(accessKeyId).
WithAccessKeySecret(accessKeySecret).
WithSecurityToken(securityToken).
WithServiceCode(SLBServiceCode).
WithRegionID(regionID).
InitClient()
return client
}

539
vendor/github.com/denverdino/aliyungo/slb/listeners.go generated vendored Normal file
View File

@ -0,0 +1,539 @@
package slb
import (
"fmt"
"strings"
"time"
"github.com/denverdino/aliyungo/common"
)
type ListenerStatus string
const (
Starting = ListenerStatus("starting")
Running = ListenerStatus("running")
Configuring = ListenerStatus("configuring")
Stopping = ListenerStatus("stopping")
Stopped = ListenerStatus("stopped")
)
type SchedulerType string
const (
WRRScheduler = SchedulerType("wrr")
WLCScheduler = SchedulerType("wlc")
)
type FlagType string
const (
OnFlag = FlagType("on")
OffFlag = FlagType("off")
)
type StickySessionType string
const (
InsertStickySessionType = StickySessionType("insert")
ServerStickySessionType = StickySessionType("server")
)
const BackendServerPort = -520
type HealthCheckHttpCodeType string
const (
HTTP_2XX = HealthCheckHttpCodeType("http_2xx")
HTTP_3XX = HealthCheckHttpCodeType("http_3xx")
HTTP_4XX = HealthCheckHttpCodeType("http_4xx")
HTTP_5XX = HealthCheckHttpCodeType("http_5xx")
)
func EncodeHealthCheckHttpCodeType(healthCheckHttpCodes []HealthCheckHttpCodeType) (HealthCheckHttpCodeType, error) {
code := ""
if nil == healthCheckHttpCodes || len(healthCheckHttpCodes) < 1 {
return "", fmt.Errorf("Invalid size of healthCheckHttpCodes")
}
for _, healthCheckHttpCode := range healthCheckHttpCodes {
if strings.EqualFold(string(HTTP_2XX), string(healthCheckHttpCode)) ||
strings.EqualFold(string(HTTP_3XX), string(healthCheckHttpCode)) ||
strings.EqualFold(string(HTTP_4XX), string(healthCheckHttpCode)) ||
strings.EqualFold(string(HTTP_5XX), string(healthCheckHttpCode)) {
if "" == code {
code = string(healthCheckHttpCode)
} else {
if strings.Contains(code, string(healthCheckHttpCode)) {
return "", fmt.Errorf("Duplicates healthCheckHttpCode(%v in %v)", healthCheckHttpCode, healthCheckHttpCodes)
}
code += code + "," + string(healthCheckHttpCode)
}
} else {
return "", fmt.Errorf("Invalid healthCheckHttpCode(%v in %v)", healthCheckHttpCode, healthCheckHttpCodes)
}
}
return HealthCheckHttpCodeType(code), nil
}
type CommonLoadBalancerListenerResponse struct {
common.Response
}
type HTTPListenerType struct {
LoadBalancerId string
ListenerPort int
BackendServerPort int
Bandwidth int
Scheduler SchedulerType
StickySession FlagType
StickySessionType StickySessionType
CookieTimeout int
Cookie string
HealthCheck FlagType
HealthCheckDomain string
HealthCheckURI string
HealthCheckConnectPort int
HealthyThreshold int
UnhealthyThreshold int
HealthCheckTimeout int
HealthCheckInterval int
HealthCheckHttpCode HealthCheckHttpCodeType
VServerGroup FlagType
VServerGroupId string
Gzip FlagType
XForwardedFor_SLBID FlagType
XForwardedFor_SLBIP FlagType
XForwardedFor_proto FlagType
}
type CreateLoadBalancerHTTPListenerArgs HTTPListenerType
// CreateLoadBalancerHTTPListener create HTTP listener on loadbalancer
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&CreateLoadBalancerHTTPListener
func (client *Client) CreateLoadBalancerHTTPListener(args *CreateLoadBalancerHTTPListenerArgs) (err error) {
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("CreateLoadBalancerHTTPListener", args, response)
return err
}
type HTTPSListenerType struct {
HTTPListenerType
ServerCertificateId string
}
type CreateLoadBalancerHTTPSListenerArgs HTTPSListenerType
// CreateLoadBalancerHTTPSListener create HTTPS listener on loadbalancer
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&CreateLoadBalancerHTTPSListener
func (client *Client) CreateLoadBalancerHTTPSListener(args *CreateLoadBalancerHTTPSListenerArgs) (err error) {
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("CreateLoadBalancerHTTPSListener", args, response)
return err
}
type HealthCheckType string
const (
TCPHealthCheckType = HealthCheckType("tcp")
HTTPHealthCheckType = HealthCheckType("http")
)
type TCPListenerType struct {
LoadBalancerId string
ListenerPort int
BackendServerPort int
Bandwidth int
Scheduler SchedulerType
PersistenceTimeout int
HealthCheck FlagType
HealthCheckType HealthCheckType
HealthCheckDomain string
HealthCheckURI string
HealthCheckConnectPort int
HealthyThreshold int
UnhealthyThreshold int
HealthCheckConnectTimeout int
HealthCheckInterval int
HealthCheckHttpCode HealthCheckHttpCodeType
VServerGroup FlagType
VServerGroupId string
}
type CreateLoadBalancerTCPListenerArgs TCPListenerType
// CreateLoadBalancerTCPListener create TCP listener on loadbalancer
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&CreateLoadBalancerTCPListener
func (client *Client) CreateLoadBalancerTCPListener(args *CreateLoadBalancerTCPListenerArgs) (err error) {
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("CreateLoadBalancerTCPListener", args, response)
return err
}
type UDPListenerType struct {
LoadBalancerId string
ListenerPort int
BackendServerPort int
Bandwidth int
Scheduler SchedulerType
PersistenceTimeout int
HealthCheck FlagType
HealthCheckConnectPort int
HealthyThreshold int
UnhealthyThreshold int
HealthCheckConnectTimeout int
HealthCheckInterval int
VServerGroup FlagType
VServerGroupId string
}
type CreateLoadBalancerUDPListenerArgs UDPListenerType
// CreateLoadBalancerUDPListener create UDP listener on loadbalancer
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&CreateLoadBalancerUDPListener
func (client *Client) CreateLoadBalancerUDPListener(args *CreateLoadBalancerUDPListenerArgs) (err error) {
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("CreateLoadBalancerUDPListener", args, response)
return err
}
type CommonLoadBalancerListenerArgs struct {
LoadBalancerId string
ListenerPort int
}
// DeleteLoadBalancerListener Delete listener
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&DeleteLoadBalancerListener
func (client *Client) DeleteLoadBalancerListener(loadBalancerId string, port int) (err error) {
args := &CommonLoadBalancerListenerArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: port,
}
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("DeleteLoadBalancerListener", args, response)
return err
}
// StartLoadBalancerListener Start listener
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&StartLoadBalancerListener
func (client *Client) StartLoadBalancerListener(loadBalancerId string, port int) (err error) {
args := &CommonLoadBalancerListenerArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: port,
}
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("StartLoadBalancerListener", args, response)
return err
}
// StopLoadBalancerListener Stop listener
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&StopLoadBalancerListener
func (client *Client) StopLoadBalancerListener(loadBalancerId string, port int) (err error) {
args := &CommonLoadBalancerListenerArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: port,
}
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("StopLoadBalancerListener", args, response)
return err
}
type AccessControlStatus string
const (
OpenWhileList = AccessControlStatus("open_white_list")
Close = AccessControlStatus("close")
)
type SetListenerAccessControlStatusArgs struct {
LoadBalancerId string
ListenerPort int
AccessControlStatus AccessControlStatus
}
// SetListenerAccessControlStatus Set listener access control status
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&SetListenerAccessControlStatus
func (client *Client) SetListenerAccessControlStatus(loadBalancerId string, port int, status AccessControlStatus) (err error) {
args := &SetListenerAccessControlStatusArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: port,
AccessControlStatus: status,
}
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("SetListenerAccessControlStatus", args, response)
return err
}
type CommonListenerWhiteListItemArgs struct {
LoadBalancerId string
ListenerPort int
SourceItems string
}
// AddListenerWhiteListItem Add listener white-list item
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&AddListenerWhiteListItem
func (client *Client) AddListenerWhiteListItem(loadBalancerId string, port int, sourceItems string) (err error) {
args := &CommonListenerWhiteListItemArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: port,
SourceItems: sourceItems,
}
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("AddListenerWhiteListItem", args, response)
return err
}
// RemoveListenerWhiteListItem Remove listener white-list item
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&RemoveListenerWhiteListItem
func (client *Client) RemoveListenerWhiteListItem(loadBalancerId string, port int, sourceItems string) (err error) {
args := &CommonListenerWhiteListItemArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: port,
SourceItems: sourceItems,
}
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("RemoveListenerWhiteListItem", args, response)
return err
}
type SetLoadBalancerHTTPListenerAttributeArgs CreateLoadBalancerHTTPListenerArgs
// SetLoadBalancerHTTPListenerAttribute Set HTTP listener attribute
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&SetLoadBalancerHTTPListenerAttribute
func (client *Client) SetLoadBalancerHTTPListenerAttribute(args *SetLoadBalancerHTTPListenerAttributeArgs) (err error) {
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("SetLoadBalancerHTTPListenerAttribute", args, response)
return err
}
type SetLoadBalancerHTTPSListenerAttributeArgs CreateLoadBalancerHTTPSListenerArgs
// SetLoadBalancerHTTPSListenerAttribute Set HTTPS listener attribute
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&SetLoadBalancerHTTPSListenerAttribute
func (client *Client) SetLoadBalancerHTTPSListenerAttribute(args *SetLoadBalancerHTTPSListenerAttributeArgs) (err error) {
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("SetLoadBalancerHTTPSListenerAttribute", args, response)
return err
}
type SetLoadBalancerTCPListenerAttributeArgs CreateLoadBalancerTCPListenerArgs
// SetLoadBalancerTCPListenerAttribute Set TCP listener attribute
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&SetLoadBalancerTCPListenerAttribute
func (client *Client) SetLoadBalancerTCPListenerAttribute(args *SetLoadBalancerTCPListenerAttributeArgs) (err error) {
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("SetLoadBalancerTCPListenerAttribute", args, response)
return err
}
type SetLoadBalancerUDPListenerAttributeArgs CreateLoadBalancerUDPListenerArgs
// SetLoadBalancerUDPListenerAttribute Set UDP listener attribute
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&SetLoadBalancerUDPListenerAttribute
func (client *Client) SetLoadBalancerUDPListenerAttribute(args *SetLoadBalancerUDPListenerAttributeArgs) (err error) {
response := &CommonLoadBalancerListenerResponse{}
err = client.Invoke("SetLoadBalancerUDPListenerAttribute", args, response)
return err
}
type DescribeLoadBalancerListenerAttributeResponse struct {
common.Response
Status ListenerStatus
}
type DescribeLoadBalancerHTTPListenerAttributeResponse struct {
DescribeLoadBalancerListenerAttributeResponse
HTTPListenerType
}
// DescribeLoadBalancerHTTPListenerAttribute Describe HTTP listener attribute
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&DescribeLoadBalancerHTTPListenerAttribute
func (client *Client) DescribeLoadBalancerHTTPListenerAttribute(loadBalancerId string, port int) (response *DescribeLoadBalancerHTTPListenerAttributeResponse, err error) {
args := &CommonLoadBalancerListenerArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: port,
}
response = &DescribeLoadBalancerHTTPListenerAttributeResponse{}
err = client.Invoke("DescribeLoadBalancerHTTPListenerAttribute", args, response)
if err != nil {
return nil, err
}
return response, err
}
type DescribeLoadBalancerHTTPSListenerAttributeResponse struct {
DescribeLoadBalancerListenerAttributeResponse
HTTPSListenerType
}
// DescribeLoadBalancerHTTPSListenerAttribute Describe HTTPS listener attribute
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&DescribeLoadBalancerHTTPSListenerAttribute
func (client *Client) DescribeLoadBalancerHTTPSListenerAttribute(loadBalancerId string, port int) (response *DescribeLoadBalancerHTTPSListenerAttributeResponse, err error) {
args := &CommonLoadBalancerListenerArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: port,
}
response = &DescribeLoadBalancerHTTPSListenerAttributeResponse{}
err = client.Invoke("DescribeLoadBalancerHTTPSListenerAttribute", args, response)
if err != nil {
return nil, err
}
return response, err
}
type DescribeLoadBalancerTCPListenerAttributeResponse struct {
DescribeLoadBalancerListenerAttributeResponse
TCPListenerType
}
// DescribeLoadBalancerTCPListenerAttribute Describe TCP listener attribute
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&DescribeLoadBalancerTCPListenerAttribute
func (client *Client) DescribeLoadBalancerTCPListenerAttribute(loadBalancerId string, port int) (response *DescribeLoadBalancerTCPListenerAttributeResponse, err error) {
args := &CommonLoadBalancerListenerArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: port,
}
response = &DescribeLoadBalancerTCPListenerAttributeResponse{}
err = client.Invoke("DescribeLoadBalancerTCPListenerAttribute", args, response)
if err != nil {
return nil, err
}
return response, err
}
type DescribeLoadBalancerUDPListenerAttributeResponse struct {
DescribeLoadBalancerListenerAttributeResponse
UDPListenerType
}
// DescribeLoadBalancerUDPListenerAttribute Describe UDP listener attribute
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&DescribeLoadBalancerUDPListenerAttribute
func (client *Client) DescribeLoadBalancerUDPListenerAttribute(loadBalancerId string, port int) (response *DescribeLoadBalancerUDPListenerAttributeResponse, err error) {
args := &CommonLoadBalancerListenerArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: port,
}
response = &DescribeLoadBalancerUDPListenerAttributeResponse{}
err = client.Invoke("DescribeLoadBalancerUDPListenerAttribute", args, response)
if err != nil {
return nil, err
}
return response, err
}
type ListenerType string
const (
UDP = ListenerType("UDP")
TCP = ListenerType("TCP")
HTTP = ListenerType("HTTP")
HTTPS = ListenerType("HTTPS")
)
const DefaultWaitForInterval = 5 //5 seconds
const DefaultTimeout = 60 //60 seconds
// WaitForListener waits for listener to given status
func (client *Client) WaitForListener(loadBalancerId string, port int, listenerType ListenerType) (status ListenerStatus, err error) {
timeout := DefaultTimeout
args := &CommonLoadBalancerListenerArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: port,
}
method := fmt.Sprintf("DescribeLoadBalancer%sListenerAttribute", listenerType)
response := &DescribeLoadBalancerListenerAttributeResponse{}
for {
timeout = timeout - DefaultWaitForInterval
if timeout <= 0 {
return response.Status, common.GetClientErrorFromString("Timeout")
}
time.Sleep(DefaultWaitForInterval * time.Second)
//Sleep first to ensure the previous request is sent
err = client.Invoke(method, args, response)
if err != nil {
return "", err
}
if response.Status == Running || response.Status == Stopped {
break
}
}
return response.Status, nil
}
// WaitForListener waits for listener to given status
func (client *Client) WaitForListenerAsyn(loadBalancerId string, port int, listenerType ListenerType, status ListenerStatus, timeout int) error {
if timeout <= 0 {
timeout = DefaultTimeout
}
args := &CommonLoadBalancerListenerArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: port,
}
method := fmt.Sprintf("DescribeLoadBalancer%sListenerAttribute", listenerType)
response := &DescribeLoadBalancerListenerAttributeResponse{}
for {
err := client.Invoke(method, args, response)
e, _ := err.(*common.Error)
if e != nil {
if e.StatusCode == 404 || e.Code == "InvalidLoadBalancerId.NotFound" {
continue
}
return err
} else if response != nil && response.Status == status {
//TODO
break
}
timeout = timeout - DefaultWaitForInterval
if timeout <= 0 {
return common.GetClientErrorFromString("Timeout")
}
time.Sleep(DefaultWaitForInterval * time.Second)
}
return nil
}
type DescribeListenerAccessControlAttributeResponse struct {
common.Response
AccessControlStatus AccessControlStatus
SourceItems string
}
// DescribeListenerAccessControlAttribute Describe listener access control attribute
//
// You can read doc at https://docs.aliyun.com/#/pub/slb/api-reference/api-related-listener&DescribeListenerAccessControlAttribute
func (client *Client) DescribeListenerAccessControlAttribute(loadBalancerId string, port int) (response *DescribeListenerAccessControlAttributeResponse, err error) {
args := &CommonLoadBalancerListenerArgs{
LoadBalancerId: loadBalancerId,
ListenerPort: port,
}
response = &DescribeListenerAccessControlAttributeResponse{}
err = client.Invoke("DescribeListenerAccessControlAttribute", args, response)
if err != nil {
return nil, err
}
return response, err
}

View File

@ -0,0 +1,320 @@
package slb
import (
"fmt"
"github.com/denverdino/aliyungo/common"
"github.com/denverdino/aliyungo/util"
"time"
)
type AddressType string
const (
InternetAddressType = AddressType("internet")
IntranetAddressType = AddressType("intranet")
)
type InternetChargeType string
const (
PayByBandwidth = InternetChargeType("paybybandwidth")
PayByTraffic = InternetChargeType("paybytraffic")
)
type LoadBalancerSpecType string
const (
S1Small = "slb.s1.small"
S2Small = "slb.s2.small"
S2Medium = "slb.s2.medium"
S3Small = "slb.s3.small"
S3Medium = "slb.s3.medium"
S3Large = "slb.s3.large"
)
type CreateLoadBalancerArgs struct {
RegionId common.Region
LoadBalancerName string
AddressType AddressType
VSwitchId string
InternetChargeType InternetChargeType
Bandwidth int
ClientToken string
MasterZoneId string
SlaveZoneId string
LoadBalancerSpec LoadBalancerSpecType
}
type CreateLoadBalancerResponse struct {
common.Response
LoadBalancerId string
Address string
NetworkType string
VpcId string
VSwitchId string
LoadBalancerName string
}
// CreateLoadBalancer create loadbalancer
//
// You can read doc at http://docs.aliyun.com/#/pub/slb/api-reference/api-related-loadbalancer&CreateLoadBalancer
func (client *Client) CreateLoadBalancer(args *CreateLoadBalancerArgs) (response *CreateLoadBalancerResponse, err error) {
response = &CreateLoadBalancerResponse{}
err = client.Invoke("CreateLoadBalancer", args, response)
if err != nil {
return nil, err
}
return response, err
}
type DeleteLoadBalancerArgs struct {
LoadBalancerId string
}
type DeleteLoadBalancerResponse struct {
common.Response
}
// DeleteLoadBalancer delete loadbalancer
//
// You can read doc at http://docs.aliyun.com/#/pub/slb/api-reference/api-related-loadbalancer&DeleteLoadBalancer
func (client *Client) DeleteLoadBalancer(loadBalancerId string) (err error) {
args := &DeleteLoadBalancerArgs{
LoadBalancerId: loadBalancerId,
}
response := &DeleteLoadBalancerResponse{}
err = client.Invoke("DeleteLoadBalancer", args, response)
return err
}
type ModifyLoadBalancerInternetSpecArgs struct {
LoadBalancerId string
InternetChargeType InternetChargeType
Bandwidth int
}
type ModifyLoadBalancerInternetSpecResponse struct {
common.Response
}
// ModifyLoadBalancerInternetSpec Modify loadbalancer internet spec
//
// You can read doc at http://docs.aliyun.com/#/pub/slb/api-reference/api-related-loadbalancer&ModifyLoadBalancerInternetSpec
func (client *Client) ModifyLoadBalancerInternetSpec(args *ModifyLoadBalancerInternetSpecArgs) (err error) {
response := &ModifyLoadBalancerInternetSpecResponse{}
err = client.Invoke("ModifyLoadBalancerInternetSpec", args, response)
return err
}
type ModifyLoadBalancerInstanceSpecArgs struct {
RegionId common.Region
LoadBalancerId string
LoadBalancerSpec LoadBalancerSpecType
}
// ModifyLoadBalancerInstanceSpec Modify loadbalancer instance spec
//
// You can read doc at https://help.aliyun.com/document_detail/53360.html
func (client *Client) ModifyLoadBalancerInstanceSpec(args *ModifyLoadBalancerInstanceSpecArgs) (err error) {
response := &common.Response{}
err = client.Invoke("ModifyLoadBalancerInstanceSpec", args, response)
return err
}
type Status string
const InactiveStatus = Status("inactive")
const ActiveStatus = Status("active")
const LockedStatus = Status("locked")
type SetLoadBalancerStatusArgs struct {
LoadBalancerId string
LoadBalancerStatus Status
}
type SetLoadBalancerStatusResponse struct {
common.Response
}
// SetLoadBalancerStatus Set loadbalancer status
//
// You can read doc at http://docs.aliyun.com/#/pub/slb/api-reference/api-related-loadbalancer&SetLoadBalancerStatus
func (client *Client) SetLoadBalancerStatus(loadBalancerId string, status Status) (err error) {
args := &SetLoadBalancerStatusArgs{
LoadBalancerId: loadBalancerId,
LoadBalancerStatus: status,
}
response := &SetLoadBalancerStatusResponse{}
err = client.Invoke("SetLoadBalancerStatus", args, response)
return err
}
type SetLoadBalancerNameArgs struct {
LoadBalancerId string
LoadBalancerName string
}
type SetLoadBalancerNameResponse struct {
common.Response
}
// SetLoadBalancerName Set loadbalancer name
//
// You can read doc at http://docs.aliyun.com/#/pub/slb/api-reference/api-related-loadbalancer&SetLoadBalancerName
func (client *Client) SetLoadBalancerName(loadBalancerId string, name string) (err error) {
args := &SetLoadBalancerNameArgs{
LoadBalancerId: loadBalancerId,
LoadBalancerName: name,
}
response := &SetLoadBalancerNameResponse{}
err = client.Invoke("SetLoadBalancerName", args, response)
return err
}
type DescribeLoadBalancersArgs struct {
RegionId common.Region
LoadBalancerId string
LoadBalancerName string
AddressType AddressType
NetworkType string
VpcId string
VSwitchId string
Address string
InternetChargeType InternetChargeType
ServerId string
}
type ListenerPortAndProtocolType struct {
ListenerPort int
ListenerProtocol string
}
type BackendServerType struct {
ServerId string
Weight int
}
type LoadBalancerType struct {
LoadBalancerId string
LoadBalancerName string
LoadBalancerStatus string
Address string
RegionId common.Region
RegionIdAlias string
AddressType AddressType
VSwitchId string
VpcId string
NetworkType string
Bandwidth int
InternetChargeType InternetChargeType
CreateTime string //Why not ISO 6801
CreateTimeStamp util.ISO6801Time
ListenerPorts struct {
ListenerPort []int
}
ListenerPortsAndProtocol struct {
ListenerPortAndProtocol []ListenerPortAndProtocolType
}
BackendServers struct {
BackendServer []BackendServerType
}
LoadBalancerSpec LoadBalancerSpecType
}
type DescribeLoadBalancersResponse struct {
common.Response
LoadBalancers struct {
LoadBalancer []LoadBalancerType
}
}
// DescribeLoadBalancers Describe loadbalancers
//
// You can read doc at http://docs.aliyun.com/#/pub/slb/api-reference/api-related-loadbalancer&DescribeLoadBalancers
func (client *Client) DescribeLoadBalancers(args *DescribeLoadBalancersArgs) (loadBalancers []LoadBalancerType, err error) {
response := &DescribeLoadBalancersResponse{}
err = client.Invoke("DescribeLoadBalancers", args, response)
if err != nil {
return nil, err
}
return response.LoadBalancers.LoadBalancer, err
}
type DescribeLoadBalancerAttributeArgs struct {
LoadBalancerId string
}
type DescribeLoadBalancerAttributeResponse struct {
common.Response
LoadBalancerType
}
// DescribeLoadBalancerAttribute Describe loadbalancer attribute
//
// You can read doc at http://docs.aliyun.com/#/pub/slb/api-reference/api-related-loadbalancer&DescribeLoadBalancerAttribute
func (client *Client) DescribeLoadBalancerAttribute(loadBalancerId string) (loadBalancer *LoadBalancerType, err error) {
args := &DescribeLoadBalancersArgs{
LoadBalancerId: loadBalancerId,
}
response := &DescribeLoadBalancerAttributeResponse{}
err = client.Invoke("DescribeLoadBalancerAttribute", args, response)
if err != nil {
return nil, err
}
return &response.LoadBalancerType, err
}
type NewDescribeLoadBalancerAttributeArgs struct {
LoadBalancerId string
RegionId common.Region
MasterZoneId string
SlaveZoneId string
}
// New DescribeLoadBalancerAttribute to describe loadbalancer attribute using regionId avoiding to get not found error
//
// You can read doc at https://www.alibabacloud.com/help/doc-detail/27583.htm
func (client *Client) NewDescribeLoadBalancerAttribute(args *NewDescribeLoadBalancerAttributeArgs) (loadBalancer *LoadBalancerType, err error) {
response := &DescribeLoadBalancerAttributeResponse{}
err = client.Invoke("DescribeLoadBalancerAttribute", args, response)
if err != nil {
return nil, err
}
return &response.LoadBalancerType, err
}
// WaitForListener waits for listener to given status
func (client *Client) WaitForLoadBalancerAsyn(loadBalancerId string, status Status, timeout int) error {
if timeout <= 0 {
timeout = DefaultTimeout
}
for {
lb, err := client.DescribeLoadBalancerAttribute(loadBalancerId)
e, _ := err.(*common.Error)
if e != nil {
if e.StatusCode == 404 || e.Code == "InvalidLoadBalancerId.NotFound" {
continue
}
return err
} else if lb != nil && Status(lb.LoadBalancerStatus) == status {
//TODO
break
}
timeout = timeout - DefaultWaitForInterval
if timeout <= 0 {
return common.GetClientErrorFromString(fmt.Sprintf("Timeout waitting for load balacner %#v", status))
}
time.Sleep(DefaultWaitForInterval * time.Second)
}
return nil
}

34
vendor/github.com/denverdino/aliyungo/slb/regions.go generated vendored Normal file
View File

@ -0,0 +1,34 @@
package slb
import "github.com/denverdino/aliyungo/common"
type DescribeRegionsArgs struct {
}
//
// You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/datatype&regiontype
type RegionType struct {
RegionId common.Region
LocalName string
}
type DescribeRegionsResponse struct {
common.Response
Regions struct {
Region []RegionType
}
}
// DescribeRegions describes regions
//
// You can read doc at http://docs.aliyun.com/#/pub/slb/api-reference/api-related-loadbalancer&DescribeRegions
func (client *Client) DescribeRegions() (regions []RegionType, err error) {
response := DescribeRegionsResponse{}
err = client.Invoke("DescribeRegions", &DescribeRegionsArgs{}, &response)
if err != nil {
return []RegionType{}, err
}
return response.Regions.Region, nil
}

126
vendor/github.com/denverdino/aliyungo/slb/rules.go generated vendored Normal file
View File

@ -0,0 +1,126 @@
package slb
import "github.com/denverdino/aliyungo/common"
type CreateRulesResponse struct {
common.Response
}
type CreateRulesArgs struct {
RegionId common.Region
LoadBalancerId string
ListenerPort int
RuleList string
}
type Rule struct {
RuleId string
RuleName string
Domain string
Url string `json:",omitempty"`
VServerGroupId string
}
// Create forward rules
//
// You can read doc at https://help.aliyun.com/document_detail/35226.html?spm=5176.doc35226.6.671.625Omh
func (client *Client) CreateRules(args *CreateRulesArgs) error {
response := CreateRulesResponse{}
err := client.Invoke("CreateRules", args, &response)
if err != nil {
return err
}
return err
}
type DeleteRulesArgs struct {
RegionId common.Region
RuleIds string
}
type DeleteRulesResponse struct {
common.Response
}
// Delete forward rules
//
// You can read doc at https://help.aliyun.com/document_detail/35227.html?spm=5176.doc35226.6.672.6iNBtR
func (client *Client) DeleteRules(args *DeleteRulesArgs) error {
response := DeleteRulesResponse{}
err := client.Invoke("DeleteRules", args, &response)
if err != nil {
return err
}
return err
}
type SetRuleArgs struct {
RegionId common.Region
RuleId string
VServerGroupId string
}
type SetRuleResponse struct {
common.Response
}
// Modify forward rules
//
// You can read doc at https://help.aliyun.com/document_detail/35228.html?spm=5176.doc35227.6.673.rq40a9
func (client *Client) SetRule(args *SetRuleArgs) error {
response := SetRuleResponse{}
err := client.Invoke("SetRule", args, &response)
if err != nil {
return err
}
return err
}
type DescribeRuleAttributeArgs struct {
RegionId common.Region
RuleId string
}
type DescribeRuleAttributeResponse struct {
common.Response
LoadBalancerId string
ListenerPort int
Rule
}
// Describe rule
//
// You can read doc at https://help.aliyun.com/document_detail/35229.html?spm=5176.doc35226.6.674.DRJeKJ
func (client *Client) DescribeRuleAttribute(args *DescribeRuleAttributeArgs) (*DescribeRuleAttributeResponse, error) {
response := &DescribeRuleAttributeResponse{}
err := client.Invoke("DescribeRuleAttribute", args, response)
if err != nil {
return nil, err
}
return response, nil
}
type DescribeRulesArgs struct {
RegionId common.Region
LoadBalancerId string
ListenerPort int
}
type DescribeRulesResponse struct {
common.Response
Rules struct {
Rule []Rule
}
}
// Describe rule
//
// You can read doc at https://help.aliyun.com/document_detail/35229.html?spm=5176.doc35226.6.674.DRJeKJ
func (client *Client) DescribeRules(args *DescribeRulesArgs) (*DescribeRulesResponse, error) {
response := &DescribeRulesResponse{}
err := client.Invoke("DescribeRules", args, response)
if err != nil {
return nil, err
}
return response, nil
}

120
vendor/github.com/denverdino/aliyungo/slb/servers.go generated vendored Normal file
View File

@ -0,0 +1,120 @@
package slb
import (
"encoding/json"
"github.com/denverdino/aliyungo/common"
)
type AddBackendServersArgs struct {
LoadBalancerId string
BackendServers string
}
type SetBackendServersArgs AddBackendServersArgs
type AddBackendServersResponse struct {
common.Response
LoadBalancerId string
BackendServers struct {
BackendServer []BackendServerType
}
}
type SetBackendServersResponse AddBackendServersResponse
// SetBackendServers set weight of backend servers
func (client *Client) SetBackendServers(loadBalancerId string, backendServers []BackendServerType) (result []BackendServerType, err error) {
bytes, _ := json.Marshal(backendServers)
args := &SetBackendServersArgs{
LoadBalancerId: loadBalancerId,
BackendServers: string(bytes),
}
response := &SetBackendServersResponse{}
err = client.Invoke("SetBackendServers", args, response)
if err != nil {
return nil, err
}
return response.BackendServers.BackendServer, err
}
// AddBackendServers Add backend servers
//
// You can read doc at http://docs.aliyun.com/#/pub/slb/api-reference/api-related-backendserver&AddBackendServers
func (client *Client) AddBackendServers(loadBalancerId string, backendServers []BackendServerType) (result []BackendServerType, err error) {
bytes, _ := json.Marshal(backendServers)
args := &AddBackendServersArgs{
LoadBalancerId: loadBalancerId,
BackendServers: string(bytes),
}
response := &AddBackendServersResponse{}
err = client.Invoke("AddBackendServers", args, response)
if err != nil {
return nil, err
}
return response.BackendServers.BackendServer, err
}
type RemoveBackendServersArgs struct {
LoadBalancerId string
BackendServers []string
}
type RemoveBackendServersResponse struct {
common.Response
LoadBalancerId string
BackendServers struct {
BackendServer []BackendServerType
}
}
// RemoveBackendServers Remove backend servers
//
// You can read doc at http://docs.aliyun.com/#/pub/slb/api-reference/api-related-backendserver&RemoveBackendServers
func (client *Client) RemoveBackendServers(loadBalancerId string, backendServers []string) (result []BackendServerType, err error) {
args := &RemoveBackendServersArgs{
LoadBalancerId: loadBalancerId,
BackendServers: backendServers,
}
response := &RemoveBackendServersResponse{}
err = client.Invoke("RemoveBackendServers", args, response)
if err != nil {
return nil, err
}
return response.BackendServers.BackendServer, err
}
type HealthStatusType struct {
ServerId string
ServerHealthStatus string
}
type DescribeHealthStatusArgs struct {
LoadBalancerId string
ListenerPort int
}
type DescribeHealthStatusResponse struct {
common.Response
BackendServers struct {
BackendServer []HealthStatusType
}
}
// DescribeHealthStatus Describe health status
//
// You can read doc at http://docs.aliyun.com/#/pub/slb/api-reference/api-related-backendserver&DescribeHealthStatus
func (client *Client) DescribeHealthStatus(args *DescribeHealthStatusArgs) (response *DescribeHealthStatusResponse, err error) {
response = &DescribeHealthStatusResponse{}
err = client.Invoke("DescribeHealthStatus", args, response)
if err != nil {
return nil, err
}
return response, err
}

85
vendor/github.com/denverdino/aliyungo/slb/tags.go generated vendored Normal file
View File

@ -0,0 +1,85 @@
package slb
import "github.com/denverdino/aliyungo/common"
type TagItem struct {
TagKey string
TagValue string
}
type AddTagsArgs struct {
RegionId common.Region
LoadBalancerID string
Tags string
}
type AddTagsResponse struct {
common.Response
}
// AddTags Add tags to resource
//
// You can read doc at https://help.aliyun.com/document_detail/42871.html
func (client *Client) AddTags(args *AddTagsArgs) error {
response := AddTagsResponse{}
err := client.Invoke("AddTags", args, &response)
if err != nil {
return err
}
return err
}
type RemoveTagsArgs struct {
RegionId common.Region
LoadBalancerID string
Tags string
}
type RemoveTagsResponse struct {
common.Response
}
// RemoveTags remove tags to resource
//
// You can read doc at https://help.aliyun.com/document_detail/42872.html
func (client *Client) RemoveTags(args *RemoveTagsArgs) error {
response := RemoveTagsResponse{}
err := client.Invoke("RemoveTags", args, &response)
if err != nil {
return err
}
return err
}
type TagItemType struct {
TagItem
InstanceCount int
}
type DescribeTagsArgs struct {
RegionId common.Region
LoadBalancerID string
Tags string
common.Pagination
}
type DescribeTagsResponse struct {
common.Response
common.PaginationResult
TagSets struct {
TagSet []TagItemType
}
}
// DescribeResourceByTags describe resource by tags
//
// You can read doc at https://help.aliyun.com/document_detail/42873.html?spm=5176.doc42872.6.267.CP1iWu
func (client *Client) DescribeTags(args *DescribeTagsArgs) (tags []TagItemType, pagination *common.PaginationResult, err error) {
args.Validate()
response := DescribeTagsResponse{}
err = client.Invoke("DescribeTags", args, &response)
if err != nil {
return nil, nil, err
}
return response.TagSets.TagSet, &response.PaginationResult, nil
}

View File

@ -0,0 +1,158 @@
package slb
import (
"github.com/denverdino/aliyungo/common"
)
type VBackendServerType struct {
ServerId string
Weight int
Port int
}
type VServerGroup struct {
VServerGroupName string
VServerGroupId string
}
type VBackendServers struct {
BackendServer []VBackendServerType
}
type CreateVServerGroupArgs struct {
LoadBalancerId string
RegionId common.Region
VServerGroupName string
VServerGroupId string
BackendServers string
}
type SetVServerGroupAttributeArgs struct {
LoadBalancerId string
RegionId common.Region
VServerGroupName string
VServerGroupId string
BackendServers string
}
type AddVServerGroupBackendServersArgs CreateVServerGroupArgs
type RemoveVServerGroupBackendServersArgs CreateVServerGroupArgs
type ModifyVServerGroupBackendServersArgs struct {
VServerGroupId string
RegionId common.Region
OldBackendServers string
NewBackendServers string
}
type DeleteVServerGroupArgs struct {
VServerGroupId string
RegionId common.Region
}
type DescribeVServerGroupsArgs struct {
LoadBalancerId string
RegionId common.Region
}
type DescribeVServerGroupAttributeArgs struct {
VServerGroupId string
RegionId common.Region
}
type CreateVServerGroupResponse struct {
common.Response
VServerGroupId string
VServerGroupName string
BackendServers VBackendServers
}
type SetVServerGroupAttributeResponse struct {
common.Response
VServerGroupId string
VServerGroupName string
BackendServers VBackendServers
}
type AddVServerGroupBackendServersResponse CreateVServerGroupResponse
type RemoveVServerGroupBackendServersResponse CreateVServerGroupResponse
type ModifyVServerGroupBackendServersResponse CreateVServerGroupResponse
type DeleteVServerGroupResponse struct{ common.Response }
type DescribeVServerGroupsResponse struct {
common.Response
VServerGroups struct {
VServerGroup []VServerGroup
}
}
type DescribeVServerGroupAttributeResponse CreateVServerGroupResponse
func (client *Client) CreateVServerGroup(args *CreateVServerGroupArgs) (response *CreateVServerGroupResponse, err error) {
response = &CreateVServerGroupResponse{}
err = client.Invoke("CreateVServerGroup", args, response)
if err != nil {
return nil, err
}
return response, err
}
func (client *Client) SetVServerGroupAttribute(args *SetVServerGroupAttributeArgs) (response *SetVServerGroupAttributeResponse, err error) {
response = &SetVServerGroupAttributeResponse{}
err = client.Invoke("SetVServerGroupAttribute", args, response)
if err != nil {
return nil, err
}
return response, err
}
func (client *Client) AddVServerGroupBackendServers(args *AddVServerGroupBackendServersArgs) (response *AddVServerGroupBackendServersResponse, err error) {
response = &AddVServerGroupBackendServersResponse{}
err = client.Invoke("AddVServerGroupBackendServers", args, response)
if err != nil {
return nil, err
}
return response, err
}
func (client *Client) RemoveVServerGroupBackendServers(args *RemoveVServerGroupBackendServersArgs) (response *RemoveVServerGroupBackendServersResponse, err error) {
response = &RemoveVServerGroupBackendServersResponse{}
err = client.Invoke("RemoveVServerGroupBackendServers", args, response)
if err != nil {
return nil, err
}
return response, err
}
func (client *Client) ModifyVServerGroupBackendServers(args *ModifyVServerGroupBackendServersArgs) (response *ModifyVServerGroupBackendServersResponse, err error) {
response = &ModifyVServerGroupBackendServersResponse{}
err = client.Invoke("ModifyVServerGroupBackendServers", args, response)
if err != nil {
return nil, err
}
return response, err
}
func (client *Client) DeleteVServerGroup(args *DeleteVServerGroupArgs) (response *DeleteVServerGroupResponse, err error) {
response = &DeleteVServerGroupResponse{}
err = client.Invoke("DeleteVServerGroup", args, response)
if err != nil {
return nil, err
}
return response, err
}
func (client *Client) DescribeVServerGroups(args *DescribeVServerGroupsArgs) (response *DescribeVServerGroupsResponse, err error) {
response = &DescribeVServerGroupsResponse{}
err = client.Invoke("DescribeVServerGroups", args, response)
if err != nil {
return nil, err
}
return response, err
}
func (client *Client) DescribeVServerGroupAttribute(args *DescribeVServerGroupAttributeArgs) (response *DescribeVServerGroupAttributeResponse, err error) {
response = &DescribeVServerGroupAttributeResponse{}
err = client.Invoke("DescribeVServerGroupAttribute", args, response)
if err != nil {
return nil, err
}
return response, err
}