Skip to content

Commit

Permalink
adding instances to create call
Browse files Browse the repository at this point in the history
  • Loading branch information
ddymko committed Apr 29, 2020
1 parent df4e131 commit d3e2245
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 18 additions & 2 deletions load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type LoadBalancerService interface {
HasSSL(ctx context.Context, ID int) (*struct {
SSLInfo bool `json:"has_ssl"`
}, error)
Create(ctx context.Context, region int, label string, genericInfo *GenericInfo, healthCheck *HealthCheck, rules []ForwardingRule, ssl *SSL) (*LoadBalancers, error)
Create(ctx context.Context, region int, label string, genericInfo *GenericInfo, healthCheck *HealthCheck, rules []ForwardingRule, ssl *SSL, instances *InstanceList) (*LoadBalancers, error)
UpdateGenericInfo(ctx context.Context, ID int, label string, genericInfo *GenericInfo) error
AddSSL(ctx context.Context, ID int, ssl *SSL) error
RemoveSSL(ctx context.Context, ID int) error
Expand Down Expand Up @@ -456,7 +456,7 @@ func (l *LoadBalancerHandler) HasSSL(ctx context.Context, ID int) (*struct {
}

// Create a load balancer
func (l *LoadBalancerHandler) Create(ctx context.Context, region int, label string, genericInfo *GenericInfo, healthCheck *HealthCheck, rules []ForwardingRule, ssl *SSL) (*LoadBalancers, error) {
func (l *LoadBalancerHandler) Create(ctx context.Context, region int, label string, genericInfo *GenericInfo, healthCheck *HealthCheck, rules []ForwardingRule, ssl *SSL, instances *InstanceList) (*LoadBalancers, error) {
uri := "/v1/loadbalancer/create"

values := url.Values{
Expand All @@ -483,6 +483,14 @@ func (l *LoadBalancerHandler) Create(ctx context.Context, region int, label stri
values.Add("cookie_name", genericInfo.StickySessions.CookieName)
}
}

if genericInfo.ProxyProtocol != nil {
value := "off"
if strconv.FormatBool(*genericInfo.ProxyProtocol) == "true" {
value = "on"
}
values.Add("proxy_protocol", value)
}
}

if healthCheck != nil {
Expand All @@ -507,6 +515,14 @@ func (l *LoadBalancerHandler) Create(ctx context.Context, region int, label stri
}
}

if instances != nil {
t, e := json.Marshal(instances.InstanceList)
if e != nil {
panic(e)
}
values.Add("attached_nodes", string(t))
}

req, err := l.client.NewRequest(ctx, http.MethodPost, uri, values)
if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion load_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,11 @@ func TestLoadBalancerHandler_Create(t *testing.T) {
})

redirect := true
proxy := true
info := GenericInfo{
BalancingAlgorithm: "roundrobin",
SSLRedirect: &redirect,
ProxyProtocol: &proxy,
StickySessions: &StickySessions{
StickySessionsEnabled: "on",
CookieName: "cookie",
Expand Down Expand Up @@ -394,7 +396,9 @@ func TestLoadBalancerHandler_Create(t *testing.T) {
Chain: "chain",
}

lb, err := client.LoadBalancer.Create(ctx, 1, "label", &info, &health, rules, &ssl)
instances := InstanceList{[]int{1234}}

lb, err := client.LoadBalancer.Create(ctx, 1, "label", &info, &health, rules, &ssl, &instances)
if err != nil {
t.Errorf("LoadBalancer.Create returned %+v", err)
}
Expand Down

0 comments on commit d3e2245

Please # to comment.