From 32086f62131e1b813e2f3d97bc2c78f66c6a3154 Mon Sep 17 00:00:00 2001 From: Carlos Konstanski Date: Wed, 13 Dec 2017 18:54:21 -0700 Subject: adding files --- files/keypair.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 files/keypair.sh (limited to 'files/keypair.sh') diff --git a/files/keypair.sh b/files/keypair.sh new file mode 100755 index 0000000..0e8374d --- /dev/null +++ b/files/keypair.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +keypair_name="${1}" +pubkey_path="${2}" + +if [ "${keypair_name}" == "" ]; then + echo "No keypair name was supplied." >&2 + exit 1 +elif [ "${pubkey_path}" == "" ]; then + echo "No pubkey path was supplied." >&2 + exit 1 +fi + +keypair_fingerprint=$(openstack keypair list | grep -F "${keypair_name}" | awk '{print $4;}') +if [ "${keypair_fingerprint}" == "" ]; then + if [ "${pubkey_path}" == "" ]; then + echo -n "Need to create an SSH keypair, but no path to a pubkey " >&2 + echo "was supplied." >&2 + exit 1 + elif [ ! -f "${pubkey_path}" ]; then + echo -n "Need to create an SSH keypair, but the supplied path " >&2 + echo "to the pubkey is invalid:" >&2 + echo "${pubkey_path}" >&2 + exit 1 + fi + + openstack keypair create --public-key "${pubkey_path}" "${keypair_name}" + keypair_fingerprint=$(openstack keypair list | grep -F "${keypair_name}" | awk '{print $4;}') + if [ "${keypair_fingerprint}" == "" ]; then + echo "Could not retrieve keypair after creation." >&2 + exit 1 + fi +fi + +exit 0 -- cgit v1.3