create-amis.sh: add support for the ZFS AMIs
This commit is contained in:
parent
1ff82fec9a
commit
407998d15a
1 changed files with 60 additions and 32 deletions
|
@ -64,10 +64,16 @@ read_image_info() {
|
|||
|
||||
# We handle a single image per invocation, store all attributes in
|
||||
# globals for convenience.
|
||||
image_label=$(read_image_info .label)
|
||||
zfs_disks=$(read_image_info .disks)
|
||||
image_label="$(read_image_info .label)${zfs_disks:+-ZFS}"
|
||||
image_system=$(read_image_info .system)
|
||||
image_file=$(read_image_info .file)
|
||||
image_logical_bytes=$(read_image_info .logical_bytes)
|
||||
image_files=( $(read_image_info "${zfs_disks:+.disks.root}.file") )
|
||||
|
||||
image_logical_bytes=$(read_image_info "${zfs_disks:+.disks.root}.logical_bytes")
|
||||
|
||||
if [[ -n "$zfs_disks" ]]; then
|
||||
image_files+=( $(read_image_info .disks.boot.file) )
|
||||
fi
|
||||
|
||||
# Derived attributes
|
||||
|
||||
|
@ -183,9 +189,15 @@ make_image_public() {
|
|||
upload_image() {
|
||||
local region=$1
|
||||
|
||||
for image_file in "${image_files[@]}"; do
|
||||
local aws_path=${image_file#/}
|
||||
|
||||
local state_key="$region.$image_label.$image_system"
|
||||
if [[ -n "$zfs_disks" ]]; then
|
||||
local suffix=${image_file%.*}
|
||||
suffix=${suffix##*.}
|
||||
fi
|
||||
|
||||
local state_key="$region.$image_label${suffix:+.${suffix}}.$image_system"
|
||||
local task_id
|
||||
task_id=$(read_state "$state_key" task_id)
|
||||
local snapshot_id
|
||||
|
@ -218,6 +230,7 @@ upload_image() {
|
|||
snapshot_id=$(wait_for_import "$region" "$task_id")
|
||||
write_state "$state_key" snapshot_id "$snapshot_id"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$ami_id" ]; then
|
||||
log "Registering snapshot $snapshot_id as AMI"
|
||||
|
@ -226,6 +239,21 @@ upload_image() {
|
|||
"DeviceName=/dev/xvda,Ebs={SnapshotId=$snapshot_id,VolumeSize=$image_logical_gigabytes,DeleteOnTermination=true,VolumeType=gp3}"
|
||||
)
|
||||
|
||||
if [[ -n "$zfs_disks" ]]; then
|
||||
local root_snapshot_id=$(read_state "$region.$image_label.root.$image_system" snapshot_id)
|
||||
|
||||
# currently there is a bug in the ZFS AMI derivation, mismatching logical_bytes
|
||||
# root.logical_bytes should be boot.logical_bytes and vice versa
|
||||
# work around until fixed
|
||||
local root_image_logical_bytes=$(read_image_info ".disks.boot.logical_bytes")
|
||||
local root_image_logical_gigabytes=$(((root_image_logical_bytes-1)/1024/1024/1024+1)) # Round to the next GB
|
||||
|
||||
block_device_mappings+=(
|
||||
"DeviceName=/dev/xvdb,Ebs={SnapshotId=$root_snapshot_id,VolumeSize=$root_image_logical_gigabytes,DeleteOnTermination=true,VolumeType=gp3}"
|
||||
)
|
||||
fi
|
||||
|
||||
|
||||
local extra_flags=(
|
||||
--root-device-name /dev/xvda
|
||||
--sriov-net-support simple
|
||||
|
|
Loading…
Reference in a new issue