-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] api list all servers by secgroup ID api
- Loading branch information
1 parent
164a1f6
commit 6a02004
Showing
7 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,3 +78,7 @@ type ( | |
Uuid string | ||
} | ||
) | ||
|
||
type ListServers struct { | ||
Items []*Server | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package v2 | ||
|
||
import ( | ||
lsclient "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/client" | ||
lsentity "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/entity" | ||
lserr "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/sdk_error" | ||
) | ||
|
||
func (s *NetworkServiceV2) ListAllServersBySecgroupId(popts IListAllServersBySubnetIdRequest) (*lsentity.ListServers, lserr.IError) { | ||
url := listAllServersBySecgroupIdUrl(s.VserverClient, popts) | ||
resp := new(ListAllServersBySecgroupIdResponse) | ||
errResp := lserr.NewErrorResponse(lserr.NormalErrorType) | ||
req := lsclient.NewRequest(). | ||
WithOkCodes(200). | ||
WithJsonResponse(resp). | ||
WithJsonError(errResp) | ||
|
||
if _, sdkErr := s.VserverClient.Get(url, req); sdkErr != nil { | ||
return nil, lserr.SdkErrorHandler(sdkErr, errResp, | ||
lserr.WithErrorSecgroupNotFound(errResp)). | ||
WithKVparameters( | ||
"secgroupId", popts.GetSecgroupId(), | ||
"projectId", s.getProjectId()) | ||
} | ||
|
||
return resp.ToEntityListServers(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package v2 | ||
|
||
import lsentity "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/entity" | ||
|
||
type ListAllServersBySecgroupIdResponse struct { | ||
Data []struct { | ||
Name string `json:"name"` | ||
UUID string `json:"uuid"` | ||
Status string `json:"status"` | ||
} `json:"data"` | ||
} | ||
|
||
func (s *ListAllServersBySecgroupIdResponse) ToEntityListServers() *lsentity.ListServers { | ||
servers := make([]*lsentity.Server, 0) | ||
for _, server := range s.Data { | ||
servers = append(servers, &lsentity.Server{ | ||
Name: server.Name, | ||
Uuid: server.UUID, | ||
Status: server.Status, | ||
}) | ||
} | ||
return &lsentity.ListServers{ | ||
Items: servers, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters