-
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 create virtual address cross project
- Loading branch information
1 parent
267309c
commit a247f8a
Showing
10 changed files
with
232 additions
and
3 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
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 test | ||
|
||
import ( | ||
lsnetworkSvcV2 "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/network/v2" | ||
ltesting "testing" | ||
) | ||
|
||
func TestCreateVirtualAddressCrossProject(t *ltesting.T) { | ||
virtualAddressName := "cuongdm3-test-virtual-address" | ||
projectId := "pro-5ce9da27-8ac9-40db-8743-d80f6cbf1491" | ||
subnetId := "sub-33ec4719-915f-4818-85b0-f17bdf7f899b" | ||
|
||
vngcloud := validSdkConfigHanRegion() | ||
opt := lsnetworkSvcV2.NewCreateVirtualAddressCrossProjectRequest( | ||
virtualAddressName, projectId, subnetId). | ||
WithDescription("Private DNS endpoint address for VPC cuongdm3 created by vDNS. Please DO NOT delete this address.") | ||
vaddr, err := vngcloud.VServerGateway().V2().NetworkService().CreateVirtualAddressCrossProject(opt) | ||
|
||
if err != nil { | ||
t.Errorf("Expect error to be nil but got %+v", err) | ||
} | ||
|
||
if vaddr == nil { | ||
t.Errorf("Expect portal not to be nil but got nil") | ||
} | ||
|
||
t.Log("RESULT:", vaddr) | ||
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,44 @@ | ||
package entity | ||
|
||
type VirtualAddress struct { | ||
Id string | ||
Name string | ||
EndpointAddress string | ||
VpcId string | ||
SubnetId string | ||
Description string | ||
SubnetCidr string | ||
VpcCidr string | ||
} | ||
|
||
func (s *VirtualAddress) GetId() string { | ||
return s.Id | ||
} | ||
|
||
func (s *VirtualAddress) GetName() string { | ||
return s.Name | ||
} | ||
|
||
func (s *VirtualAddress) GetEndpointAddress() string { | ||
return s.EndpointAddress | ||
} | ||
|
||
func (s *VirtualAddress) GetVpcId() string { | ||
return s.VpcId | ||
} | ||
|
||
func (s *VirtualAddress) GetSubnetId() string { | ||
return s.SubnetId | ||
} | ||
|
||
func (s *VirtualAddress) GetDescription() string { | ||
return s.Description | ||
} | ||
|
||
func (s *VirtualAddress) GetSubnetCidr() string { | ||
return s.SubnetCidr | ||
} | ||
|
||
func (s *VirtualAddress) GetVpcCidr() string { | ||
return s.VpcCidr | ||
} |
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 v2 | ||
|
||
func NewCreateVirtualAddressCrossProjectRequest(pname, pprojectId, psubnetId string) ICreateVirtualAddressCrossProjectRequest { | ||
opts := new(CreateVirtualAddressCrossProjectRequest) | ||
opts.Name = pname | ||
opts.CrossProjectRequest.ProjectId = pprojectId | ||
opts.CrossProjectRequest.SubnetId = psubnetId | ||
return opts | ||
} |
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,26 @@ | ||
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) CreateVirtualAddressCrossProject(popts ICreateVirtualAddressCrossProjectRequest) (*lsentity.VirtualAddress, lserr.IError) { | ||
url := createVirtualAddressCrossProjectUrl(s.VserverClient) | ||
resp := new(CreateVirtualAddressCrossProjectResponse) | ||
errResp := lserr.NewErrorResponse(lserr.NormalErrorType) | ||
req := lsclient.NewRequest(). | ||
WithHeader("User-Agent", popts.ParseUserAgent()). | ||
WithOkCodes(201). | ||
WithJsonBody(popts.ToRequestBody()). | ||
WithJsonResponse(resp). | ||
WithJsonError(errResp) | ||
|
||
if _, sdkErr := s.VserverClient.Post(url, req); sdkErr != nil { | ||
return nil, lserr.SdkErrorHandler(sdkErr, errResp). | ||
WithKVparameters(popts.ToMap()) | ||
} | ||
|
||
return resp.ToEntityVirtualAddress(), 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,57 @@ | ||
package v2 | ||
|
||
import lscommon "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/common" | ||
|
||
/** | ||
* The group of Virtual Address APIs | ||
*/ | ||
|
||
// API Create virtual address cross project | ||
type CreateVirtualAddressCrossProjectRequest struct { | ||
// Name is the name of the virtual address. | ||
Name string `json:"name"` // required | ||
|
||
// Description is the description of the virtual address. | ||
Description string `json:"description"` | ||
|
||
// Contains the required information to create a virtual address cross project. | ||
CrossProjectRequest struct { | ||
// The project ID whose virtual address will be created. | ||
ProjectId string `json:"projectId"` // required | ||
|
||
// The subnet ID where the virtual address will be created. | ||
SubnetId string `json:"subnetId"` // required | ||
|
||
// The IP address of the virtual address. | ||
IpAddress string `json:"ipAddress"` | ||
} `json:"crossProjectRequest"` // required | ||
|
||
// others... | ||
lscommon.UserAgent | ||
} | ||
|
||
func (s *CreateVirtualAddressCrossProjectRequest) ToRequestBody() interface{} { | ||
return s | ||
} | ||
|
||
func (s *CreateVirtualAddressCrossProjectRequest) ToMap() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"name": s.Name, | ||
"description": s.Description, | ||
"crossProjectRequest": map[string]interface{}{ | ||
"projectId": s.CrossProjectRequest.ProjectId, | ||
"subnetId": s.CrossProjectRequest.SubnetId, | ||
"ipAddress": s.CrossProjectRequest.IpAddress, | ||
}, | ||
} | ||
} | ||
|
||
func (s *CreateVirtualAddressCrossProjectRequest) AddUserAgent(pagent ...string) ICreateVirtualAddressCrossProjectRequest { | ||
s.UserAgent.AddUserAgent(pagent...) | ||
return s | ||
} | ||
|
||
func (s *CreateVirtualAddressCrossProjectRequest) WithDescription(pdescription string) ICreateVirtualAddressCrossProjectRequest { | ||
s.Description = pdescription | ||
return s | ||
} |
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,32 @@ | ||
package v2 | ||
|
||
import lsentity "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/entity" | ||
|
||
type CreateVirtualAddressCrossProjectResponse struct { | ||
Data struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
NetworkName string `json:"networkName"` | ||
NetworkCIDR string `json:"networkCIDR"` | ||
SubnetCIDR string `json:"subnetCIDR"` | ||
SubnetName string `json:"subnetName"` | ||
UUID string `json:"uuid"` | ||
NetworkID string `json:"networkId"` | ||
SubnetID string `json:"subnetId"` | ||
IPAddress string `json:"ipAddress"` | ||
CreatedAt string `json:"createdAt"` | ||
} `json:"data"` | ||
} | ||
|
||
func (s *CreateVirtualAddressCrossProjectResponse) ToEntityVirtualAddress() *lsentity.VirtualAddress { | ||
return &lsentity.VirtualAddress{ | ||
Id: s.Data.UUID, | ||
Name: s.Data.Name, | ||
EndpointAddress: s.Data.IPAddress, | ||
VpcId: s.Data.NetworkID, | ||
SubnetId: s.Data.SubnetID, | ||
Description: s.Data.Description, | ||
SubnetCidr: s.Data.SubnetCIDR, | ||
VpcCidr: s.Data.NetworkCIDR, | ||
} | ||
} |