Do not regenerate ironic ssh key if one exists
Gets rid of redundant globals and avoids regenerating an ssh key
for ironic if one exists. Also allows key file to be user-specified,
letting ironic use pregenerated keys.
Change-Id: Iaa6f8918bf14dae2116269a0be5039fc5afaecfa
diff --git a/lib/ironic b/lib/ironic
index 0e72f6e..0a0e8b8 100644
--- a/lib/ironic
+++ b/lib/ironic
@@ -60,7 +60,7 @@
IRONIC_SSH_USERNAME=${IRONIC_SSH_USERNAME:-`whoami`}
IRONIC_SSH_KEY_DIR=${IRONIC_SSH_KEY_DIR:-$IRONIC_DATA_DIR/ssh_keys}
IRONIC_SSH_KEY_FILENAME=${IRONIC_SSH_KEY_FILENAME:-ironic_key}
-IRONIC_KEY_FILE=$IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME
+IRONIC_KEY_FILE=${IRONIC_KEY_FILE:-$IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME}
IRONIC_SSH_VIRT_TYPE=${IRONIC_SSH_VIRT_TYPE:-virsh}
IRONIC_TFTPBOOT_DIR=${IRONIC_TFTPBOOT_DIR:-$IRONIC_DATA_DIR/tftpboot}
IRONIC_TFTPSERVER_IP=${IRONIC_TFTPSERVER_IP:-$HOST_IP}
@@ -632,15 +632,16 @@
}
function configure_ironic_ssh_keypair {
- # Generating ssh key pair for stack user
- if [[ ! -d $IRONIC_SSH_KEY_DIR ]]; then
- mkdir -p $IRONIC_SSH_KEY_DIR
- fi
if [[ ! -d $HOME/.ssh ]]; then
mkdir -p $HOME/.ssh
chmod 700 $HOME/.ssh
fi
- echo -e 'n\n' | ssh-keygen -q -t rsa -P '' -f $IRONIC_KEY_FILE
+ if [[ ! -e $IRONIC_KEY_FILE ]]; then
+ if [[ ! -d $(dirname $IRONIC_KEY_FILE) ]]; then
+ mkdir -p $(dirname $IRONIC_KEY_FILE)
+ fi
+ echo -e 'n\n' | ssh-keygen -q -t rsa -P '' -f $IRONIC_KEY_FILE
+ fi
cat $IRONIC_KEY_FILE.pub | tee -a $IRONIC_AUTHORIZED_KEYS_FILE
}
@@ -657,7 +658,7 @@
function configure_ironic_auxiliary {
configure_ironic_ssh_keypair
- ironic_ssh_check $IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME $IRONIC_VM_SSH_ADDRESS $IRONIC_VM_SSH_PORT $IRONIC_SSH_USERNAME 10
+ ironic_ssh_check $IRONIC_KEY_FILE $IRONIC_VM_SSH_ADDRESS $IRONIC_VM_SSH_PORT $IRONIC_SSH_USERNAME 10
}
function build_ipa_coreos_ramdisk {