create-amis.sh: add support for the ZFS AMIs
(cherry picked from commit 46bbf738eaebf82cf59391d38f5a9d77ecf53049)
This commit is contained in:
parent
9e5f907d1d
commit
ff568a49ec
@ -64,10 +64,16 @@ read_image_info() {
|
|||||||
|
|
||||||
# We handle a single image per invocation, store all attributes in
|
# We handle a single image per invocation, store all attributes in
|
||||||
# globals for convenience.
|
# 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_system=$(read_image_info .system)
|
||||||
image_file=$(read_image_info .file)
|
image_files=( $(read_image_info "${zfs_disks:+.disks.root}.file") )
|
||||||
image_logical_bytes=$(read_image_info .logical_bytes)
|
|
||||||
|
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
|
# Derived attributes
|
||||||
|
|
||||||
@ -183,9 +189,15 @@ make_image_public() {
|
|||||||
upload_image() {
|
upload_image() {
|
||||||
local region=$1
|
local region=$1
|
||||||
|
|
||||||
|
for image_file in "${image_files[@]}"; do
|
||||||
local aws_path=${image_file#/}
|
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
|
local task_id
|
||||||
task_id=$(read_state "$state_key" task_id)
|
task_id=$(read_state "$state_key" task_id)
|
||||||
local snapshot_id
|
local snapshot_id
|
||||||
@ -218,6 +230,7 @@ upload_image() {
|
|||||||
snapshot_id=$(wait_for_import "$region" "$task_id")
|
snapshot_id=$(wait_for_import "$region" "$task_id")
|
||||||
write_state "$state_key" snapshot_id "$snapshot_id"
|
write_state "$state_key" snapshot_id "$snapshot_id"
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
if [ -z "$ami_id" ]; then
|
if [ -z "$ami_id" ]; then
|
||||||
log "Registering snapshot $snapshot_id as AMI"
|
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}"
|
"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=(
|
local extra_flags=(
|
||||||
--root-device-name /dev/xvda
|
--root-device-name /dev/xvda
|
||||||
--sriov-net-support simple
|
--sriov-net-support simple
|
||||||
|
Loading…
x
Reference in New Issue
Block a user