Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 update pool #87

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 154 additions & 1 deletion test/lb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,42 @@ func TestCreateInterVPCLoadBalancerWithPoolAndListenerSuccess(t *ltesting.T) {
t.Log("PASS")
}

func TestResizeLoadBalancerSuccess(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := lslbv2.NewResizeLoadBalancerRequest("lb-4d1508f9-8bb0-45a6-b55b-21a7412b4658", "").WithPackageId("lbp-71cc3022-5fee-426d-9509-3341053e2477")

lb, sdkerr := vngcloud.VLBGateway().V2().LoadBalancerService().ResizeLoadBalancer(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %+v", sdkerr)
}

if lb == nil {
t.Fatalf("Expect not nil but got nil")
}

t.Log("Result: ", lb)
t.Log("PASS")
}

func TestListLoadBalancerPackagesSuccess(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := lslbv2.NewListLoadBalancerPackagesRequest()
packages, sdkerr := vngcloud.VLBGateway().V2().LoadBalancerService().ListLoadBalancerPackages(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %+v", sdkerr)
}

if packages == nil {
t.Fatalf("Expect not nil but got nil")
}

t.Log("Result: ", packages)
for _, pkg := range packages.Items {
t.Logf("Package: %+v", pkg)
}
t.Log("PASS")
}

func TestGetLoadBalancerSuccess(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := lslbv2.NewGetLoadBalancerByIdRequest("lb-10689014-4c30-415c-96f7-2293b137854f").
Expand Down Expand Up @@ -409,7 +445,7 @@ func TestListListenersByLoadBalancerId(t *ltesting.T) {

func TestListPoolsByLoadBalancerId(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := lslbv2.NewListPoolsByLoadBalancerIdRequest("lb-8bd4ea07-ab40-483d-8387-124ed2f2cecb")
opt := lslbv2.NewListPoolsByLoadBalancerIdRequest("lb-4cc1add7-677f-4130-b71a-206940dad28e")
pools, sdkerr := vngcloud.VLBGateway().V2().LoadBalancerService().ListPoolsByLoadBalancerId(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %+v", sdkerr)
Expand All @@ -420,6 +456,9 @@ func TestListPoolsByLoadBalancerId(t *ltesting.T) {
}

t.Log("Result: ", pools)
for _, pool := range pools.Items {
t.Logf("Pool: %+v", pool)
}
t.Log("PASS")
}

Expand Down Expand Up @@ -546,3 +585,117 @@ func TestUpdatePoolSuccess(t *ltesting.T) {
t.Log("Result: ", sdkerr)
t.Log("PASS")
}

func TestGetPoolHealthMonitorSuccess(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := lslbv2.NewGetPoolHealthMonitorByIdRequest("lb-d5501a8c-d40e-4e3d-b86a-3e4041c629f7", "pool-1c5dfb52-922a-4dac-9dc0-970980637199")
hm, sdkerr := vngcloud.VLBGateway().V2().LoadBalancerService().GetPoolHealthMonitorById(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %+v", sdkerr)
}

if hm == nil {
t.Fatalf("Expect not nil but got nil")
}

t.Log("Result: ", hm)
t.Log("PASS")
}

func TestListPoliciesSuccess(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := lslbv2.NewListPoliciesRequest("lb-eb9f558a-4724-4d0b-a197-60fd642236f4", "lis-b38a9abc-2979-444f-afce-da824e32ea75")
policies, sdkerr := vngcloud.VLBGateway().V2().LoadBalancerService().ListPolicies(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %+v", sdkerr)
}

if policies == nil {
t.Fatalf("Expect not nil but got nil")
}

t.Log("Result: ", policies)
for _, policy := range policies.Items {
t.Logf("Policy: %+v", policy)
}
t.Log("PASS")
}

func TestCreatePolicySuccess(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := lslbv2.NewCreatePolicyRequest("lb-eb9f558a-4724-4d0b-a197-60fd642236f4", "lis-b38a9abc-2979-444f-afce-da824e32ea75").
WithName("test-policy-1").
WithAction(lslbv2.PolicyActionREJECT).
// WithRedirectPoolId("pool-1c5dfb52-922a-4dac-9dc0-970980637199").
// WithRedirectURL("https://vngcloud.vn").
// WithRedirectHTTPCode(301).
// WithKeepQueryString(true).
WithRules(lslbv2.L7RuleRequest{
CompareType: lslbv2.PolicyCompareTypeCONTAINS,
RuleType: lslbv2.PolicyRuleTypeHOSTNAME,
RuleValue: "vngcloud.vn",
})

policy, sdkerr := vngcloud.VLBGateway().V2().LoadBalancerService().CreatePolicy(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %+v", sdkerr)
}

if policy == nil {
t.Fatalf("Expect not nil but got nil")
}

t.Log("Result: ", policy)
t.Log("PASS")
}

func TestGetPolicyByIdSuccess(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := lslbv2.NewGetPolicyByIdRequest("lb-eb9f558a-4724-4d0b-a197-60fd642236f4", "lis-b38a9abc-2979-444f-afce-da824e32ea75", "policy-dea6106b-dd41-4fc1-bddc-61acc034787b")
policy, sdkerr := vngcloud.VLBGateway().V2().LoadBalancerService().GetPolicyById(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %+v", sdkerr)
}

if policy == nil {
t.Fatalf("Expect not nil but got nil")
}

t.Log("Result: ", policy)
t.Log("PASS")
}

func TestUpdatePolicySuccess(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := lslbv2.NewUpdatePolicyRequest("lb-eb9f558a-4724-4d0b-a197-60fd642236f4", "lis-b38a9abc-2979-444f-afce-da824e32ea75", "policy-dea6106b-dd41-4fc1-bddc-61acc034787b").
WithAction(lslbv2.PolicyActionREDIRECTTOURL).
// WithRedirectPoolId("pool-1c5dfb52-922a-4dac-9dc0-970980637199").
WithRedirectURL("https://vngcloud.vn").
WithRedirectHTTPCode(301).
WithKeepQueryString(true).
WithRules(lslbv2.L7RuleRequest{
CompareType: lslbv2.PolicyCompareTypeCONTAINS,
RuleType: lslbv2.PolicyRuleTypeHOSTNAME,
RuleValue: "vngcloud.com.vn",
})

sdkerr := vngcloud.VLBGateway().V2().LoadBalancerService().UpdatePolicy(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %+v", sdkerr)
}

t.Log("Result: ", sdkerr)
t.Log("PASS")
}

func TestDeletePolicySuccess(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := lslbv2.NewDeletePolicyByIdRequest("lb-eb9f558a-4724-4d0b-a197-60fd642236f4", "lis-b38a9abc-2979-444f-afce-da824e32ea75", "policy-5cf4bacb-93b6-4078-bbf7-cb5d0d701828")
sdkerr := vngcloud.VLBGateway().V2().LoadBalancerService().DeletePolicyById(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %+v", sdkerr)
}

t.Log("Result: ", sdkerr)
t.Log("PASS")
}
23 changes: 23 additions & 0 deletions test/secgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,26 @@ func TestListAllServerBySecgroupIdSuccess(t *ltesting.T) {
t.Log("RESULT:", serbvers)
t.Log("PASS")
}

func TestListSecgroupSuccess(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := lsnetworkSvcV2.NewListSecgroupRequest()
secgroups, err := vngcloud.VServerGateway().V2().NetworkService().ListSecgroup(opt)

if err != nil {
t.Errorf("Expect error to be nil but got %+v", err)
}

if secgroups == nil {
t.Errorf("Expect portal not to be nil but got nil")
}

t.Log("RESULT:", secgroups)
if secgroups == nil || len(secgroups.Items) == 0 {
t.Log("No secgroup found")
}
for _, secgroup := range secgroups.Items {
t.Logf("Secgroup: %+v", secgroup)
}
t.Log("PASS")
}
15 changes: 15 additions & 0 deletions vngcloud/entity/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,18 @@ func (s *ListLoadBalancers) At(pidx int) *LoadBalancer {

return s.Items[pidx]
}

type ListLoadBalancerPackages struct {
Items []*LoadBalancerPackage
}

type LoadBalancerPackage struct {
UUID string
Name string
Type string
ConnectionNumber int
DataTransfer int
Mode string
LbType string
DisplayLbType string
}
32 changes: 32 additions & 0 deletions vngcloud/entity/policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package entity

type Policy struct {
UUID string
Name string
Description string
RedirectPoolID string
RedirectPoolName string
Action string
RedirectURL string
RedirectHTTPCode int
KeepQueryString bool
Position int
L7Rules []*L7Rule
DisplayStatus string
CreatedAt string
UpdatedAt string
ProgressStatus string
}

type L7Rule struct {
UUID string
CompareType string
RuleValue string
RuleType string
ProvisioningStatus string
OperatingStatus string
}

type ListPolicies struct {
Items []*Policy
}
11 changes: 11 additions & 0 deletions vngcloud/entity/pool.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package entity

import "encoding/json"

type Pool struct {
UUID string
Name string
Expand Down Expand Up @@ -48,6 +50,15 @@ type HealthMonitor struct {
DisplayStatus string `json:"displayStatus"`
}

func (s *HealthMonitor) String() string {
// parse to string and return
out, err := json.Marshal(s)
if err != nil {
return "Error parsing to string"
}
return string(out)
}

type ListPools struct {
Items []*Pool
}
Expand Down
4 changes: 4 additions & 0 deletions vngcloud/entity/secgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ type Secgroup struct {
Description string
Status string
}

type ListSecgroups struct {
Items []*Secgroup
}
8 changes: 8 additions & 0 deletions vngcloud/services/common/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ type PoolCommon struct {
func (s *PoolCommon) GetPoolId() string {
return s.PoolId
}

type PolicyCommon struct {
PolicyId string
}

func (s *PolicyCommon) GetPolicyId() string {
return s.PolicyId
}
9 changes: 9 additions & 0 deletions vngcloud/services/loadbalancer/iloadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import (

type ILoadBalancerServiceV2 interface {
CreateLoadBalancer(popts lslbSvcV2.ICreateLoadBalancerRequest) (*lsentity.LoadBalancer, lserr.IError)
ResizeLoadBalancer(popts lslbSvcV2.IResizeLoadBalancerRequest) (*lsentity.LoadBalancer, lserr.IError)
ListLoadBalancerPackages(popts lslbSvcV2.IListLoadBalancerPackagesRequest) (*lsentity.ListLoadBalancerPackages, lserr.IError)
GetLoadBalancerById(popts lslbSvcV2.IGetLoadBalancerByIdRequest) (*lsentity.LoadBalancer, lserr.IError)
ListLoadBalancers(popts lslbSvcV2.IListLoadBalancersRequest) (*lsentity.ListLoadBalancers, lserr.IError)
GetPoolHealthMonitorById(popts lslbSvcV2.IGetPoolHealthMonitorByIdRequest) (*lsentity.HealthMonitor, lserr.IError)
CreatePool(popts lslbSvcV2.ICreatePoolRequest) (*lsentity.Pool, lserr.IError)
UpdatePool(popts lslbSvcV2.IUpdatePoolRequest) lserr.IError
CreateListener(popts lslbSvcV2.ICreateListenerRequest) (*lsentity.Listener, lserr.IError)
Expand All @@ -25,6 +28,12 @@ type ILoadBalancerServiceV2 interface {
ListTags(popts lslbSvcV2.IListTagsRequest) (*lsentity.ListTags, lserr.IError)
CreateTags(popts lslbSvcV2.ICreateTagsRequest) lserr.IError
UpdateTags(popts lslbSvcV2.IUpdateTagsRequest) lserr.IError

ListPolicies(popts lslbSvcV2.IListPoliciesRequest) (*lsentity.ListPolicies, lserr.IError)
CreatePolicy(popts lslbSvcV2.ICreatePolicyRequest) (*lsentity.Policy, lserr.IError)
GetPolicyById(popts lslbSvcV2.IGetPolicyByIdRequest) (*lsentity.Policy, lserr.IError)
UpdatePolicy(popts lslbSvcV2.IUpdatePolicyRequest) lserr.IError
DeletePolicyById(popts lslbSvcV2.IDeletePolicyByIdRequest) lserr.IError
}

type ILoadBalancerServiceInternal interface {
Expand Down
Loading
Loading