From fdf028c46359a990165e73f0682c3b08e4784865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Sm=C3=B3=C5=82ka?= Date: Wed, 6 Feb 2019 12:27:57 +0100 Subject: [PATCH] Search SCSI device in /sys/bus due to issues with by-path --- builder/hyperone/step_create_vm.go | 5 ++++- builder/hyperone/step_prepare_device.go | 22 ++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/builder/hyperone/step_create_vm.go b/builder/hyperone/step_create_vm.go index 2bb3ae84a..1ffd06d35 100644 --- a/builder/hyperone/step_create_vm.go +++ b/builder/hyperone/step_create_vm.go @@ -3,6 +3,7 @@ package hyperone import ( "context" "fmt" + "strings" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" @@ -78,7 +79,9 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis for _, hdd := range hdds { if hdd.Disk.Name == chrootDiskName { 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 } } diff --git a/builder/hyperone/step_prepare_device.go b/builder/hyperone/step_prepare_device.go index 00a720b68..1a4b74bb0 100644 --- a/builder/hyperone/step_prepare_device.go +++ b/builder/hyperone/step_prepare_device.go @@ -10,21 +10,22 @@ import ( ) const ( - diskByPathPrefix = "/dev/disk/by-path/acpi-VMBUS:01-scsi-0:0:0:" + vmBusPath = "/sys/bus/vmbus/devices" ) type stepPrepareDevice struct{} func (s *stepPrepareDevice) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { 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...") - diskByPath := fmt.Sprintf("%s%d", diskByPathPrefix, chrootDiskLocation) - cmd := fmt.Sprintf("readlink -f %s", diskByPath) + cmd := fmt.Sprintf("find %s/%s/ -path *:%d/block -exec ls {} \\;", + vmBusPath, controllerNumber, controllerLocation) - device, err := captureOutput(cmd, state) + block, err := captureOutput(cmd, state) if err != nil { err := fmt.Errorf("error finding available device: %s", err) state.Put("error", err) @@ -32,7 +33,16 @@ func (s *stepPrepareDevice) Run(_ context.Context, state multistep.StateBag) mul 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) return multistep.ActionContinue }