Search SCSI device in /sys/bus due to issues with by-path
This commit is contained in:
parent
0d8e9f50bf
commit
fdf028c463
|
@ -3,6 +3,7 @@ package hyperone
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/helper/multistep"
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
|
@ -78,7 +79,9 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis
|
||||||
for _, hdd := range hdds {
|
for _, hdd := range hdds {
|
||||||
if hdd.Disk.Name == chrootDiskName {
|
if hdd.Disk.Name == chrootDiskName {
|
||||||
state.Put("chroot_disk_id", hdd.Disk.Id)
|
state.Put("chroot_disk_id", hdd.Disk.Id)
|
||||||
state.Put("chroot_disk_location", int(hdd.ControllerLocation))
|
controllerNumber := strings.ToLower(strings.Trim(hdd.ControllerNumber, "{}"))
|
||||||
|
state.Put("chroot_controller_number", controllerNumber)
|
||||||
|
state.Put("chroot_controller_location", int(hdd.ControllerLocation))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,21 +10,22 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
diskByPathPrefix = "/dev/disk/by-path/acpi-VMBUS:01-scsi-0:0:0:"
|
vmBusPath = "/sys/bus/vmbus/devices"
|
||||||
)
|
)
|
||||||
|
|
||||||
type stepPrepareDevice struct{}
|
type stepPrepareDevice struct{}
|
||||||
|
|
||||||
func (s *stepPrepareDevice) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *stepPrepareDevice) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
chrootDiskLocation := state.Get("chroot_disk_location").(int)
|
controllerNumber := state.Get("chroot_controller_number").(string)
|
||||||
|
controllerLocation := state.Get("chroot_controller_location").(int)
|
||||||
|
|
||||||
log.Println("Searching for available device...")
|
log.Println("Searching for available device...")
|
||||||
|
|
||||||
diskByPath := fmt.Sprintf("%s%d", diskByPathPrefix, chrootDiskLocation)
|
cmd := fmt.Sprintf("find %s/%s/ -path *:%d/block -exec ls {} \\;",
|
||||||
cmd := fmt.Sprintf("readlink -f %s", diskByPath)
|
vmBusPath, controllerNumber, controllerLocation)
|
||||||
|
|
||||||
device, err := captureOutput(cmd, state)
|
block, err := captureOutput(cmd, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("error finding available device: %s", err)
|
err := fmt.Errorf("error finding available device: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
@ -32,7 +33,16 @@ func (s *stepPrepareDevice) Run(_ context.Context, state multistep.StateBag) mul
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Say(fmt.Sprintf("Found device: %s -> %s", diskByPath, device))
|
if block == "" {
|
||||||
|
err := fmt.Errorf("device not found")
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
device := fmt.Sprintf("/dev/%s", block)
|
||||||
|
|
||||||
|
ui.Say(fmt.Sprintf("Found device: %s", device))
|
||||||
state.Put("device", device)
|
state.Put("device", device)
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue