@@ -137,9 +137,9 @@ type Config struct {
137
137
JailerCfg * JailerConfig
138
138
139
139
// (Optional) VMID is a unique identifier for this VM. It's set to a
140
- // random uuid if not provided by the user. It's currently used to
141
- // set the CNI ContainerID and create a network namespace path if
142
- // CNI configuration is provided as part of NetworkInterfaces
140
+ // random uuid if not provided by the user. It's used to set Firecracker's instance ID.
141
+ // If CNI configuration is provided as part of NetworkInterfaces,
142
+ // the VMID is used to set CNI ContainerID and create a network namespace path.
143
143
VMID string
144
144
145
145
// NetNS represents the path to a network namespace handle. If present, the
@@ -303,13 +303,27 @@ func (m *Machine) LogLevel() string {
303
303
return m .Cfg .LogLevel
304
304
}
305
305
306
+ func configureBuilder (builder VMCommandBuilder , cfg Config ) VMCommandBuilder {
307
+ return builder .
308
+ WithSocketPath (cfg .SocketPath ).
309
+ AddArgs ("--seccomp-level" , cfg .SeccompLevel .String (), "--id" , cfg .VMID )
310
+ }
311
+
306
312
// NewMachine initializes a new Machine instance and performs validation of the
307
313
// provided Config.
308
314
func NewMachine (ctx context.Context , cfg Config , opts ... Opt ) (* Machine , error ) {
309
315
m := & Machine {
310
316
exitCh : make (chan struct {}),
311
317
}
312
318
319
+ if cfg .VMID == "" {
320
+ randomID , err := uuid .NewV4 ()
321
+ if err != nil {
322
+ return nil , errors .Wrap (err , "failed to create random ID for VMID" )
323
+ }
324
+ cfg .VMID = randomID .String ()
325
+ }
326
+
313
327
m .Handlers = defaultHandlers
314
328
315
329
if cfg .JailerCfg != nil {
@@ -319,10 +333,7 @@ func NewMachine(ctx context.Context, cfg Config, opts ...Opt) (*Machine, error)
319
333
}
320
334
} else {
321
335
m .Handlers .Validation = m .Handlers .Validation .Append (ConfigValidationHandler )
322
- m .cmd = defaultFirecrackerVMMCommandBuilder .
323
- WithSocketPath (cfg .SocketPath ).
324
- AddArgs ("--seccomp-level" , cfg .SeccompLevel .String ()).
325
- Build (ctx )
336
+ m .cmd = configureBuilder (defaultFirecrackerVMMCommandBuilder , cfg ).Build (ctx )
326
337
}
327
338
328
339
for _ , opt := range opts {
@@ -339,14 +350,6 @@ func NewMachine(ctx context.Context, cfg Config, opts ...Opt) (*Machine, error)
339
350
m .client = NewClient (cfg .SocketPath , m .logger , false )
340
351
}
341
352
342
- if cfg .VMID == "" {
343
- randomID , err := uuid .NewV4 ()
344
- if err != nil {
345
- return nil , errors .Wrap (err , "failed to create random ID for VMID" )
346
- }
347
- cfg .VMID = randomID .String ()
348
- }
349
-
350
353
if cfg .ForwardSignals == nil {
351
354
cfg .ForwardSignals = []os.Signal {
352
355
os .Interrupt ,
0 commit comments