Skip to content

Commit 244d54a

Browse files
authored
Merge pull request #60 from serverscom/add-ipxe-config-flag-for-ebm-creating
Add ipxe-config flag support for hosts ebm add command
2 parents da37fa3 + 2418d9a commit 244d54a

6 files changed

Lines changed: 114 additions & 4 deletions

File tree

cmd/entities/hosts/add.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type AddEBMFlags struct {
1717
ServerModelID int
1818
OperatingSystemID int
1919
Features []string
20+
IPXEConfig string
2021
RAMSize int
2122
PublicUplinkID int
2223
PublicBandwidthID int
@@ -56,6 +57,9 @@ func (f *AddEBMFlags) FillInput(cmd *cobra.Command, input *serverscom.DedicatedS
5657
if pflags.Changed("feature") {
5758
input.Features = f.Features
5859
}
60+
if pflags.Changed("ipxe-config") {
61+
input.IPXEConfig = &f.IPXEConfig
62+
}
5963
if pflags.Changed("ram-size") {
6064
input.RAMSize = f.RAMSize
6165
}
@@ -233,6 +237,7 @@ func newAddEBMCmd(cmdContext *base.CmdContext) *cobra.Command {
233237
cmd.Flags().IntVar(&flags.ServerModelID, "server-model-id", 0, "Use specific server model ID to create the server")
234238
cmd.Flags().IntVar(&flags.OperatingSystemID, "operating-system-id", 0, "Install the specific operating system")
235239
cmd.Flags().StringSliceVar(&flags.Features, "feature", nil, "Set of features")
240+
cmd.Flags().StringVar(&flags.IPXEConfig, "ipxe-config", "", "iPXE script content")
236241
cmd.Flags().IntVar(&flags.RAMSize, "ram-size", 0, "Desired amount of RAM in GB")
237242
cmd.Flags().IntVar(&flags.PublicUplinkID, "public-uplink-id", 0, "The public uplink ID, can be omitted if do not want public uplink")
238243
cmd.Flags().IntVar(&flags.PrivateUplinkID, "private-uplink-id", 0, "The private uplink ID")

cmd/entities/hosts/hosts_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,55 @@ func TestAddEBMCmd(t *testing.T) {
352352
Times(0)
353353
},
354354
},
355+
{
356+
name: "create ebm server with public_ipxe_boot feature and ipxe-config",
357+
output: "json",
358+
expectedOutput: testutils.ReadFixture(filepath.Join(fixtureBasePath, "create_ebm_resp.json")),
359+
args: []string{
360+
"--input", filepath.Join(fixtureBasePath, "create_ebm_input.json"),
361+
"--feature", "public_ipxe_boot",
362+
"--ipxe-config", "#!ipxe\nboot",
363+
},
364+
configureMock: func(mock *mocks.MockHostsService) {
365+
input := expectedInput
366+
input.Features = []string{"public_ipxe_boot"}
367+
input.IPXEConfig = testutils.PtrString("#!ipxe\nboot")
368+
mock.EXPECT().
369+
CreateDedicatedServers(gomock.Any(), input).
370+
Return([]serverscom.DedicatedServer{testDS}, nil)
371+
},
372+
},
373+
{
374+
name: "create ebm server with ipxe-config flag",
375+
output: "json",
376+
expectedOutput: testutils.ReadFixture(filepath.Join(fixtureBasePath, "create_ebm_resp.json")),
377+
args: []string{
378+
"--input", filepath.Join(fixtureBasePath, "create_ebm_input.json"),
379+
"--ipxe-config", "#!ipxe\nboot",
380+
},
381+
configureMock: func(mock *mocks.MockHostsService) {
382+
input := expectedInput
383+
input.IPXEConfig = testutils.PtrString("#!ipxe\nboot")
384+
mock.EXPECT().
385+
CreateDedicatedServers(gomock.Any(), input).
386+
Return([]serverscom.DedicatedServer{testDS}, nil)
387+
},
388+
},
389+
{
390+
name: "create ebm server with ipxe-config in input file",
391+
output: "json",
392+
expectedOutput: testutils.ReadFixture(filepath.Join(fixtureBasePath, "create_ebm_resp.json")),
393+
args: []string{
394+
"--input", filepath.Join(fixtureBasePath, "create_ebm_ipxe_input.json"),
395+
},
396+
configureMock: func(mock *mocks.MockHostsService) {
397+
input := expectedInput
398+
input.IPXEConfig = testutils.PtrString("#!ipxe\nboot")
399+
mock.EXPECT().
400+
CreateDedicatedServers(gomock.Any(), input).
401+
Return([]serverscom.DedicatedServer{testDS}, nil)
402+
},
403+
},
355404
{
356405
name: "create ebm server with error",
357406
expectError: true,

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/creack/pty v1.1.24
88
github.com/jmespath/go-jmespath v0.4.0
99
github.com/onsi/gomega v1.38.0
10-
github.com/serverscom/serverscom-go-client v1.0.30
10+
github.com/serverscom/serverscom-go-client v1.0.32
1111
github.com/spf13/cobra v1.9.1
1212
github.com/spf13/pflag v1.0.7
1313
github.com/spf13/viper v1.20.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
4646
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
4747
github.com/sagikazarmark/locafero v0.10.0 h1:FM8Cv6j2KqIhM2ZK7HZjm4mpj9NBktLgowT1aN9q5Cc=
4848
github.com/sagikazarmark/locafero v0.10.0/go.mod h1:Ieo3EUsjifvQu4NZwV5sPd4dwvu0OCgEQV7vjc9yDjw=
49-
github.com/serverscom/serverscom-go-client v1.0.30 h1:J6bp3fVevZKzNduyj2XAZGvQVIReg3RMGcOS/Idz92c=
50-
github.com/serverscom/serverscom-go-client v1.0.30/go.mod h1:/Nf+XygKOxm19Sl2gvMzT55O4X+tWDkj/UM4mjzfKgM=
49+
github.com/serverscom/serverscom-go-client v1.0.32 h1:7pW3TJN4x7vF5QPSjBxQ3IKEr656LSaLgAZ3/09395k=
50+
github.com/serverscom/serverscom-go-client v1.0.32/go.mod h1:/Nf+XygKOxm19Sl2gvMzT55O4X+tWDkj/UM4mjzfKgM=
5151
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
5252
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
5353
github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA=

internal/output/skeletons/templates/hosts/add_ebm.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@
4444
}
4545
}
4646
],
47-
"operating_system_id": ""
47+
"operating_system_id": "",
48+
"features": [],
49+
"ipxe_config": ""
4850
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"server_model_id": 1234,
3+
"location_id": 5678,
4+
"ram_size": 16,
5+
"uplink_models": {
6+
"public": {
7+
"id": 4321,
8+
"bandwidth_model_id": 8765
9+
},
10+
"private": {
11+
"id": 7890
12+
}
13+
},
14+
"drives": {
15+
"slots": [
16+
{
17+
"position": 1,
18+
"drive_model_id": 3456
19+
},
20+
{
21+
"position": 2,
22+
"drive_model_id": 3456
23+
}
24+
],
25+
"layout": [
26+
{
27+
"slot_positions": [
28+
1,
29+
2
30+
],
31+
"raid": 1,
32+
"partitions": [
33+
{
34+
"target": "/boot",
35+
"size": 500,
36+
"fill": false,
37+
"fs": "ext4"
38+
}
39+
]
40+
}
41+
]
42+
},
43+
"hosts": [
44+
{
45+
"hostname": "example.aa",
46+
"public_ipv4_network_id": "PublicNet123",
47+
"private_ipv4_network_id": "PrivateNet456",
48+
"labels": {
49+
"environment": "testing"
50+
}
51+
}
52+
],
53+
"ipxe_config": "#!ipxe\nboot"
54+
}

0 commit comments

Comments
 (0)