diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2017-07-11 20:29:39 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2017-07-11 20:29:39 -0300 |
commit | c366547627e794994cfc2333de36e677da19f670 (patch) | |
tree | f6ec0d12d97c7f5dfeaa2a45d50011c8a2cfd9d7 | |
parent | b519ba1e41c58369428a8b74ffc2b313b6ecf054 (diff) | |
download | kvmx-c366547627e794994cfc2333de36e677da19f670.tar.gz kvmx-c366547627e794994cfc2333de36e677da19f670.tar.bz2 |
Implements kvmx_rename and some aliases
-rwxr-xr-x | kvmx | 71 |
1 files changed, 67 insertions, 4 deletions
@@ -760,6 +760,11 @@ function kvmx_clone { fi } +# Alias to clone +function kvmx_copy { + kvmx_clone $* +} + # Edit guest config function kvmx_edit { if [ -z "$EDITOR" ]; then @@ -1075,11 +1080,69 @@ function kvmx_rename { exit 1 fi - echo "TODO" - # Rename folder - # Rename image - # Rename keypair + FOLDER="$3" + DEST="`basename $FOLDER`" + + if [ -z "$FOLDER" ]; then + kvmx_usage + fi + + # If dest is given without a full path, rename to the same basedir + # as the original guest. + if [ "$FOLDER" == "$DEST" ]; then + FOLDER="`dirname $image`" + FOLDER="`dirname $FOLDER`/$DEST" + fi + + # Check if dest machine exists + if [ -e "$GLOBAL_USER_CONFIG_FOLDER/$DEST" ]; then + echo "$BASENAME: destination guest $DEST already exists." + exit 1 + fi + + if [ -d "$FOLDER" ]; then + echo "$BASENAME: destination $FOLDER already exists." + exit 1 + fi + + # Ensure we have an absolute folder name + mkdir -p $FOLDER + FOLDER="`cd $FOLDER &> /dev/null && pwd`" + rmdir $FOLDER + + # Copy image and configuration + echo "Renaming guest..." + mv "`dirname $image`" "$FOLDER" + + # Remove old state folder + rm -rf $FOLDER/state/* + + # Create config entry + ( cd $GLOBAL_USER_CONFIG_FOLDER && ln -s $FOLDER/kvmxfile $DEST ) + + # Remove old kvmxfile + rm $GLOBAL_USER_CONFIG_FOLDER/$VM + # Update config file + new_image="$FOLDER/`basename $image`" + sed -i -e "s|image=\"$image\"|image=\"$new_image\"|g" $FOLDER/kvmxfile + sed -i -e "s|hostname=\"$VM\"|hostname=\"$DEST\"|g" $FOLDER/kvmxfile + + # Rename keypair if exists + if [ -e "$FOLDER/ssh/$VM.key" ]; then + mv $FOLDER/ssh/$VM.key $FOLDER/ssh/$DEST.key + mv $FOLDER/ssh/$VM.key.pub $FOLDER/ssh/$DEST.key.pub + fi +} + +# Alias to rename +function kvmx_move { + kvmx_rename $* +} + +# Alias to rename +function kvmx_mv { + kvmx_rename $* } # Dispatch |