@@ -137,9 +137,9 @@ type Config struct {
137137 JailerCfg * JailerConfig
138138
139139 // (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.
143143 VMID string
144144
145145 // NetNS represents the path to a network namespace handle. If present, the
@@ -303,13 +303,27 @@ func (m *Machine) LogLevel() string {
303303 return m .Cfg .LogLevel
304304}
305305
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+
306312// NewMachine initializes a new Machine instance and performs validation of the
307313// provided Config.
308314func NewMachine (ctx context.Context , cfg Config , opts ... Opt ) (* Machine , error ) {
309315 m := & Machine {
310316 exitCh : make (chan struct {}),
311317 }
312318
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+
313327 m .Handlers = defaultHandlers
314328
315329 if cfg .JailerCfg != nil {
@@ -319,10 +333,7 @@ func NewMachine(ctx context.Context, cfg Config, opts ...Opt) (*Machine, error)
319333 }
320334 } else {
321335 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 )
326337 }
327338
328339 for _ , opt := range opts {
@@ -339,14 +350,6 @@ func NewMachine(ctx context.Context, cfg Config, opts ...Opt) (*Machine, error)
339350 m .client = NewClient (cfg .SocketPath , m .logger , false )
340351 }
341352
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-
350353 if cfg .ForwardSignals == nil {
351354 cfg .ForwardSignals = []os.Signal {
352355 os .Interrupt ,
0 commit comments