dmctl: possibilité d'importer toutes les machines d'un répertoire
This commit is contained in:
parent
b0db9af448
commit
668eec1497
74
dmctl
74
dmctl
|
@ -13,28 +13,14 @@ OPTIONS
|
||||||
-d, --dump
|
-d, --dump
|
||||||
Exporter la machine
|
Exporter la machine
|
||||||
-l, --load
|
-l, --load
|
||||||
Import la machine"
|
Import la machine
|
||||||
|
-a, --load-all
|
||||||
|
Importer toutes les machines"
|
||||||
}
|
}
|
||||||
|
|
||||||
action=
|
function dump_machine() {
|
||||||
args=(
|
local name srcdir workdir destdir archive i
|
||||||
--help '$exit_with display_help'
|
|
||||||
-d,--dump,-x,--export,-s,--save action=dump
|
|
||||||
-l,--load,-i,--import action=load
|
|
||||||
)
|
|
||||||
parse_args "$@"; set -- "${args[@]}"
|
|
||||||
|
|
||||||
if [ -z "$action" ]; then
|
|
||||||
case "$1" in
|
|
||||||
d|dump|x|export|s|save) action=dump; shift;;
|
|
||||||
l|load|i|import) action=load; shift;;
|
|
||||||
*) die "Vous devez spécifier l'action à effectuer";;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$action" in
|
|
||||||
dump)
|
|
||||||
############################################################################
|
|
||||||
name="$1"
|
name="$1"
|
||||||
[ -n "$name" ] || die "Vous devez spécifier le nom de la machine"
|
[ -n "$name" ] || die "Vous devez spécifier le nom de la machine"
|
||||||
|
|
||||||
|
@ -64,10 +50,11 @@ s|DOCKER_MACHINE_HOME/certs/|DOCKER_MACHINE_HOME/machines/$name/|g
|
||||||
tar czf "$archive" -C "$workdir" "$name" || die
|
tar czf "$archive" -C "$workdir" "$name" || die
|
||||||
|
|
||||||
ac_clean "$workdir"
|
ac_clean "$workdir"
|
||||||
;;
|
}
|
||||||
|
|
||||||
|
function load_machine() {
|
||||||
|
local archive archivename destdir machinedir origdir workdir srcdir
|
||||||
|
|
||||||
load)
|
|
||||||
############################################################################
|
|
||||||
archive="$1"
|
archive="$1"
|
||||||
[ -n "$archive" ] || die "Vous devez spécifier l'archive à importer"
|
[ -n "$archive" ] || die "Vous devez spécifier l'archive à importer"
|
||||||
|
|
||||||
|
@ -82,12 +69,17 @@ load)
|
||||||
machinedir="$destdir/$name"
|
machinedir="$destdir/$name"
|
||||||
origdir="$HOME/${name}-machine.orig"
|
origdir="$HOME/${name}-machine.orig"
|
||||||
if [ -d "$machinedir" ]; then
|
if [ -d "$machinedir" ]; then
|
||||||
|
if [ -n "$NOCLOBBER" ]; then
|
||||||
|
ewarn "$name: cette machine existe déjà"
|
||||||
|
return
|
||||||
|
else
|
||||||
ewarn "$name: une machine du même nom existe déjà"
|
ewarn "$name: une machine du même nom existe déjà"
|
||||||
ask_yesno "Voulez-vous l'écraser?" N || die
|
ask_yesno "Voulez-vous l'écraser?" N || die
|
||||||
|
|
||||||
[ -d "$origdir" ] && rm -rf "$origdir"
|
[ -d "$origdir" ] && rm -rf "$origdir"
|
||||||
mv "$machinedir" "$origdir"
|
mv "$machinedir" "$origdir"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
ac_set_tmpdir workdir
|
ac_set_tmpdir workdir
|
||||||
srcdir="$workdir/$name"
|
srcdir="$workdir/$name"
|
||||||
|
@ -112,5 +104,43 @@ s|DOCKER_MACHINE_HOME|$HOME/.docker/machine|g
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ac_clean "$workdir"
|
ac_clean "$workdir"
|
||||||
|
}
|
||||||
|
|
||||||
|
# faut-il ignorer les machines existantes
|
||||||
|
NOCLOBBER=
|
||||||
|
|
||||||
|
action=
|
||||||
|
args=(
|
||||||
|
--help '$exit_with display_help'
|
||||||
|
-d,--dump,-x,--export,-s,--save action=dump
|
||||||
|
-l,--load,-i,--import action=load
|
||||||
|
-a,--all,--load-all,--import-all action=loadall
|
||||||
|
)
|
||||||
|
parse_args "$@"; set -- "${args[@]}"
|
||||||
|
|
||||||
|
if [ -z "$action" ]; then
|
||||||
|
case "$1" in
|
||||||
|
d|dump|x|export|s|save) action=dump; shift;;
|
||||||
|
l|load|i|import) action=load; shift;;
|
||||||
|
a|all|loadall|importall) action=loadall; shift;;
|
||||||
|
*) die "Vous devez spécifier l'action à effectuer";;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$action" in
|
||||||
|
dump) dump_machine "$1";;
|
||||||
|
load) load_machine "$1";;
|
||||||
|
loadall)
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
archives=("$@")
|
||||||
|
else
|
||||||
|
NOCLOBBER=1
|
||||||
|
array_lsfiles archives . "*-machine.tar.gz"
|
||||||
|
fi
|
||||||
|
for archive in "${archives[@]}"; do
|
||||||
|
etitle "$archive"
|
||||||
|
load_machine "$archive"
|
||||||
|
eend
|
||||||
|
done
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in New Issue