Skip to content

Commit

Permalink
[feat] list all servers by secgroup id
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Sep 11, 2024
1 parent 6a02004 commit 30b4bb1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
18 changes: 18 additions & 0 deletions test/secgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,21 @@ func TestDeleteSecgroupByIdSuccess(t *ltesting.T) {
t.Log("RESULT:", err)
t.Log("PASS")
}

func TestListAllServerBySecgroupIdSuccess(t *ltesting.T) {
secgroupId := "secg-1395e86c-9631-4c13-93b6-e41be5bdaab3"
vngcloud := validSdkConfig()
opt := lsnetworkSvcV2.NewListAllServersBySubnetIdRequest(secgroupId)
serbvers, err := vngcloud.VServerGateway().V2().NetworkService().ListAllServersBySecgroupId(opt)

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

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

t.Log("RESULT:", serbvers)
t.Log("PASS")
}
2 changes: 1 addition & 1 deletion vngcloud/services/network/inetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ type INetworkServiceV2 interface {
DeleteAddressPair(popts lsnetworkSvcV2.IDeleteAddressPairRequest) lserr.IError

// Servers
ListAllServersBySecgroupId(popts lsnetworkSvcV2.IListAllServersBySubnetIdRequest) (*lsentity.ListServers, lserr.IError)
ListAllServersBySecgroupId(popts lsnetworkSvcV2.IListAllServersBySecgroupIdRequest) (*lsentity.ListServers, lserr.IError)
}
2 changes: 1 addition & 1 deletion vngcloud/services/network/v2/irequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ type IDeleteAddressPairRequest interface {
GetAddressPairID() string
}

type IListAllServersBySubnetIdRequest interface {
type IListAllServersBySecgroupIdRequest interface {
GetSecgroupId() string
}
2 changes: 1 addition & 1 deletion vngcloud/services/network/v2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
lserr "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/sdk_error"
)

func (s *NetworkServiceV2) ListAllServersBySecgroupId(popts IListAllServersBySubnetIdRequest) (*lsentity.ListServers, lserr.IError) {
func (s *NetworkServiceV2) ListAllServersBySecgroupId(popts IListAllServersBySecgroupIdRequest) (*lsentity.ListServers, lserr.IError) {
url := listAllServersBySecgroupIdUrl(s.VserverClient, popts)
resp := new(ListAllServersBySecgroupIdResponse)
errResp := lserr.NewErrorResponse(lserr.NormalErrorType)
Expand Down
10 changes: 10 additions & 0 deletions vngcloud/services/network/v2/server_request.go
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
package v2

func NewListAllServersBySubnetIdRequest(psecgroupId string) IListAllServersBySecgroupIdRequest {
opt := new(ListAllServersBySecgroupIdRequest)
opt.SecgroupId = psecgroupId
return opt
}

type ListAllServersBySecgroupIdRequest struct {
SecgroupCommon
}
2 changes: 1 addition & 1 deletion vngcloud/services/network/v2/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func deleteAddressPairUrl(psc lsclient.IServiceClient, popts IDeleteAddressPairR
popts.GetAddressPairID())
}

func listAllServersBySecgroupIdUrl(psc lsclient.IServiceClient, popts IListAllServersBySubnetIdRequest) string {
func listAllServersBySecgroupIdUrl(psc lsclient.IServiceClient, popts IListAllServersBySecgroupIdRequest) string {
return psc.ServiceURL(
psc.GetProjectId(),
"secgroups",
Expand Down

0 comments on commit 30b4bb1

Please sign in to comment.