Skip to content

Commit

Permalink
[chore] nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Nov 2, 2024
1 parent 2f47d57 commit c1927ed
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 44 deletions.
48 changes: 39 additions & 9 deletions test/server_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package test

import (
lscomputeSvcV2 "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/compute/v2"
ltesting "testing"

lscomputeSvcV2 "github.com/vngcloud/vngcloud-go-sdk/v2/vngcloud/services/compute/v2"
)

func TestCreateServerFailed(t *ltesting.T) {
Expand All @@ -11,11 +12,10 @@ func TestCreateServerFailed(t *ltesting.T) {
"cuongdm3-test",
"img-b5bf635e-0456-4765-b493-31d5fcfc05aa",
"flav-3929c073-9da9-486f-a96f-9282dbb8d83f",
"net-4f35f173-e0fe-4202-9c2b-5121b558bcd2",
"sub-1f98ff1e-2e36-4a40-a0f4-4eadfeb1ea63",
"vtype-61c3fc5b-f4e9-45b4-8957-8aa7b6029018",
30,
)
).WithNetwork("net-4f35f173-e0fe-4202-9c2b-5121b558bcd2",
"sub-1f98ff1e-2e36-4a40-a0f4-4eadfeb1ea63")
server, sdkerr := vngcloud.VServerGateway().V2().ComputeService().CreateServer(opt)
if sdkerr == nil {
t.Fatalf("Expect error but got nil")
Expand All @@ -35,11 +35,11 @@ func TestCreateServerSuccess(t *ltesting.T) {
"cuongdm3-test-tags",
"img-b5bf635e-0456-4765-b493-31d5fcfc05aa",
"flav-3929c073-9da9-486f-a96f-9282dbb8d83f",
"net-4f35f173-e0fe-4202-9c2b-5121b558bcd3",
"sub-1f98ff1e-2e36-4a40-a0f4-4eadfeb1ea63",
"vtype-61c3fc5b-f4e9-45b4-8957-8aa7b6029018",
30,
).WithTags("cuongdm3", "deptrai", "wife", "unknown")
).WithTags("cuongdm3", "deptrai", "wife", "unknown").
WithNetwork("net-4f35f173-e0fe-4202-9c2b-5121b558bcd3",
"sub-1f98ff1e-2e36-4a40-a0f4-4eadfeb1ea63")
server, sdkerr := vngcloud.VServerGateway().V2().ComputeService().CreateServer(opt)
if sdkerr != nil {
t.Fatalf("Expect nil but got %v", sdkerr)
Expand Down Expand Up @@ -182,10 +182,10 @@ func TestCreateServerWithAutoRenew(t *ltesting.T) {
"cuongdm3-dep-trai-vo-dich-sieu-cap-vu-tru-4",
"img-108b3a77-ab58-4000-9b3e-190d0b4b07fc",
"flav-3929c073-9da9-486f-a96f-9282dbb8d83f",
"net-dae83c7a-f837-4227-bcfa-ec0755549724",
"sub-f7770744-6aa4-4292-9ff9-b43b44716ede",
"vtype-61c3fc5b-f4e9-45b4-8957-8aa7b6029018",
30).
WithNetwork("net-dae83c7a-f837-4227-bcfa-ec0755549724",
"sub-f7770744-6aa4-4292-9ff9-b43b44716ede").
WithTags("cuongdm3", "deptrai", "wife", "unknown").
WithAutoRenew(false).
WithType("VKS").WithProduct("VKS").
Expand Down Expand Up @@ -285,3 +285,33 @@ func TestDetachFloatingIp(t *ltesting.T) {

t.Log("PASS")
}

func TestCreateDnsServer(t *ltesting.T) {
vngcloud := validSdkConfigHanRegion()
opt := lscomputeSvcV2.NewCreateServerRequest(
"cuongdm3-test",
"img-b5bf635e-0456-4765-b493-31d5fcfc05aa",
"flav-8066e9ff-5d80-4e8f-aeae-9e8a934bfc44",
"vtype-7a7a8610-34f5-11ee-be56-0242ac120002",
30,
).WithNetwork("", "").WithServerNetworkInterface(
"pro-5ce9da27-8ac9-40db-8743-d80f6cbf1491",
"net-6ad5cc2d-5dfe-4632-a578-6446e6503dd0",
"sub-33ec4719-915f-4818-85b0-f17bdf7f899b",
true,
).WithServerNetworkInterface(
"pro-e5af9dda-cccb-4f49-bb15-de890cb015c7",
"net-0dc4cf1e-d961-4483-b848-62ed86fa69f1",
"sub-1a7e3339-5a73-4cd4-a998-77df31e39303",
false,
)

server, sdkerr := vngcloud.VServerGateway().V2().ComputeService().CreateServer(opt)

if sdkerr != nil {
t.Fatalf("Expect nil but got %v", sdkerr)
}

t.Log("Result: ", server)
t.Log("PASS")
}
4 changes: 4 additions & 0 deletions vngcloud/services/compute/v2/irequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ type ICreateServerRequest interface {
WithSecgroups(psecgroups ...string) ICreateServerRequest
WithPoc(pisPoc bool) ICreateServerRequest
WithType(ptype string) ICreateServerRequest
WithNetwork(pnetworkId, psubnetId string) ICreateServerRequest
WithProduct(pproduct string) ICreateServerRequest
WithServerNetworkInterface(pprojectId, pnetworkId, psubnetId string, pattachFloating bool) ICreateServerRequest
AddUserAgent(pagent ...string) ICreateServerRequest
ParseUserAgent() string
}

type IGetServerByIdRequest interface {
Expand Down
6 changes: 2 additions & 4 deletions vngcloud/services/compute/v2/requests.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package v2

func NewCreateServerRequest(pname, pimageId, pflavorId, pnetworkId, psubnetId, prootDiskType string, prootDiskSize int) ICreateServerRequest {
func NewCreateServerRequest(pname, pimageId, pflavorId, prootDiskType string, prootDiskSize int) ICreateServerRequest {
opt := new(CreateServerRequest)
opt.Name = pname
opt.ImageId = pimageId
opt.FlavorId = pflavorId
opt.NetworkId = pnetworkId
opt.SubnetId = psubnetId
opt.RootDiskTypeId = prootDiskType
opt.RootDiskSize = prootDiskSize
return opt
Expand Down Expand Up @@ -61,4 +59,4 @@ func NewDetachFloatingIpRequest(pserverId, pwanId, pniid string) IDetachFloating
opt.NetworkInterfaceId = pniid
opt.WanId = pwanId
return opt
}
}
1 change: 1 addition & 0 deletions vngcloud/services/compute/v2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func (s *ComputeServiceV2) CreateServer(popts ICreateServerRequest) (*lsentity.S
resp := new(CreateServerResponse)
errResp := lserr.NewErrorResponse(lserr.NormalErrorType)
req := lsclient.NewRequest().
WithHeader("User-Agent", popts.ParseUserAgent()).
WithOkCodes(202).
WithJsonBody(popts.ToRequestBody()).
WithJsonResponse(resp).
Expand Down
95 changes: 64 additions & 31 deletions vngcloud/services/compute/v2/server_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,47 @@ const (
)

type CreateServerRequest struct {
AttachFloating bool `json:"attachFloating,omitempty"`
BackupInstancePointId string `json:"backupInstancePointId,omitempty"`
DataDiskEncryptionType DataDiskEncryptionType `json:"dataDiskEncryptionType,omitempty"`
DataDiskName string `json:"dataDiskName,omitempty"`
DataDiskSize int `json:"dataDiskSize,omitempty"`
DataDiskTypeId string `json:"dataDiskTypeId,omitempty"`
EnableBackup bool `json:"enableBackup,omitempty"`
EncryptionVolume bool `json:"encryptionVolume"`
ExpirePassword bool `json:"expirePassword,omitempty"`
FlavorId string `json:"flavorId"`
ImageId string `json:"imageId"`
Name string `json:"name"`
NetworkId string `json:"networkId"`
OsLicence bool `json:"osLicence,omitempty"`
RestoreBackup bool `json:"restoreBackup,omitempty"`
RootDiskEncryptionType DataDiskEncryptionType `json:"rootDiskEncryptionType,omitempty"`
RootDiskSize int `json:"rootDiskSize"`
RootDiskTypeId string `json:"rootDiskTypeId"`
SecurityGroup []string `json:"securityGroup,omitempty"`
ServerGroupId string `json:"serverGroupId,omitempty"`
SshKeyId string `json:"sshKeyId,omitempty"`
SubnetId string `json:"subnetId"`
UserData string `json:"userData,omitempty"`
UserDataBase64Encoded bool `json:"userDataBase64Encoded,omitempty"`
UserName string `json:"userName,omitempty"`
UserPassword string `json:"userPassword,omitempty"`
IsPoc bool `json:"isPoc,omitempty"`
Product string `json:"product,omitempty"`
Type string `json:"type,omitempty"`
Tags []ServerTag `json:"tags,omitempty"`
AutoRenew bool `json:"isEnableAutoRenew,omitempty"`
AttachFloating bool `json:"attachFloating,omitempty"`
BackupInstancePointId string `json:"backupInstancePointId,omitempty"`
DataDiskEncryptionType DataDiskEncryptionType `json:"dataDiskEncryptionType,omitempty"`
DataDiskName string `json:"dataDiskName,omitempty"`
DataDiskSize int `json:"dataDiskSize,omitempty"`
DataDiskTypeId string `json:"dataDiskTypeId,omitempty"`
EnableBackup bool `json:"enableBackup,omitempty"`
EncryptionVolume bool `json:"encryptionVolume"`
ExpirePassword bool `json:"expirePassword,omitempty"`
FlavorId string `json:"flavorId"`
ImageId string `json:"imageId"`
Name string `json:"name"`
NetworkId *string `json:"networkId,omitempty"`
SubnetId *string `json:"subnetId,omitempty"`
OsLicence bool `json:"osLicence,omitempty"`
RestoreBackup bool `json:"restoreBackup,omitempty"`
RootDiskEncryptionType DataDiskEncryptionType `json:"rootDiskEncryptionType,omitempty"`
RootDiskSize int `json:"rootDiskSize"`
RootDiskTypeId string `json:"rootDiskTypeId"`
SecurityGroup []string `json:"securityGroup,omitempty"`
ServerGroupId string `json:"serverGroupId,omitempty"`
SshKeyId string `json:"sshKeyId,omitempty"`
UserData string `json:"userData,omitempty"`
UserDataBase64Encoded bool `json:"userDataBase64Encoded,omitempty"`
UserName string `json:"userName,omitempty"`
UserPassword string `json:"userPassword,omitempty"`
IsPoc bool `json:"isPoc,omitempty"`
Product string `json:"product,omitempty"`
Type string `json:"type,omitempty"`
Tags []ServerTag `json:"tags,omitempty"`
AutoRenew bool `json:"isEnableAutoRenew,omitempty"`
Networks []ServerNetworkInterface `json:"networks,omitempty"`

lscommon.UserAgent
}

type ServerNetworkInterface struct {
ProjectId string `json:"projectId"`
NetworkId string `json:"networkId"`
SubnetId string `json:"subnetId"`
AttachFloating bool `json:"attachFloating"`
}

type AttachBlockVolumeRequest struct {
Expand All @@ -62,6 +72,17 @@ func (s *CreateServerRequest) ToRequestBody() interface{} {
return s
}

func (s *CreateServerRequest) WithServerNetworkInterface(pprojectId, pnetworkId, psubnetId string, pattachFloating bool) ICreateServerRequest {
s.Networks = append(s.Networks, ServerNetworkInterface{
ProjectId: pprojectId,
NetworkId: pnetworkId,
SubnetId: psubnetId,
AttachFloating: pattachFloating,
})

return s
}

func (s *CreateServerRequest) WithRootDiskEncryptionType(pdataDisk DataDiskEncryptionType) ICreateServerRequest {
s.EncryptionVolume = true
s.RootDiskEncryptionType = pdataDisk
Expand Down Expand Up @@ -124,6 +145,18 @@ func (s *CreateServerRequest) WithProduct(pproduct string) ICreateServerRequest
return s
}

func (s *CreateServerRequest) WithNetwork(pnetworkId, psubnetId string) ICreateServerRequest {
s.NetworkId = &pnetworkId
s.SubnetId = &psubnetId

return s
}

func (s *CreateServerRequest) AddUserAgent(pagent ...string) ICreateServerRequest {
s.UserAgent.AddUserAgent(pagent...)
return s
}

type GetServerByIdRequest struct {
lscommon.ServerCommon
}
Expand Down

0 comments on commit c1927ed

Please sign in to comment.