diff --git a/vngcloud/services/loadbalancer/inter/irequest.go b/vngcloud/services/loadbalancer/inter/irequest.go index e5ad7c6..5384a7c 100644 --- a/vngcloud/services/loadbalancer/inter/irequest.go +++ b/vngcloud/services/loadbalancer/inter/irequest.go @@ -9,6 +9,7 @@ type ICreateLoadBalancerRequest interface { WithTags(ptags ...string) ICreateLoadBalancerRequest GetMapHeaders() map[string]string ParseUserAgent() string + ToMap() map[string]interface{} } type ICreateListenerRequest interface { diff --git a/vngcloud/services/loadbalancer/inter/loadbalancer.go b/vngcloud/services/loadbalancer/inter/loadbalancer.go index 4b295cb..c2a1f7f 100644 --- a/vngcloud/services/loadbalancer/inter/loadbalancer.go +++ b/vngcloud/services/loadbalancer/inter/loadbalancer.go @@ -20,7 +20,9 @@ func (s *LoadBalancerServiceInternal) CreateLoadBalancer(popts ICreateLoadBalanc if _, sdkErr := s.VLBClient.Post(url, req); sdkErr != nil { return nil, lserr.SdkErrorHandler(sdkErr, errResp, - lserr.WithErrorLoadBalancerExceedQuota(errResp)) + lserr.WithErrorLoadBalancerExceedQuota(errResp)). + WithParameters(popts.ToMap()). + AppendCategories(lserr.ErrCatProductVlb) } return resp.ToEntityLoadBalancer(), nil diff --git a/vngcloud/services/loadbalancer/inter/loadbalancer_request.go b/vngcloud/services/loadbalancer/inter/loadbalancer_request.go index 17b9a35..8aadd53 100644 --- a/vngcloud/services/loadbalancer/inter/loadbalancer_request.go +++ b/vngcloud/services/loadbalancer/inter/loadbalancer_request.go @@ -18,18 +18,6 @@ type ( LoadBalancerType string ) -func NewCreateLoadBalancerRequest(puserId, pname, ppackageId, pbeSubnetId, psubnetId string) ICreateLoadBalancerRequest { - opt := new(CreateLoadBalancerRequest) - opt.SetPortalUserId(puserId) - opt.Name = pname - opt.PackageID = ppackageId - opt.Scheme = InterVpcLoadBalancerScheme - opt.BackEndSubnetId = pbeSubnetId - opt.SubnetID = psubnetId - opt.Type = CreateOptsTypeOptLayer4 - return opt -} - type CreateLoadBalancerRequest struct { Name string `json:"name"` PackageID string `json:"packageId"` @@ -46,6 +34,19 @@ type CreateLoadBalancerRequest struct { lscommon.UserAgent } +func (s *CreateLoadBalancerRequest) ToMap() map[string]interface{} { + return map[string]interface{}{ + "name": s.Name, + "packageId": s.PackageID, + "scheme": s.Scheme, + "subnetId": s.SubnetID, + "backendSubnetId": s.BackEndSubnetId, + "projectId": s.ProjectId, + "type": s.Type, + "tags": s.Tags, + } +} + func (s *CreateLoadBalancerRequest) ToRequestBody() interface{} { if s.Pool != nil { s.Pool = s.Pool.ToRequestBody().(*CreatePoolRequest) diff --git a/vngcloud/services/loadbalancer/inter/requests.go b/vngcloud/services/loadbalancer/inter/requests.go new file mode 100644 index 0000000..dfdc63c --- /dev/null +++ b/vngcloud/services/loadbalancer/inter/requests.go @@ -0,0 +1,13 @@ +package inter + +func NewCreateLoadBalancerRequest(puserId, pname, ppackageId, pbeSubnetId, psubnetId string) ICreateLoadBalancerRequest { + opt := new(CreateLoadBalancerRequest) + opt.SetPortalUserId(puserId) + opt.Name = pname + opt.PackageID = ppackageId + opt.Scheme = InterVpcLoadBalancerScheme + opt.BackEndSubnetId = pbeSubnetId + opt.SubnetID = psubnetId + opt.Type = CreateOptsTypeOptLayer4 + return opt +} diff --git a/vngcloud/services/loadbalancer/v2/irequest.go b/vngcloud/services/loadbalancer/v2/irequest.go index ac349c8..cc41c99 100644 --- a/vngcloud/services/loadbalancer/v2/irequest.go +++ b/vngcloud/services/loadbalancer/v2/irequest.go @@ -14,6 +14,7 @@ type ICreateLoadBalancerRequest interface { WithSubnetId(psubnetId string) ICreateLoadBalancerRequest WithType(ptype LoadBalancerType) ICreateLoadBalancerRequest ParseUserAgent() string + ToMap() map[string]interface{} } type IGetLoadBalancerByIdRequest interface { diff --git a/vngcloud/services/loadbalancer/v2/loadbalancer.go b/vngcloud/services/loadbalancer/v2/loadbalancer.go index 036a907..01e6cc6 100644 --- a/vngcloud/services/loadbalancer/v2/loadbalancer.go +++ b/vngcloud/services/loadbalancer/v2/loadbalancer.go @@ -20,6 +20,7 @@ func (s *LoadBalancerServiceV2) CreateLoadBalancer(popts ICreateLoadBalancerRequ if _, sdkErr := s.VLBClient.Post(url, req); sdkErr != nil { return nil, lserr.SdkErrorHandler(sdkErr, errResp, lserr.WithErrorLoadBalancerExceedQuota(errResp)). + WithParameters(popts.ToMap()). AppendCategories(lserr.ErrCatProductVlb) } diff --git a/vngcloud/services/loadbalancer/v2/loadbalancer_request.go b/vngcloud/services/loadbalancer/v2/loadbalancer_request.go index 8d6018a..6207447 100644 --- a/vngcloud/services/loadbalancer/v2/loadbalancer_request.go +++ b/vngcloud/services/loadbalancer/v2/loadbalancer_request.go @@ -23,33 +23,6 @@ type ( LoadBalancerType string ) -func NewCreateLoadBalancerRequest(pname string) ICreateLoadBalancerRequest { - return &CreateLoadBalancerRequest{ - Name: pname, - Scheme: InternetLoadBalancerScheme, - Type: LoadBalancerTypeLayer4, - } -} - -func NewGetLoadBalancerByIdRequest(plbId string) IGetLoadBalancerByIdRequest { - opts := new(GetLoadBalancerByIdRequest) - opts.LoadBalancerId = plbId - return opts -} - -func NewListLoadBalancersRequest(ppage, psize int) IListLoadBalancersRequest { - opts := new(ListLoadBalancersRequest) - opts.Page = ppage - opts.Size = psize - 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"` @@ -83,6 +56,20 @@ type DeleteLoadBalancerByIdRequest struct { lscommon.LoadBalancerCommon } +func (S *CreateLoadBalancerRequest) ToMap() map[string]interface{} { + return map[string]interface{}{ + "name": S.Name, + "packageId": S.PackageID, + "scheme": S.Scheme, + "autoScalable": S.AutoScalable, + "subnetId": S.SubnetID, + "type": S.Type, + "listener": S.Listener.ToMap(), + "pool": S.Pool.ToMap(), + "tags": S.Tags, + } +} + func (s *CreateLoadBalancerRequest) ToRequestBody() interface{} { if s.Pool != nil { s.Pool = s.Pool.ToRequestBody().(*CreatePoolRequest) diff --git a/vngcloud/services/loadbalancer/v2/requests.go b/vngcloud/services/loadbalancer/v2/requests.go new file mode 100644 index 0000000..40c9db2 --- /dev/null +++ b/vngcloud/services/loadbalancer/v2/requests.go @@ -0,0 +1,28 @@ +package v2 + +func NewCreateLoadBalancerRequest(pname string) ICreateLoadBalancerRequest { + return &CreateLoadBalancerRequest{ + Name: pname, + Scheme: InternetLoadBalancerScheme, + Type: LoadBalancerTypeLayer4, + } +} + +func NewGetLoadBalancerByIdRequest(plbId string) IGetLoadBalancerByIdRequest { + opts := new(GetLoadBalancerByIdRequest) + opts.LoadBalancerId = plbId + return opts +} + +func NewListLoadBalancersRequest(ppage, psize int) IListLoadBalancersRequest { + opts := new(ListLoadBalancersRequest) + opts.Page = ppage + opts.Size = psize + return opts +} + +func NewDeleteLoadBalancerByIdRequest(plbId string) IDeleteLoadBalancerByIdRequest { + opts := new(DeleteLoadBalancerByIdRequest) + opts.LoadBalancerId = plbId + return opts +}