Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unecessary check for symbolic link for volume mounted (WIP) #124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 3 additions & 34 deletions builder/osc/chroot/step_mount_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,7 @@ func (s *StepMountDevice) Run(_ context.Context, state multistep.StateBag) multi
return multistep.ActionHalt
}

//Check the symbolic link for the device to get the real device name
cmd := ShellCommand(fmt.Sprintf("lsblk -no pkname $(readlink -f %s)", device))

realDeviceName, err := cmd.Output()
if err != nil {
err := fmt.Errorf(
"Error retrieving the symlink of the device %s.\n", device)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

log.Printf("[DEBUG] RealDeviceName: %s", realDeviceName)

realDeviceNameSplitted := strings.Split(string(realDeviceName), "\n")
log.Printf("[DEBUG] RealDeviceName Splitted %+v", realDeviceNameSplitted)
log.Printf("[DEBUG] RealDeviceName Splitted Length %d", len(realDeviceNameSplitted))
log.Printf("[DEBUG] RealDeviceName Splitted [0] %s", realDeviceNameSplitted[0])
log.Printf("[DEBUG] RealDeviceName Splitted [1] %s", realDeviceNameSplitted[1])

realDeviceNameStr := realDeviceNameSplitted[0]
if realDeviceNameStr == "" {
realDeviceNameStr = realDeviceNameSplitted[1]
}

deviceMount := fmt.Sprintf("/dev/%s", strings.Replace(realDeviceNameStr, "\n", "", -1))

log.Printf("[DEBUG] s.MountPartition = %s", s.MountPartition)
log.Printf("[DEBUG ] DeviceMount: %s", deviceMount)

state.Put("deviceMount", deviceMount)

state.Put("deviceMount", device)
ui.Say("Mounting the root device...")
stderr := new(bytes.Buffer)

Expand All @@ -113,15 +82,15 @@ func (s *StepMountDevice) Run(_ context.Context, state multistep.StateBag) multi
opts = "-o " + strings.Join(s.MountOptions, " -o ")
}
mountCommand, err := wrappedCommand(
fmt.Sprintf("mount %s %s %s", opts, deviceMount, mountPath))
fmt.Sprintf("mount %s %s %s", opts, device, mountPath))
if err != nil {
err := fmt.Errorf("Error creating mount command: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
log.Printf("[DEBUG] (step mount) mount command is %s", mountCommand)
cmd = ShellCommand(mountCommand)
cmd := ShellCommand(mountCommand)
cmd.Stderr = stderr
if err := cmd.Run(); err != nil {
err := fmt.Errorf(
Expand Down
7 changes: 3 additions & 4 deletions builder/osc/common/block_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
oscgo "github.com/outscale/osc-sdk-go/v2"
)
Expand Down Expand Up @@ -69,7 +68,7 @@ func buildOscBlockDevicesImage(b []BlockDevice) []oscgo.BlockDeviceMappingImage
bsu.SnapshotId = &blockDevice.SnapshotId
}

mapping.Bsu = &bsu
mapping.SetBsu(bsu)
}

blockDevices = append(blockDevices, mapping)
Expand All @@ -88,7 +87,7 @@ func buildOscBlockDevicesVmCreation(b []BlockDevice) []oscgo.BlockDeviceMappingV
}

if blockDevice.NoDevice {
mapping.NoDevice = aws.String("")
mapping.NoDevice = oscgo.PtrString("")
//blockDevices = mapping[0]
} else if blockDevice.VirtualName != "" {
if strings.HasPrefix(blockDevice.VirtualName, "ephemeral") {
Expand Down Expand Up @@ -117,7 +116,7 @@ func buildOscBlockDevicesVmCreation(b []BlockDevice) []oscgo.BlockDeviceMappingV
bsu.SnapshotId = &blockDevice.SnapshotId
}

mapping.Bsu = &bsu
mapping.SetBsu(bsu)
}

blockDevices = append(blockDevices, mapping)
Expand Down
10 changes: 7 additions & 3 deletions example/osc-chroot.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ variable "osc_secret_key" {
type = string
default = "${env("OSC_SECRET_KEY")}"
}

packer {
required_plugins {
outscale = {
Expand All @@ -23,12 +24,15 @@ source "outscale-chroot" "windows" {
from_scratch = true
pre_mount_commands = [
"parted {{.Device}} mklabel msdos mkpart primary 1M 100% set 1 boot on print",
"mkfs.ext4 {{.Device}}1"
"fdisk {{.Device}}",
"sleep 1",
"mkfs -t xfs -f {{.Device}}"
]
root_volume_size = 15
root_device_name = "xvdf"
root_device_name = "xvda"
omi_block_device_mappings {
device_name = "xvdf"
delete_on_vm_deletion = false
device_name = "xvda"
volume_type = "gp2"
}
}
Expand Down