Skip to content

Commit

Permalink
[feat] vlb gateway v2 - api delete loadbalancer
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Jun 18, 2024
1 parent 1d7c558 commit d66a099
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/lb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,15 @@ func TestDeleteListenterSuccess(t *ltesting.T) {
t.Log("Result: ", sdkerr)
t.Log("PASS")
}

func TestDeleteLoadBalancer(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := lslbv2.NewDeleteLoadBalancerByIdRequest("lb-f7adf4ba-7734-45f3-8cb5-9b0c3850cd6f")
sdkerr := vngcloud.VLBGateway().V2().LoadBalancerService().DeleteLoadBalancerById(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %+v", sdkerr)
}

t.Log("Result: ", sdkerr)
t.Log("PASS")
}
1 change: 1 addition & 0 deletions vngcloud/services/loadbalancer/iloadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ILoadBalancerServiceV2 interface {
ListPoolMembers(popts lslbSvcV2.IListPoolMembersRequest) (*lsentity.ListMembers, lserr.ISdkError)
DeletePoolById(popt lslbSvcV2.IDeletePoolByIdRequest) lserr.ISdkError
DeleteListenerById(popts lslbSvcV2.IDeleteListenerByIdRequest) lserr.ISdkError
DeleteLoadBalancerById(popts lslbSvcV2.IDeleteLoadBalancerByIdRequest) lserr.ISdkError
}

type ILoadBalancerServiceInternal interface {
Expand Down
5 changes: 5 additions & 0 deletions vngcloud/services/loadbalancer/v2/irequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ type IDeleteListenerByIdRequest interface {
ParseUserAgent() string
}

type IDeleteLoadBalancerByIdRequest interface {
GetLoadBalancerId() string
ParseUserAgent() string
}

type IHealthMonitorRequest interface {
ToRequestBody() interface{}
ToMap() map[string]interface{}
Expand Down
17 changes: 17 additions & 0 deletions vngcloud/services/loadbalancer/v2/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,20 @@ func (s *LoadBalancerServiceV2) DeleteListenerById(popts IDeleteListenerByIdRequ

return nil
}

func (s *LoadBalancerServiceV2) DeleteLoadBalancerById(popts IDeleteLoadBalancerByIdRequest) lserr.ISdkError {
url := deleteLoadBalancerByIdUrl(s.VLBClient, popts)
errResp := lserr.NewErrorResponse(lserr.NormalErrorType)
req := lsclient.NewRequest().
WithHeader("User-Agent", popts.ParseUserAgent()).
WithOkCodes(202).
WithJsonError(errResp)

if _, sdkErr := s.VLBClient.Delete(url, req); sdkErr != nil {
return lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorLoadBalancerNotFound(errResp),
lserr.WithErrorLoadBalancerNotReady(errResp))
}

return nil
}
11 changes: 11 additions & 0 deletions vngcloud/services/loadbalancer/v2/loadbalancer_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func NewListLoadBalancersRequest(ppage, psize int) IListLoadBalancersRequest {
return opts
}

func NewDeleteLoadBalancerByIdRequest(plbId string) IDeleteLoadBalancerByIdRequest {
opts := new(DeleteLoadBalancerByIdRequest)
opts.LoadBalancerId = plbId
return opts
}

type CreateLoadBalancerRequest struct {
Name string `json:"name"`
PackageID string `json:"packageId"`
Expand Down Expand Up @@ -73,6 +79,11 @@ type ListLoadBalancersRequest struct {
lscommon.UserAgent
}

type DeleteLoadBalancerByIdRequest struct {
lscommon.UserAgent
lscommon.LoadBalancerCommon
}

func (s *CreateLoadBalancerRequest) ToRequestBody() interface{} {
if s.Pool != nil {
s.Pool = s.Pool.ToRequestBody().(*CreatePoolRequest)
Expand Down
7 changes: 7 additions & 0 deletions vngcloud/services/loadbalancer/v2/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,10 @@ func deleteListenerByIdUrl(psc lsclient.IServiceClient, popts IDeleteListenerByI
"listeners",
popts.GetListenerId())
}

func deleteLoadBalancerByIdUrl(psc lsclient.IServiceClient, popts IDeleteLoadBalancerByIdRequest) string {
return psc.ServiceURL(
psc.GetProjectId(),
"loadBalancers",
popts.GetLoadBalancerId())
}

0 comments on commit d66a099

Please sign in to comment.