builder/qemu: remove floppy support, not used currently
This commit is contained in:
parent
07e5a85bab
commit
d78787e182
|
@ -58,7 +58,6 @@ type config struct {
|
||||||
BootCommand []string `mapstructure:"boot_command"`
|
BootCommand []string `mapstructure:"boot_command"`
|
||||||
DiskInterface string `mapstructure:"disk_interface"`
|
DiskInterface string `mapstructure:"disk_interface"`
|
||||||
DiskSize uint `mapstructure:"disk_size"`
|
DiskSize uint `mapstructure:"disk_size"`
|
||||||
FloppyFiles []string `mapstructure:"floppy_files"`
|
|
||||||
Format string `mapstructure:"format"`
|
Format string `mapstructure:"format"`
|
||||||
Headless bool `mapstructure:"headless"`
|
Headless bool `mapstructure:"headless"`
|
||||||
HTTPDir string `mapstructure:"http_directory"`
|
HTTPDir string `mapstructure:"http_directory"`
|
||||||
|
@ -111,10 +110,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
b.config.DiskSize = 40000
|
b.config.DiskSize = 40000
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.config.FloppyFiles == nil {
|
|
||||||
b.config.FloppyFiles = make([]string, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if b.config.Accelerator == "" {
|
if b.config.Accelerator == "" {
|
||||||
b.config.Accelerator = "kvm"
|
b.config.Accelerator = "kvm"
|
||||||
}
|
}
|
||||||
|
@ -220,16 +215,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, file := range b.config.FloppyFiles {
|
|
||||||
var err error
|
|
||||||
b.config.FloppyFiles[i], err = b.config.tpl.Process(file, nil)
|
|
||||||
if err != nil {
|
|
||||||
errs = packer.MultiErrorAppend(errs,
|
|
||||||
fmt.Errorf("Error processing floppy_files[%d]: %s",
|
|
||||||
i, err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !(b.config.Format == "qcow2" || b.config.Format == "raw") {
|
if !(b.config.Format == "qcow2" || b.config.Format == "raw") {
|
||||||
errs = packer.MultiErrorAppend(
|
errs = packer.MultiErrorAppend(
|
||||||
errs, errors.New("invalid format, only 'qcow2' or 'img' are allowed"))
|
errs, errors.New("invalid format, only 'qcow2' or 'img' are allowed"))
|
||||||
|
@ -383,9 +368,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
Url: b.config.ISOUrls,
|
Url: b.config.ISOUrls,
|
||||||
},
|
},
|
||||||
new(stepPrepareOutputDir),
|
new(stepPrepareOutputDir),
|
||||||
&common.StepCreateFloppy{
|
|
||||||
Files: b.config.FloppyFiles,
|
|
||||||
},
|
|
||||||
new(stepCreateDisk),
|
new(stepCreateDisk),
|
||||||
new(stepHTTPServer),
|
new(stepHTTPServer),
|
||||||
new(stepForwardSSH),
|
new(stepForwardSSH),
|
||||||
|
|
|
@ -164,39 +164,6 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuilderPrepare_FloppyFiles(t *testing.T) {
|
|
||||||
var b Builder
|
|
||||||
config := testConfig()
|
|
||||||
|
|
||||||
delete(config, "floppy_files")
|
|
||||||
warns, err := b.Prepare(config)
|
|
||||||
if len(warns) > 0 {
|
|
||||||
t.Fatalf("bad: %#v", warns)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("bad err: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(b.config.FloppyFiles) != 0 {
|
|
||||||
t.Fatalf("bad: %#v", b.config.FloppyFiles)
|
|
||||||
}
|
|
||||||
|
|
||||||
config["floppy_files"] = []string{"foo", "bar"}
|
|
||||||
b = Builder{}
|
|
||||||
warns, err = b.Prepare(config)
|
|
||||||
if len(warns) > 0 {
|
|
||||||
t.Fatalf("bad: %#v", warns)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("should not have error: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := []string{"foo", "bar"}
|
|
||||||
if !reflect.DeepEqual(b.config.FloppyFiles, expected) {
|
|
||||||
t.Fatalf("bad: %#v", b.config.FloppyFiles)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuilderPrepare_HTTPPort(t *testing.T) {
|
func TestBuilderPrepare_HTTPPort(t *testing.T) {
|
||||||
var b Builder
|
var b Builder
|
||||||
config := testConfig()
|
config := testConfig()
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
package qemu
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/mitchellh/multistep"
|
|
||||||
"github.com/mitchellh/packer/packer"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
// This step attaches the ISO to the virtual machine.
|
|
||||||
//
|
|
||||||
// Uses:
|
|
||||||
//
|
|
||||||
// Produces:
|
|
||||||
type stepCopyFloppy struct {
|
|
||||||
floppyPath string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *stepCopyFloppy) Run(state multistep.StateBag) multistep.StepAction {
|
|
||||||
// Determine if we even have a floppy disk to attach
|
|
||||||
var floppyPath string
|
|
||||||
if floppyPathRaw, ok := state.GetOk("floppy_path"); ok {
|
|
||||||
floppyPath = floppyPathRaw.(string)
|
|
||||||
} else {
|
|
||||||
log.Println("No floppy disk, not attaching.")
|
|
||||||
return multistep.ActionContinue
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy the floppy for exclusive use during the vm creation
|
|
||||||
ui := state.Get("ui").(packer.Ui)
|
|
||||||
ui.Say("Copying floppy disk for exclusive use...")
|
|
||||||
floppyPath, err := s.copyFloppy(floppyPath)
|
|
||||||
if err != nil {
|
|
||||||
state.Put("error", fmt.Errorf("Error preparing floppy: %s", err))
|
|
||||||
return multistep.ActionHalt
|
|
||||||
}
|
|
||||||
|
|
||||||
// Track the path so that we can remove it later
|
|
||||||
s.floppyPath = floppyPath
|
|
||||||
|
|
||||||
return multistep.ActionContinue
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *stepCopyFloppy) Cleanup(state multistep.StateBag) {
|
|
||||||
if s.floppyPath == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete the floppy disk
|
|
||||||
ui := state.Get("ui").(packer.Ui)
|
|
||||||
ui.Say("Removing floppy disk previously copied...")
|
|
||||||
defer os.Remove(s.floppyPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *stepCopyFloppy) copyFloppy(path string) (string, error) {
|
|
||||||
tempdir, err := ioutil.TempDir("", "packer")
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
floppyPath := filepath.Join(tempdir, "floppy.img")
|
|
||||||
f, err := os.Create(floppyPath)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
sourceF, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
defer sourceF.Close()
|
|
||||||
|
|
||||||
log.Printf("Copying floppy to temp location: %s", floppyPath)
|
|
||||||
if _, err := io.Copy(f, sourceF); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return floppyPath, nil
|
|
||||||
}
|
|
Loading…
Reference in New Issue