2018-01-24 09:56:14 -05:00
|
|
|
package iso
|
|
|
|
|
|
|
|
import (
|
2018-04-25 05:23:37 -04:00
|
|
|
"fmt"
|
|
|
|
|
2018-01-24 09:56:14 -05:00
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/jetbrains-infra/packer-builder-vsphere/driver"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CDRomConfig struct {
|
2018-01-31 12:29:03 -05:00
|
|
|
ISOPaths []string `mapstructure:"iso_paths"`
|
2018-01-24 09:56:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CDRomConfig) Prepare() []error {
|
2018-01-30 11:45:56 -05:00
|
|
|
return nil
|
2018-01-24 09:56:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type StepAddCDRom struct {
|
2018-02-01 06:47:09 -05:00
|
|
|
Config *CDRomConfig
|
2018-01-24 09:56:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepAddCDRom) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2018-02-02 13:04:32 -05:00
|
|
|
vm := state.Get("vm").(*driver.VirtualMachine)
|
2018-01-24 09:56:14 -05:00
|
|
|
|
2018-01-31 12:29:03 -05:00
|
|
|
ui.Say("Adding CDRoms...")
|
2018-02-26 16:17:48 -05:00
|
|
|
if err := vm.AddSATAController(); err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("error adding SATA controller: %v", err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2018-02-01 06:47:09 -05:00
|
|
|
for _, path := range s.Config.ISOPaths {
|
2018-01-31 12:29:03 -05:00
|
|
|
if err := vm.AddCdrom(path); err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("error adding a cdrom: %v", err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2018-01-24 09:56:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2018-04-25 05:23:37 -04:00
|
|
|
func (s *StepAddCDRom) Cleanup(state multistep.StateBag) {}
|