-
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.
Merge pull request #85 from vngcloud/v2-aap
V2 + Allow address pair
- Loading branch information
Showing
17 changed files
with
423 additions
and
1 deletion.
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,55 @@ | ||
package test | ||
|
||
import ( | ||
ltesting "testing" | ||
|
||
lsnetworkSvcV2 "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/network/v2" | ||
) | ||
|
||
func TestGetAllAddressPairByVirtualSubnetId(t *ltesting.T) { | ||
vngcloud := validSdkConfig() | ||
opt := lsnetworkSvcV2.NewGetAllAddressPairByVirtualSubnetIdRequest(getValueOfEnv("VIRTUAL_SUBNET_ID")) | ||
network, err := vngcloud.VServerGateway().V2().NetworkService().GetAllAddressPairByVirtualSubnetId(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) | ||
for _, addressPair := range network { | ||
t.Logf("AddressPair: %+v", addressPair) | ||
} | ||
t.Log("PASS") | ||
} | ||
|
||
func TestSetAddressPairInVirtualSubnet(t *ltesting.T) { | ||
vngcloud := validSdkConfig() | ||
opt := lsnetworkSvcV2.NewSetAddressPairInVirtualSubnetRequest(getValueOfEnv("VIRTUAL_SUBNET_ID"), getValueOfEnv("NETWORK_INTERFACE_ID"), "10.30.1.28/30") | ||
network, err := vngcloud.VServerGateway().V2().NetworkService().SetAddressPairInVirtualSubnet(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) | ||
} | ||
|
||
func TestDeleteAddressPair(t *ltesting.T) { | ||
vngcloud := validSdkConfig() | ||
opt := lsnetworkSvcV2.NewDeleteAddressPairRequest(getValueOfEnv("ADDRESS_PAIR_ID")) | ||
err := vngcloud.VServerGateway().V2().NetworkService().DeleteAddressPair(opt) | ||
|
||
if err != nil { | ||
t.Fatalf("Expect error to be nil but got %+v", err) | ||
} | ||
|
||
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
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
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,10 @@ | ||
package entity | ||
|
||
type AddressPair struct { | ||
Id string | ||
VirtualIpAddressId string | ||
VirtualSubnetId string | ||
NetworkInterfaceIp string | ||
NetworkInterfaceId string | ||
CIDR 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,60 @@ | ||
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) GetAllAddressPairByVirtualSubnetId(popts IGetAllAddressPairByVirtualSubnetIdRequest) ([]*lsentity.AddressPair, lserr.IError) { | ||
url := getAllAddressPairByVirtualSubnetIdUrl(s.VserverClient, popts) | ||
resp := new(GetAllAddressPairByVirtualSubnetIdResponse) | ||
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( | ||
// "virtualSubnetId", popts.GetVirtualSubnetId(), | ||
// "projectId", s.getProjectId(), | ||
|
||
} | ||
return resp.ToListAddressPair(), nil | ||
} | ||
|
||
func (s *NetworkServiceV2) SetAddressPairInVirtualSubnet(popts ISetAddressPairInVirtualSubnetRequest) (*lsentity.AddressPair, lserr.IError) { | ||
url := setAddressPairInVirtualSubnetUrl(s.VserverClient, popts) | ||
resp := new(SetAddressPairInVirtualSubnetResponse) | ||
errResp := lserr.NewErrorResponse(lserr.NormalErrorType) | ||
req := lsclient.NewRequest(). | ||
WithHeader("User-Agent", popts.ParseUserAgent()). | ||
WithOkCodes(200, 201, 202, 203, 204). | ||
WithJsonBody(popts.ToRequestBody()). | ||
WithJsonResponse(resp). | ||
WithJsonError(errResp) | ||
|
||
if _, sdkErr := s.VserverClient.Post(url, req); sdkErr != nil { | ||
return nil, lserr.SdkErrorHandler(sdkErr, errResp) | ||
} | ||
return resp.ToAddressPair(), nil | ||
} | ||
|
||
func (s *NetworkServiceV2) DeleteAddressPair(popts IDeleteAddressPairRequest) lserr.IError { | ||
url := deleteAddressPairUrl(s.VserverClient, popts) | ||
errResp := lserr.NewErrorResponse(lserr.NormalErrorType) | ||
req := lsclient.NewRequest(). | ||
WithHeader("User-Agent", popts.ParseUserAgent()). | ||
WithOkCodes(200, 201, 202, 203, 204). | ||
WithJsonError(errResp) | ||
|
||
if _, sdkErr := s.VserverClient.Delete(url, req); sdkErr != nil { | ||
return lserr.SdkErrorHandler(sdkErr, errResp) | ||
} | ||
return 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,68 @@ | ||
package v2 | ||
|
||
import lscommon "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/common" | ||
|
||
func NewGetAllAddressPairByVirtualSubnetIdRequest(psubnetId string) IGetAllAddressPairByVirtualSubnetIdRequest { | ||
opt := new(GetAllAddressPairByVirtualSubnetIdRequest) | ||
opt.VirtualSubnetId = psubnetId | ||
return opt | ||
} | ||
|
||
type GetAllAddressPairByVirtualSubnetIdRequest struct { | ||
lscommon.UserAgent | ||
VirtualSubnetId string | ||
} | ||
|
||
func (s *GetAllAddressPairByVirtualSubnetIdRequest) GetVirtualSubnetId() string { | ||
return s.VirtualSubnetId | ||
} | ||
|
||
// -------------------------------------------------------- | ||
|
||
func NewSetAddressPairInVirtualSubnetRequest(psubnetId, networkInterfaceID, CIDR string) ISetAddressPairInVirtualSubnetRequest { | ||
opt := new(SetAddressPairInVirtualSubnetRequest) | ||
opt.VirtualSubnetId = psubnetId | ||
opt.AddressPairRequest = AddressPairRequest{ | ||
CIDR: CIDR, | ||
InternalNetworkInterfaceId: networkInterfaceID, | ||
} | ||
return opt | ||
} | ||
|
||
type SetAddressPairInVirtualSubnetRequest struct { | ||
lscommon.UserAgent | ||
VirtualSubnetId string | ||
AddressPairRequest AddressPairRequest | ||
} | ||
|
||
func (s *SetAddressPairInVirtualSubnetRequest) GetVirtualSubnetId() string { | ||
return s.VirtualSubnetId | ||
} | ||
|
||
func (s *SetAddressPairInVirtualSubnetRequest) ToRequestBody() interface{} { | ||
return s.AddressPairRequest | ||
} | ||
|
||
type AddressPairRequest struct { | ||
CIDR string `json:"cidr"` | ||
InternalNetworkInterfaceId string `json:"internalNetworkInterfaceId"` | ||
} | ||
|
||
// -------------------------------------------------------- | ||
|
||
func NewDeleteAddressPairRequest(addressPairID string) IDeleteAddressPairRequest { | ||
opt := new(DeleteAddressPairRequest) | ||
opt.AddressPairID = addressPairID | ||
return opt | ||
} | ||
|
||
type DeleteAddressPairRequest struct { | ||
lscommon.UserAgent | ||
AddressPairID string | ||
} | ||
|
||
func (s *DeleteAddressPairRequest) GetAddressPairID() string { | ||
return s.AddressPairID | ||
} | ||
|
||
// -------------------------------------------------------- |
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,52 @@ | ||
package v2 | ||
|
||
import lsentity "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/entity" | ||
|
||
type GetAllAddressPairByVirtualSubnetIdResponse struct { | ||
Data []*AddressPairResponse `json:"data"` | ||
} | ||
|
||
type AddressPairResponse struct { | ||
UUID string `json:"uuid"` | ||
VirtualIpAddressId string `json:"virtualIpAddressId"` | ||
VirtualSubnetId string `json:"virtualSubnetId"` | ||
NetworkInterfaceIp string `json:"networkInterfaceIp"` | ||
NetworkInterfaceId string `json:"networkInterfaceId"` | ||
|
||
CIDR string `json:"cidr"` | ||
// ID string `json:"id"` | ||
// BackendSubnetId int `json:"backendSubnetId"` | ||
// ProjectId string `json:"projectId"` | ||
// CreatedAt string `json:"createdAt"` | ||
// DeletedAt string `json:"deletedAt"` | ||
} | ||
|
||
func (s *GetAllAddressPairByVirtualSubnetIdResponse) ToListAddressPair() []*lsentity.AddressPair { | ||
addressPairs := make([]*lsentity.AddressPair, 0) | ||
for _, addressPair := range s.Data { | ||
addressPairs = append(addressPairs, &lsentity.AddressPair{ | ||
Id: addressPair.UUID, | ||
VirtualIpAddressId: addressPair.VirtualIpAddressId, | ||
VirtualSubnetId: addressPair.VirtualSubnetId, | ||
NetworkInterfaceIp: addressPair.NetworkInterfaceIp, | ||
NetworkInterfaceId: addressPair.NetworkInterfaceId, | ||
CIDR: addressPair.CIDR, | ||
}) | ||
} | ||
return addressPairs | ||
} | ||
|
||
type SetAddressPairInVirtualSubnetResponse struct { | ||
Data *AddressPairResponse `json:"data"` | ||
} | ||
|
||
func (s *SetAddressPairInVirtualSubnetResponse) ToAddressPair() *lsentity.AddressPair { | ||
return &lsentity.AddressPair{ | ||
Id: s.Data.UUID, | ||
VirtualIpAddressId: s.Data.VirtualIpAddressId, | ||
VirtualSubnetId: s.Data.VirtualSubnetId, | ||
NetworkInterfaceIp: s.Data.NetworkInterfaceIp, | ||
NetworkInterfaceId: s.Data.NetworkInterfaceId, | ||
CIDR: s.Data.CIDR, | ||
} | ||
} |
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
Oops, something went wrong.