Skip to content

Commit 7dce86a

Browse files
authored
Merge pull request #167 from smira/update-swagger
Update Swagger API spec to include new option, InitrdPath
2 parents 3a8f736 + d2ac2e5 commit 7dce86a

File tree

6 files changed

+120
-86
lines changed

6 files changed

+120
-86
lines changed

client/models/boot_source.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/swagger.yaml

Lines changed: 86 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ swagger: "2.0"
22
info:
33
title: Firecracker API
44
description: RESTful public-facing API.
5-
The API is accessible through HTTP calls on specific URLs
6-
carrying JSON modeled data.
7-
The transport medium is a Unix Domain Socket.
8-
version: 0.19.0
5+
The API is accessible through HTTP calls on specific URLs
6+
carrying JSON modeled data.
7+
The transport medium is a Unix Domain Socket.
8+
version: 0.20.0
99
termsOfService: ""
1010
contact:
1111
@@ -43,11 +43,11 @@ paths:
4343
summary: Creates a synchronous action.
4444
operationId: createSyncAction
4545
parameters:
46-
- name: info
47-
in: body
48-
required: true
49-
schema:
50-
$ref: "#/definitions/InstanceActionInfo"
46+
- name: info
47+
in: body
48+
required: true
49+
schema:
50+
$ref: "#/definitions/InstanceActionInfo"
5151
responses:
5252
204:
5353
description: The update was successful
@@ -69,12 +69,12 @@ paths:
6969
Note that the only currently supported boot source is LocalImage.
7070
operationId: putGuestBootSource
7171
parameters:
72-
- name: body
73-
in: body
74-
description: Guest boot source properties
75-
required: true
76-
schema:
77-
$ref: "#/definitions/BootSource"
72+
- name: body
73+
in: body
74+
description: Guest boot source properties
75+
required: true
76+
schema:
77+
$ref: "#/definitions/BootSource"
7878
responses:
7979
204:
8080
description: Boot source created/updated
@@ -96,17 +96,17 @@ paths:
9696
Will fail if update is not possible.
9797
operationId: putGuestDriveByID
9898
parameters:
99-
- name: drive_id
100-
in: path
101-
description: The id of the guest drive
102-
required: true
103-
type: string
104-
- name: body
105-
in: body
106-
description: Guest drive properties
107-
required: true
108-
schema:
109-
$ref: "#/definitions/Drive"
99+
- name: drive_id
100+
in: path
101+
description: The id of the guest drive
102+
required: true
103+
type: string
104+
- name: body
105+
in: body
106+
description: Guest drive properties
107+
required: true
108+
schema:
109+
$ref: "#/definitions/Drive"
110110
responses:
111111
204:
112112
description: Drive created/updated
@@ -125,17 +125,17 @@ paths:
125125
Will fail if update is not possible.
126126
operationId: patchGuestDriveByID
127127
parameters:
128-
- name: drive_id
129-
in: path
130-
description: The id of the guest drive
131-
required: true
132-
type: string
133-
- name: body
134-
in: body
135-
description: Guest drive properties
136-
required: true
137-
schema:
138-
$ref: "#/definitions/PartialDrive"
128+
- name: drive_id
129+
in: path
130+
description: The id of the guest drive
131+
required: true
132+
type: string
133+
- name: body
134+
in: body
135+
description: Guest drive properties
136+
required: true
137+
schema:
138+
$ref: "#/definitions/PartialDrive"
139139
responses:
140140
204:
141141
description: Drive updated
@@ -149,27 +149,27 @@ paths:
149149
$ref: "#/definitions/Error"
150150

151151
/logger:
152-
put:
153-
summary: Initializes the logger by specifying two named pipes (i.e. for the logs and metrics output).
154-
operationId: putLogger
155-
parameters:
152+
put:
153+
summary: Initializes the logger by specifying two named pipes (i.e. for the logs and metrics output).
154+
operationId: putLogger
155+
parameters:
156156
- name: body
157157
in: body
158158
description: Logging system description
159159
required: true
160160
schema:
161161
$ref: "#/definitions/Logger"
162-
responses:
163-
204:
164-
description: Logger created.
165-
400:
166-
description: Logger cannot be initialized due to bad input.
167-
schema:
168-
$ref: "#/definitions/Error"
169-
default:
170-
description: Internal server error.
171-
schema:
172-
$ref: "#/definitions/Error"
162+
responses:
163+
204:
164+
description: Logger created.
165+
400:
166+
description: Logger cannot be initialized due to bad input.
167+
schema:
168+
$ref: "#/definitions/Error"
169+
default:
170+
description: Internal server error.
171+
schema:
172+
$ref: "#/definitions/Error"
173173

174174
/machine-config:
175175
get:
@@ -199,11 +199,11 @@ paths:
199199
If any of the parameters has an incorrect value, the whole update fails.
200200
operationId: putMachineConfiguration
201201
parameters:
202-
- name: body
203-
in: body
204-
description: Machine Configuration Parameters
205-
schema:
206-
$ref: "#/definitions/MachineConfiguration"
202+
- name: body
203+
in: body
204+
description: Machine Configuration Parameters
205+
schema:
206+
$ref: "#/definitions/MachineConfiguration"
207207
responses:
208208
204:
209209
description: Machine Configuration created/updated
@@ -223,11 +223,11 @@ paths:
223223
If any of the parameters has an incorrect value, the whole update fails.
224224
operationId: patchMachineConfiguration
225225
parameters:
226-
- name: body
227-
in: body
228-
description: A subset of Machine Configuration Parameters
229-
schema:
230-
$ref: "#/definitions/MachineConfiguration"
226+
- name: body
227+
in: body
228+
description: A subset of Machine Configuration Parameters
229+
schema:
230+
$ref: "#/definitions/MachineConfiguration"
231231
responses:
232232
204:
233233
description: Machine Configuration created/updated
@@ -302,17 +302,17 @@ paths:
302302
Creates new network interface with ID specified by iface_id path parameter.
303303
operationId: putGuestNetworkInterfaceByID
304304
parameters:
305-
- name: iface_id
306-
in: path
307-
description: The id of the guest network interface
308-
required: true
309-
type: string
310-
- name: body
311-
in: body
312-
description: Guest network interface properties
313-
required: true
314-
schema:
315-
$ref: "#/definitions/NetworkInterface"
305+
- name: iface_id
306+
in: path
307+
description: The id of the guest network interface
308+
required: true
309+
type: string
310+
- name: body
311+
in: body
312+
description: Guest network interface properties
313+
required: true
314+
schema:
315+
$ref: "#/definitions/NetworkInterface"
316316
responses:
317317
204:
318318
description: Network interface created/updated
@@ -362,12 +362,12 @@ paths:
362362
May fail if update is not possible.
363363
operationId: putGuestVsock
364364
parameters:
365-
- name: body
366-
in: body
367-
description: Guest vsock properties
368-
required: true
369-
schema:
370-
$ref: "#/definitions/Vsock"
365+
- name: body
366+
in: body
367+
description: Guest vsock properties
368+
required: true
369+
schema:
370+
$ref: "#/definitions/Vsock"
371371
responses:
372372
204:
373373
description: Vsock created/updated
@@ -391,6 +391,9 @@ definitions:
391391
kernel_image_path:
392392
type: string
393393
description: Host level path to the kernel image used to boot the guest
394+
initrd_path:
395+
type: string
396+
description: Host level path to the initrd image used to boot the guest
394397
boot_args:
395398
type: string
396399
description: Kernel boot arguments
@@ -449,10 +452,10 @@ definitions:
449452
description: Enumeration indicating what type of action is contained in the payload
450453
type: string
451454
enum:
452-
- BlockDeviceRescan
453-
- FlushMetrics
454-
- InstanceStart
455-
- SendCtrlAltDel
455+
- BlockDeviceRescan
456+
- FlushMetrics
457+
- InstanceStart
458+
- SendCtrlAltDel
456459
payload:
457460
type: string
458461

handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ var CreateMachineHandler = Handler{
192192
var CreateBootSourceHandler = Handler{
193193
Name: CreateBootSourceHandlerName,
194194
Fn: func(ctx context.Context, m *Machine) error {
195-
return m.createBootSource(ctx, m.Cfg.KernelImagePath, m.Cfg.KernelArgs)
195+
return m.createBootSource(ctx, m.Cfg.KernelImagePath, m.Cfg.InitrdPath, m.Cfg.KernelArgs)
196196
},
197197
}
198198

jailer.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,19 @@ func LinkFilesHandler(rootfs, kernelImageFileName string) Handler {
381381
return err
382382
}
383383

384+
initrdFilename := ""
385+
if m.Cfg.InitrdPath != "" {
386+
initrdFilename := filepath.Base(m.Cfg.InitrdPath)
387+
// copy initrd to root fs
388+
if err := linkFileToRootFS(
389+
m.Cfg.JailerCfg,
390+
filepath.Join(rootfs, initrdFilename),
391+
m.Cfg.InitrdPath,
392+
); err != nil {
393+
return err
394+
}
395+
}
396+
384397
// copy all drives to the root fs
385398
for i, drive := range m.Cfg.Drives {
386399
hostPath := StringValue(drive.PathOnHost)
@@ -398,6 +411,9 @@ func LinkFilesHandler(rootfs, kernelImageFileName string) Handler {
398411
}
399412

400413
m.Cfg.KernelImagePath = kernelImageFileName
414+
if m.Cfg.InitrdPath != "" {
415+
m.Cfg.InitrdPath = initrdFilename
416+
}
401417

402418
for _, fifoPath := range []*string{&m.Cfg.LogFifo, &m.Cfg.MetricsFifo} {
403419
if fifoPath == nil || *fifoPath == "" {

machine.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ type Config struct {
7575
// The kernel image must be an uncompressed ELF image.
7676
KernelImagePath string
7777

78+
// InitrdPath defines the file path where initrd image is located.
79+
//
80+
// This parameter is optional.
81+
InitrdPath string
82+
7883
// KernelArgs defines the command-line arguments that should be passed to
7984
// the kernel.
8085
KernelArgs string
@@ -134,6 +139,12 @@ func (cfg *Config) Validate() error {
134139
return fmt.Errorf("failed to stat kernel image path, %q: %v", cfg.KernelImagePath, err)
135140
}
136141

142+
if cfg.InitrdPath != "" {
143+
if _, err := os.Stat(cfg.InitrdPath); err != nil {
144+
return fmt.Errorf("failed to stat initrd image path, %q: %v", cfg.InitrdPath, err)
145+
}
146+
}
147+
137148
for _, drive := range cfg.Drives {
138149
if BoolValue(drive.IsRootDevice) {
139150
rootPath := StringValue(drive.PathOnHost)
@@ -645,9 +656,10 @@ func (m *Machine) createMachine(ctx context.Context) error {
645656
return err
646657
}
647658

648-
func (m *Machine) createBootSource(ctx context.Context, imagePath, kernelArgs string) error {
659+
func (m *Machine) createBootSource(ctx context.Context, imagePath, initrdPath, kernelArgs string) error {
649660
bsrc := models.BootSource{
650661
KernelImagePath: &imagePath,
662+
InitrdPath: initrdPath,
651663
BootArgs: kernelArgs,
652664
}
653665

machine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ func testCreateBootSource(ctx context.Context, t *testing.T, m *Machine, vmlinux
499499
// filesystem available to the guest.
500500
// Kernel command-line options can be found in the kernel source tree at
501501
// Documentation/admin-guide/kernel-parameters.txt.
502-
err := m.createBootSource(ctx, vmlinuxPath, "ro console=ttyS0 noapic reboot=k panic=0 pci=off nomodules")
502+
err := m.createBootSource(ctx, vmlinuxPath, "", "ro console=ttyS0 noapic reboot=k panic=0 pci=off nomodules")
503503
if err != nil {
504504
t.Errorf("failed to create boot source: %s", err)
505505
}

0 commit comments

Comments
 (0)