From d78787e1823a46525a3c622be7f331986b8e5dd3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 5 Nov 2013 18:11:38 -0800 Subject: [PATCH] builder/qemu: remove floppy support, not used currently --- builder/qemu/builder.go | 18 ------- builder/qemu/builder_test.go | 33 ------------- builder/qemu/step_copy_floppy.go | 84 -------------------------------- 3 files changed, 135 deletions(-) delete mode 100644 builder/qemu/step_copy_floppy.go diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index e22d090c2..9a93efcd8 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -58,7 +58,6 @@ type config struct { BootCommand []string `mapstructure:"boot_command"` DiskInterface string `mapstructure:"disk_interface"` DiskSize uint `mapstructure:"disk_size"` - FloppyFiles []string `mapstructure:"floppy_files"` Format string `mapstructure:"format"` Headless bool `mapstructure:"headless"` HTTPDir string `mapstructure:"http_directory"` @@ -111,10 +110,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { b.config.DiskSize = 40000 } - if b.config.FloppyFiles == nil { - b.config.FloppyFiles = make([]string, 0) - } - if b.config.Accelerator == "" { 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") { errs = packer.MultiErrorAppend( 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, }, new(stepPrepareOutputDir), - &common.StepCreateFloppy{ - Files: b.config.FloppyFiles, - }, new(stepCreateDisk), new(stepHTTPServer), new(stepForwardSSH), diff --git a/builder/qemu/builder_test.go b/builder/qemu/builder_test.go index 4fb4338a9..86c561263 100644 --- a/builder/qemu/builder_test.go +++ b/builder/qemu/builder_test.go @@ -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) { var b Builder config := testConfig() diff --git a/builder/qemu/step_copy_floppy.go b/builder/qemu/step_copy_floppy.go deleted file mode 100644 index 28acfae9f..000000000 --- a/builder/qemu/step_copy_floppy.go +++ /dev/null @@ -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 -}