diff --git a/cmd/machine/cmd/init.go b/cmd/machine/cmd/init.go index 28a05ce..e444156 100644 --- a/cmd/machine/cmd/init.go +++ b/cmd/machine/cmd/init.go @@ -174,7 +174,7 @@ func DoCreateMachine(machineName, machineType, fileName string, editFile bool) e return fmt.Errorf("Error calling editor: %s", err) } } - log.Debug("Got config:\n%s", string(machineBytes)) + log.Debugf("Got config:\n%s", string(machineBytes)) for { if err = yaml.Unmarshal(machineBytes, &newMachine); err == nil { @@ -195,7 +195,9 @@ func DoCreateMachine(machineName, machineType, fileName string, editFile bool) e } } - checkMachineFilePaths(&newMachine) + if err := checkMachineFilePaths(&newMachine); err != nil { + return fmt.Errorf("Error while checking machine fiel paths: %s", err) + } // persist config if not ephemeral err = postMachine(newMachine) @@ -264,6 +266,14 @@ func checkMachineFilePaths(newMachine *api.Machine) error { log.Infof("Fully qualified uefi-vars path %s", newPath) newMachine.Config.UEFIVars = newPath } + if newMachine.Config.UEFICode != "" { + newPath, err := verifyPath(cwd, newMachine.Config.UEFICode) + if err != nil { + return fmt.Errorf("Failed to verify path to uefi-code: %q: %s", newMachine.Config.UEFICode, err) + } + log.Infof("Fully qualified uefi-code path %s", newPath) + newMachine.Config.UEFICode = newPath + } return nil } @@ -301,6 +311,10 @@ func doInitArgsValidate(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true return fmt.Errorf("Invalid machine-type '%s', must be one of: %s", mType, strings.Join(mTypes, ", ")) } + debug, _ := cmd.Flags().GetBool("debug") + if debug { + log.SetLevel(log.DebugLevel) + } return nil } @@ -309,5 +323,6 @@ func init() { rootCmd.AddCommand(initCmd) initCmd.PersistentFlags().StringP("file", "f", "", "yaml file to import. If unspecified, use stdin") initCmd.PersistentFlags().BoolP("edit", "e", false, "edit the yaml file inline") + initCmd.PersistentFlags().BoolP("debug", "D", false, "enable debug logging") initCmd.PersistentFlags().StringP("machine-type", "m", defaultMachineType, fmt.Sprintf("specify the machine type, one of [%s]", strings.Join(mTypes, ", "))) } diff --git a/pkg/api/qconfig.go b/pkg/api/qconfig.go index 942f493..fab79f7 100644 --- a/pkg/api/qconfig.go +++ b/pkg/api/qconfig.go @@ -364,21 +364,41 @@ func (nd NicDef) QNetDevice(qti *qcli.QemuTypeIndex) (qcli.NetDevice, error) { return ndev, nil } -func ConfigureUEFIVars(c *qcli.Config, srcVars, runDir string, secureBoot bool) error { +func ConfigureUEFIVars(c *qcli.Config, srcCode, srcVars, runDir string, secureBoot bool) error { uefiDev, err := qcli.NewSystemUEFIFirmwareDevice(secureBoot) if err != nil { return fmt.Errorf("failed to create a UEFI Firmware Device: %s", err) } - src := uefiDev.Vars + // Import source UEFI Code (if provided) + src := uefiDev.Code + if len(srcCode) > 0 { + src = srcCode + } + // FIXME: create a qcli.UEFICodeFileName + dest := filepath.Join(runDir, "uefi-code.fd") + log.Infof("Importing UEFI Code from '%s' to '%q'", src, dest) + if err := CopyFileBits(src, dest); err != nil { + return fmt.Errorf("Failed to import UEFI Code from '%s' to '%q': %s", src, dest, err) + } + uefiDev.Code = dest + + // Import source UEFI Vxrs (if provided) + src = uefiDev.Vars if len(srcVars) > 0 { src = srcVars } - dest := filepath.Join(runDir, qcli.UEFIVarsFileName) + dest = filepath.Join(runDir, qcli.UEFIVarsFileName) log.Infof("Importing UEFI Vars from '%s' to '%q'", src, dest) + // FIXME: should we skip re-import of srcVars, the imported Vars may have + // had changes that a new import would clobber, warning for now + if PathExists(dest) { + log.Warnf("Already imported UEFI Vars file %q to %q, overwriting...", src, dest) + } if err := CopyFileBits(src, dest); err != nil { return fmt.Errorf("Failed to import UEFI Vars from '%s' to '%q': %s", src, dest, err) } uefiDev.Vars = dest + c.UEFIFirmwareDevices = []qcli.UEFIFirmwareDevice{*uefiDev} return nil } @@ -397,7 +417,7 @@ func GenerateQConfig(runDir, sockDir string, v VMDef) (*qcli.Config, error) { return c, err } - err = ConfigureUEFIVars(c, v.UEFIVars, runDir, v.SecureBoot) + err = ConfigureUEFIVars(c, v.UEFICode, v.UEFIVars, runDir, v.SecureBoot) if err != nil { return c, fmt.Errorf("Error configuring UEFI Vars: %s", err) } diff --git a/pkg/api/vm.go b/pkg/api/vm.go index aca3474..934fc18 100644 --- a/pkg/api/vm.go +++ b/pkg/api/vm.go @@ -65,6 +65,7 @@ type VMDef struct { Disks []QemuDisk `yaml:"disks"` Boot string `yaml:"boot"` Cdrom string `yaml:"cdrom"` + UEFICode string `yaml:"uefi-code"` UEFIVars string `yaml:"uefi-vars"` TPM bool `yaml:"tpm"` TPMVersion string `yaml:"tpm-version"`