add script easzctl: cluster manage tool

pull/360/head
gjmzj 2018-11-05 12:47:25 +08:00
parent c381639320
commit 320887dab4
2 changed files with 126 additions and 0 deletions

3
.gitignore vendored
View File

@ -20,3 +20,6 @@ roles/cluster-backup/files/*
# role based variable settings, exclude roles/os-harden/vars/ # role based variable settings, exclude roles/os-harden/vars/
/roles/*/vars/* /roles/*/vars/*
!/roles/os-harden/vars/ !/roles/os-harden/vars/
# cluster backups
.cluster/

123
tools/easzctl 100755
View File

@ -0,0 +1,123 @@
#!/bin/bash
#
# This script can be used to manage multiple k8s clusters. (unfinished)
set -o nounset
set -o errexit
#set -o xtrace
function process_cmd {
echo "$ACTION : $CMD"
$CMD
if [[ $? -ne 0 ]]; then
echo "Command failed $CMD"
exit 1
fi
}
function usage {
cat <<EOF
Usage: $0 COMMAND [args]
Commands:
backup To backup the current cluster (data and config)
checkout <name> To checkout and to use the chosen cluster context
create <name> To create a new cluster and to checkout the new cluster
delete To delete the current cluster (keeping backups)
destroy To delete the current cluster and its backups
help To display usage
list To list the existing cluster names
rename <oldname> <newname> To rename an existing cluster's name
restore To restore the current cluster from backups
test To do some smoke tests on the current cluster
untest To remove smoke tests on the current cluster
upgrade Upgrades the current kubernetes cluster
EOF
}
function cp_role_conf {
ROLESPATH=$BASEPATH/../roles
for ROLE in $(ls $ROLESPATH);
do
if [ -d "$ROLESPATH/$ROLE/defaults" ]; then
mkdir -p $BASEPATH/../.cluster/$CLUSTERNAME/$ROLE/defaults/
cp -rp $ROLESPATH/$ROLE/defaults/* $BASEPATH/../.cluster/$CLUSTERNAME/$ROLE/defaults/
fi
done;
}
function init {
if [ ! -d "$BASEPATH/../.cluster" ]; then
mkdir -p $BASEPATH/../.cluster
CLUSTERNAME=default
cp_role_conf
fi
}
###############################################################
BASEPATH=$(cd `dirname $0`; pwd)
init
[ "$#" -gt 0 ] || { usage >&2; exit 2; }
case "$1" in
(backup)
ACTION="action backup"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=precheck"
;;
(checkout)
ACTION="action checkout"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(create)
ACTION="action create"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=deploy -e common_run=true"
PLAYBOOK="${BASEDIR}/ansible/mariadb_recovery.yml"
;;
(delete)
ACTION="action delete"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(destroy)
ACTION="action destroy"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(help)
usage
;;
(list)
ACTION="action list"
CMD="ls $BASEPATH/../.cluster"
process_cmd
;;
(rename)
ACTION="action rename"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(restore)
ACTION="action restore"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(test)
ACTION="action test"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(untest)
ACTION="action untest"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(upgrade)
ACTION="action upgrade"
EXTRA_OPTS="$EXTRA_OPTS -e kolla_action=check"
;;
(*)
usage
exit 0
;;
esac
#CMD="echo $BASEPATH $ACTION"
#process_cmd