Skip to content

Commit

Permalink
Marketplace support (#150)
Browse files Browse the repository at this point in the history
* adding marketplace deploy support

* adding marketplace to baremetal
  • Loading branch information
ddymko authored Jul 13, 2021
1 parent 092b88a commit 5912470
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 1 deletion.
3 changes: 3 additions & 0 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type Application struct {
Name string `json:"name"`
ShortName string `json:"short_name"`
DeployName string `json:"deploy_name"`
Type string `json:"type"`
Vendor string `json:"vendor"`
ImageID string `json:"image_id"`
}

type applicationBase struct {
Expand Down
8 changes: 7 additions & 1 deletion application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ func TestApplicationServiceHandler_List(t *testing.T) {
"id": 1,
"name": "LEMP",
"short_name": "lemp",
"deploy_name": "LEMP on CentOS 6 x64"
"deploy_name": "LEMP on CentOS 6 x64",
"type": "one-click",
"vendor": "",
"image_id": ""
}
],
"meta": {
Expand Down Expand Up @@ -51,6 +54,9 @@ func TestApplicationServiceHandler_List(t *testing.T) {
Name: "LEMP",
ShortName: "lemp",
DeployName: "LEMP on CentOS 6 x64",
Vendor: "",
Type: "one-click",
ImageID: "",
},
}

Expand Down
2 changes: 2 additions & 0 deletions bare_metal_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type BareMetalServer struct {
Tag string `json:"tag"`
OsID int `json:"os_id"`
AppID int `json:"app_id"`
ImageID string `json:"image_id"`
Features []string `json:"features"`
}

Expand All @@ -80,6 +81,7 @@ type BareMetalCreate struct {
Label string `json:"label,omitempty"`
SSHKeyIDs []string `json:"sshkey_id,omitempty"`
AppID int `json:"app_id,omitempty"`
ImageID string `json:"image_id,omitempty"`
UserData string `json:"user_data,omitempty"`
ActivationEmail *bool `json:"activation_email,omitempty"`
Hostname string `json:"hostname,omitempty"`
Expand Down
90 changes: 90 additions & 0 deletions bare_metal_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,93 @@ func TestBareMetalServerServiceHandler_MassHalt(t *testing.T) {
t.Errorf("BareMetalServer.MassHalf returned %+v, expected %+v", err, nil)
}
}

func TestBareMetalServerServiceHandler_CreateMarketplaceImage(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/v2/bare-metals", func(writer http.ResponseWriter, request *http.Request) {
response := `
{
"bare_metal": {
"id": "900000",
"os": "CentOS 6 x64",
"ram": "65536 MB",
"disk": "2x 240 GB SSD",
"main_ip": "203.0.113.10",
"cpu_count": 1,
"region": "ewr",
"default_password": "ab81u!ryranq",
"date_created": "2017-04-12 18:45:41",
"status": "active",
"netmask_v4": "255.255.255.0",
"gateway_v4": "203.0.113.1",
"plan": "vbm-4c-32gb",
"v6_network": "2001:DB8:9000::",
"v6_main_ip": "2001:DB8:9000::100",
"v6_network_size": 64,
"mac_address": 0,
"label": "go-bm-test",
"tag": "my tag",
"os_id": 127,
"app_id": 0,
"image_id": "test"
}
}
`
fmt.Fprint(writer, response)
})

options := &BareMetalCreate{
StartupScriptID: "1",
Region: "ewr",
Plan: "vbm-4c-32gb",
SnapshotID: "1",
EnableIPv6: BoolToBoolPtr(true),
Label: "go-bm-test",
SSHKeyIDs: []string{"6b80207b1821f"},
AppID: 1,
UserData: "echo Hello World",
ActivationEmail: BoolToBoolPtr(true),
Hostname: "test",
Tag: "go-test",
ReservedIPv4: "111.111.111.111",
PersistentPxe: BoolToBoolPtr(true),
ImageID: "test",
}

bm, err := client.BareMetalServer.Create(ctx, options)

if err != nil {
t.Errorf("BareMetalServer.Create returned error: %v", err)
}

expected := &BareMetalServer{
ID: "900000",
Os: "CentOS 6 x64",
RAM: "65536 MB",
Disk: "2x 240 GB SSD",
MainIP: "203.0.113.10",
CPUCount: 1,
DefaultPassword: "ab81u!ryranq",
DateCreated: "2017-04-12 18:45:41",
Status: "active",
NetmaskV4: "255.255.255.0",
GatewayV4: "203.0.113.1",
Plan: "vbm-4c-32gb",
V6Network: "2001:DB8:9000::",
V6MainIP: "2001:DB8:9000::100",
V6NetworkSize: 64,
Label: "go-bm-test",
Tag: "my tag",
MacAddress: 0,
OsID: 127,
Region: "ewr",
AppID: 0,
ImageID: "test",
}

if !reflect.DeepEqual(bm, expected) {
t.Errorf("BareMetalServer.Create returned %+v, expected %+v", bm, expected)
}
}
2 changes: 2 additions & 0 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type Instance struct {
Tag string `json:"tag"`
OsID int `json:"os_id"`
AppID int `json:"app_id"`
ImageID string `json:"image_id"`
FirewallGroupID string `json:"firewall_group_id"`
Features []string `json:"features"`
}
Expand Down Expand Up @@ -214,6 +215,7 @@ type InstanceCreateReq struct {
OsID int `json:"os_id,omitempty"`
ISOID string `json:"iso_id,omitempty"`
AppID int `json:"app_id,omitempty"`
ImageID string `json:"image_id,omitempty"`
FirewallGroupID string `json:"firewall_group_id,omitempty"`
Hostname string `json:"hostname,omitempty"`
IPXEChainURL string `json:"ipxe_chain_url,omitempty"`
Expand Down
104 changes: 104 additions & 0 deletions instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,3 +1003,107 @@ func TestServerServiceHandler_Update(t *testing.T) {
t.Errorf("Instance.Update returned %+v", err)
}
}

func TestServerServiceHandler_CreateMarketplace(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/v2/instances", func(writer http.ResponseWriter, request *http.Request) {
response := `{
"instance": {
"id": "14b3e7d6-ffb5-4994-8502-57fcd9db3b33",
"os": "CentOS SELinux 8 x64",
"ram": 2048,
"disk": 60,
"main_ip": "123.123.123.123",
"vcpu_count": 2,
"region": "ewr",
"plan": "vc2-1c-2gb",
"date_created": "2013-12-19 14:45:41",
"status": "active",
"allowed_bandwidth": 2000,
"netmask_v4": "255.255.255.248",
"gateway_v4": "123.123.123.1",
"power_status": "running",
"server_status": "ok",
"v6_network": "2001:DB8:1000::",
"v6_main_ip": "fd11:1111:1112:1c02:0200:00ff:fe00:0000",
"v6_network_size": 64,
"label": "my new server",
"internal_ip": "10.99.0.10",
"kvm": "https://my.vultr.com/subs/novnc/api.php?data=eawxFVZw2mXnhGUV",
"default_password" : "nreqnusibni",
"tag": "tagger",
"os_id": 362,
"image_id": "test",
"app_id": 0,
"firewall_group_id": "1234",
"features": [
"auto_backups", "ipv6"
]
}
}`
fmt.Fprint(writer, response)
})

options := &InstanceCreateReq{
IPXEChainURL: "test.org",
ISOID: "14b3e7d6-ffb5-4994-8502-57fcd9db3b33",
ScriptID: "213",
EnableIPv6: BoolToBoolPtr(true),
Backups: "enabled",
UserData: "dW5vLWRvcy10cmVz",
ActivationEmail: BoolToBoolPtr(true),
DDOSProtection: BoolToBoolPtr(true),
SnapshotID: "12ab",
Hostname: "hostname-3000",
Tag: "tagger",
Label: "label-extreme",
SSHKeys: []string{"14b3e7d6-ffb5-4994-8502-57fcd9db3b33", "dev-preview-abc124"},
ReservedIPv4: "63.209.35.79",
FirewallGroupID: "1234",
ImageID: "test",
}

server, err := client.Instance.Create(ctx, options)
if err != nil {
t.Errorf("Instance.Create returned %+v", err)
}

features := []string{"auto_backups", "ipv6"}

expected := &Instance{
ID: "14b3e7d6-ffb5-4994-8502-57fcd9db3b33",
Os: "CentOS SELinux 8 x64",
OsID: 362,
RAM: 2048,
Disk: 60,
MainIP: "123.123.123.123",
VCPUCount: 2,
Region: "ewr",
DefaultPassword: "nreqnusibni",
DateCreated: "2013-12-19 14:45:41",
Status: "active",
AllowedBandwidth: 2000,
NetmaskV4: "255.255.255.248",
GatewayV4: "123.123.123.1",
PowerStatus: "running",
ServerStatus: "ok",
Plan: "vc2-1c-2gb",
V6Network: "2001:DB8:1000::",
V6MainIP: "fd11:1111:1112:1c02:0200:00ff:fe00:0000",
V6NetworkSize: 64,
Label: "my new server",
InternalIP: "10.99.0.10",
KVM: "https://my.vultr.com/subs/novnc/api.php?data=eawxFVZw2mXnhGUV",
Tag: "tagger",
AppID: 0,
ImageID: "test",
FirewallGroupID: "1234",
Features: features,
}

if !reflect.DeepEqual(server, expected) {
t.Errorf("Instance.Create returned %+v, expected %+v", server, expected)
}
}

0 comments on commit 5912470

Please sign in to comment.