-
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] vserver gateway v2 - api get subnet
- Loading branch information
1 parent
d66a099
commit 3a26eb3
Showing
14 changed files
with
173 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package test | ||
|
||
import ( | ||
lsnetworkSvcV2 "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/network/v2" | ||
ltesting "testing" | ||
) | ||
|
||
func TestGetSubnetByIdSuccess(t *ltesting.T) { | ||
vngcloud := validSdkConfig() | ||
opt := lsnetworkSvcV2.NewGetSubnetByIdRequest("net-4f35f173-e0fe-4202-9c2b-5121b558bcd3", "sub-27a0562d-07f9-4e87-81fd-e0ba9658f156") | ||
network, err := vngcloud.VServerGateway().V2().NetworkService().GetSubnetById(opt) | ||
|
||
if err != nil { | ||
t.Fatalf("Expect error to be nil but got %+v", err) | ||
} | ||
|
||
if network == nil { | ||
t.Fatalf("Expect portal not to be nil but got nil") | ||
} | ||
|
||
t.Log("RESULT:", network) | ||
t.Log("PASS") | ||
} |
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,12 @@ | ||
package entity | ||
|
||
type Subnet struct { | ||
Id string | ||
NetworkId string | ||
Name string | ||
Status string | ||
Cidr string | ||
RouteTableId string | ||
InterfaceAclPolicyId string | ||
InterfaceAclPolicyName string | ||
} |
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,9 @@ | ||
package common | ||
|
||
type NetworkCommon struct { | ||
NetworkId string | ||
} | ||
|
||
func (s *NetworkCommon) GetNetworkId() string { | ||
return s.NetworkId | ||
} |
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,9 @@ | ||
package common | ||
|
||
type SubnetCommon struct { | ||
SubnetId string | ||
} | ||
|
||
func (s *SubnetCommon) GetSubnetId() string { | ||
return s.SubnetId | ||
} |
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
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package v2 | ||
|
||
import lscommon "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/common" | ||
|
||
func NewGetNetworkByIdRequest(pnetworkId string) IGetNetworkByIdRequest { | ||
opt := new(GetNetworkByIdRequest) | ||
opt.NetworkId = pnetworkId | ||
return opt | ||
} | ||
|
||
type GetNetworkByIdRequest struct { | ||
NetworkCommon | ||
lscommon.NetworkCommon | ||
} |
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,29 @@ | ||
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) GetSubnetById(popts IGetSubnetByIdRequest) (*lsentity.Subnet, lserr.ISdkError) { | ||
url := getSubnetByIdUrl(s.VserverClient, popts) | ||
resp := new(GetSubnetByIdResponse) | ||
errResp := lserr.NewErrorResponse(lserr.NormalErrorType) | ||
req := lsclient.NewRequest(). | ||
WithHeader("User-Agent", popts.ParseUserAgent()). | ||
WithOkCodes(200). | ||
WithJsonResponse(resp). | ||
WithJsonError(errResp) | ||
|
||
if _, sdkErr := s.VserverClient.Get(url, req); sdkErr != nil { | ||
return nil, lserr.SdkErrorHandler(sdkErr, errResp, | ||
lserr.WithErrorSubnetNotBelongNetwork(sdkErr), | ||
lserr.WithErrorSubnetNotFound(errResp)). | ||
WithKVparameters( | ||
"subnetId", popts.GetSubnetId(), | ||
"projectId", s.getProjectId()) | ||
} | ||
|
||
return resp.ToEntitySubnet(), 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,16 @@ | ||
package v2 | ||
|
||
import lscommon "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/common" | ||
|
||
func NewGetSubnetByIdRequest(pnetworkId, psubnetId string) IGetSubnetByIdRequest { | ||
opt := new(GetSubnetByIdRequest) | ||
opt.NetworkId = pnetworkId | ||
opt.SubnetId = psubnetId | ||
return opt | ||
} | ||
|
||
type GetSubnetByIdRequest struct { | ||
lscommon.UserAgent | ||
lscommon.SubnetCommon | ||
lscommon.NetworkCommon | ||
} |
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,29 @@ | ||
package v2 | ||
|
||
import lsentity "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/entity" | ||
|
||
type GetSubnetByIdResponse struct { | ||
UUID string `json:"uuid"` | ||
CreatedAt string `json:"createdAt"` | ||
UpdatedAt string `json:"updatedAt,omitempty"` | ||
Status string `json:"status"` | ||
Cidr string `json:"cidr"` | ||
NetworkUuid string `json:"networkUuid"` | ||
RouteTableUuid string `json:"routeTableUuid,omitempty"` | ||
Name string `json:"name"` | ||
InterfaceAclPolicyUuid string `json:"interfaceAclPolicyUuid,omitempty"` | ||
InterfaceAclPolicyName string `json:"interfaceAclPolicyName,omitempty"` | ||
} | ||
|
||
func (s *GetSubnetByIdResponse) ToEntitySubnet() *lsentity.Subnet { | ||
return &lsentity.Subnet{ | ||
Id: s.UUID, | ||
NetworkId: s.NetworkUuid, | ||
Name: s.Name, | ||
Status: s.Status, | ||
Cidr: s.Cidr, | ||
RouteTableId: s.RouteTableUuid, | ||
InterfaceAclPolicyId: s.InterfaceAclPolicyUuid, | ||
InterfaceAclPolicyName: s.InterfaceAclPolicyName, | ||
} | ||
} |
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