packer-cn/iso/step_add_floppy.go

71 lines
1.8 KiB
Go
Raw Normal View History

package iso
import (
2018-04-25 07:22:38 -04:00
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/jetbrains-infra/packer-builder-vsphere/driver"
2018-04-25 07:22:38 -04:00
"fmt"
"context"
)
type FloppyConfig struct {
FloppyIMGPath string `mapstructure:"floppy_img_path"`
FloppyFiles []string `mapstructure:"floppy_files"`
FloppyDirectories []string `mapstructure:"floppy_dirs"`
}
type StepAddFloppy struct {
Config *FloppyConfig
Datastore string
Host string
}
2018-04-25 07:22:38 -04:00
func (s *StepAddFloppy) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
vm := state.Get("vm").(*driver.VirtualMachine)
d := state.Get("driver").(*driver.Driver)
if floppyPath, ok := state.GetOk("floppy_path"); ok {
ui.Say("Uploading created floppy image")
2018-03-20 19:03:47 -04:00
ds, err := d.FindDatastore(s.Datastore, s.Host)
if err != nil {
2018-05-06 17:26:04 -04:00
state.Put("error", err)
return multistep.ActionHalt
}
vmDir, err := vm.GetDir()
if err != nil {
2018-05-06 17:26:04 -04:00
state.Put("error", err)
return multistep.ActionHalt
}
2018-05-06 17:26:04 -04:00
uploadPath := fmt.Sprintf("%v/packer-tmp-created-floppy.flp", vmDir)
if err := ds.UploadFile(floppyPath.(string), uploadPath); err != nil {
2018-05-06 17:26:04 -04:00
state.Put("error", err)
return multistep.ActionHalt
}
2018-04-25 04:43:47 -04:00
state.Put("uploaded_floppy_path", uploadPath)
ui.Say("Adding generated Floppy...")
2018-05-06 17:26:04 -04:00
floppyIMGPath := ds.ResolvePath(uploadPath)
err = vm.AddFloppy(floppyIMGPath)
if err != nil {
2018-05-06 17:26:04 -04:00
state.Put("error", err)
return multistep.ActionHalt
}
}
if s.Config.FloppyIMGPath != "" {
ui.Say("Adding Floppy image...")
2018-05-06 17:26:04 -04:00
err := vm.AddFloppy(s.Config.FloppyIMGPath)
if err != nil {
2018-05-06 17:26:04 -04:00
state.Put("error", err)
return multistep.ActionHalt
}
}
2018-05-06 17:26:04 -04:00
return multistep.ActionContinue
}
func (s *StepAddFloppy) Cleanup(state multistep.StateBag) {}