Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1615 from mcastelino/topic/fc_cpu_mem
Browse files Browse the repository at this point in the history
 firecracker: Add support for default VM configuration
  • Loading branch information
Eric Ernst committed May 2, 2019
2 parents 570eff6 + b496f3f commit 2051dac
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions virtcontainers/fc.go
Expand Up @@ -281,11 +281,7 @@ func (fc *firecracker) fcSetBootSource(path, params string) error {
bootSrcParams.SetBody(src)

_, err := fc.client().Operations.PutGuestBootSource(bootSrcParams)
if err != nil {
return err
}

return nil
return err
}

func (fc *firecracker) fcSetVMRootfs(path string) error {
Expand All @@ -308,11 +304,25 @@ func (fc *firecracker) fcSetVMRootfs(path string) error {
}
driveParams.SetBody(drive)
_, err := fc.client().Operations.PutGuestDriveByID(driveParams)
if err != nil {
return err
}
return err
}

return nil
func (fc *firecracker) fcSetVMBaseConfig(mem int64, vcpus int64, htEnabled bool) error {
span, _ := fc.trace("fcSetVMBaseConfig")
defer span.Finish()
fc.Logger().WithFields(logrus.Fields{"mem": mem,
"vcpus": vcpus,
"htEnabled": htEnabled}).Debug("fcSetVMBaseConfig")

param := ops.NewPutMachineConfigurationParams()
cfg := &models.MachineConfiguration{
HtEnabled: htEnabled,
MemSizeMib: mem,
VcpuCount: vcpus,
}
param.SetBody(cfg)
_, err := fc.client().Operations.PutMachineConfiguration(param)
return err
}

func (fc *firecracker) fcStartVM() error {
Expand Down Expand Up @@ -351,6 +361,12 @@ func (fc *firecracker) startSandbox(timeout int) error {
return err
}

if err := fc.fcSetVMBaseConfig(int64(fc.config.MemorySize),
int64(fc.config.NumVCPUs),
false); err != nil {
return err
}

kernelPath, err := fc.config.KernelAssetPath()
if err != nil {
return err
Expand Down Expand Up @@ -528,11 +544,7 @@ func (fc *firecracker) fcAddNetDevice(endpoint Endpoint) error {
cfg.SetBody(ifaceCfg)
cfg.SetIfaceID(ifaceID)
_, err := fc.client().Operations.PutGuestNetworkInterfaceByID(cfg)
if err != nil {
return err
}

return nil
return err
}

func (fc *firecracker) fcAddBlockDrive(drive config.BlockDrive) error {
Expand All @@ -552,11 +564,7 @@ func (fc *firecracker) fcAddBlockDrive(drive config.BlockDrive) error {
}
driveParams.SetBody(driveFc)
_, err := fc.client().Operations.PutGuestDriveByID(driveParams)
if err != nil {
return err
}

return nil
return err
}

// Firecracker supports replacing the host drive used once the VM has booted up
Expand Down

0 comments on commit 2051dac

Please sign in to comment.