aboutsummaryrefslogtreecommitdiffstats
path: root/mcp/scripts/create-config-drive.sh
diff options
context:
space:
mode:
authorMichael Polenchuk <mpolenchuk@mirantis.com>2017-06-29 15:52:28 +0400
committerMichael Polenchuk <mpolenchuk@mirantis.com>2017-07-03 11:18:25 +0400
commite49e91d7aa740437c01e6531ef648d2dae97c11d (patch)
tree4227d9f205f59d5a6a1cdf086ad689dfc4bcb477 /mcp/scripts/create-config-drive.sh
parent3fb5e5454045860463a92c18d4d859967002e6fb (diff)
Rewrite infra deployment scripts
* bring in scenario files * shift infra code into functions Change-Id: I650a26d03d842c3afcc7fcb97b84ef4826827a38 Signed-off-by: Michael Polenchuk <mpolenchuk@mirantis.com>
Diffstat (limited to 'mcp/scripts/create-config-drive.sh')
-rwxr-xr-xmcp/scripts/create-config-drive.sh102
1 files changed, 102 insertions, 0 deletions
diff --git a/mcp/scripts/create-config-drive.sh b/mcp/scripts/create-config-drive.sh
new file mode 100755
index 000000000..df3f72f1f
--- /dev/null
+++ b/mcp/scripts/create-config-drive.sh
@@ -0,0 +1,102 @@
+#!/bin/bash
+
+# This will generate a openstack-style config drive image suitable for
+# use with cloud-init. You may optionally pass in an ssh public key
+# (using the -k/--ssh-key option) and a user-data blog (using the
+# -u/--user-data option).
+
+usage () {
+ echo "usage: ${0##*/}: [--ssh-key <pubkey>] [--vendor-data <file>] [--user-data <file>] [--hostname <hostname>] <imagename>"
+}
+
+ARGS=$(getopt \
+ -o k:u:v:h: \
+ --long help,hostname:,ssh-key:,user-data:,vendor-data: -n ${0##*/} \
+ -- "$@")
+
+if [ $? -ne 0 ]; then
+ usage >&2
+ exit 2
+fi
+
+eval set -- "$ARGS"
+
+while :; do
+ case "$1" in
+ --help)
+ usage
+ exit 0
+ ;;
+ -k|--ssh-key)
+ ssh_key="$2"
+ shift 2
+ ;;
+ -u|--user-data)
+ user_data="$2"
+ shift 2
+ ;;
+ -v|--vendor-data)
+ vendor_data="$2"
+ shift 2
+ ;;
+ -h|--hostname)
+ hostname="$2"
+ shift 2
+ ;;
+ --) shift
+ break
+ ;;
+ esac
+done
+
+config_image=$1
+shift
+
+if [ "$ssh_key" ] && [ -f "$ssh_key" ]; then
+ echo "adding pubkey from $ssh_key"
+ ssh_key_data=$(cat "$ssh_key")
+fi
+
+uuid=$(uuidgen)
+if ! [ "$hostname" ]; then
+ hostname="$uuid"
+fi
+
+trap 'rm -rf $config_dir' EXIT
+config_dir=$(mktemp -t -d configXXXXXX)
+
+if [ "$user_data" ] && [ -f "$user_data" ]; then
+ echo "adding user data from $user_data"
+ cp ${user_data} ${config_dir}/user-data
+else
+ touch $config_dir/user-data
+fi
+
+if [ "$vendor_data" ] && [ -f "$vendor_data" ]; then
+ echo "adding vendor data from $vendor_data"
+ cp ${vendor_data} ${config_dir}/vendor-data
+fi
+
+cat > $config_dir/meta-data <<-EOF
+instance-id: $uuid
+hostname: $hostname
+local-hostname: $hostname
+EOF
+
+if [ "$ssh_key_data" ]; then
+ cat >> $config_dir/meta-data <<-EOF
+ public-keys:
+ - |
+ $ssh_key_data
+ EOF
+fi
+
+#PS1="debug> " bash --norc
+
+echo "generating configuration image at $config_image"
+if ! mkisofs -o $config_image -V cidata -r -J --quiet $config_dir; then
+ echo "ERROR: failed to create $config_image" >&2
+ exit 1
+fi
+chmod a+r $config_image
+