#!/bin/bash
# c5 - Cloud management helper
source "/home/zwelch/src/mcf/mcsh-release/install/share/mcsh/mcsh.sh"
lib_load 'sys/cloud'
######
# Clouds
c5_cloud() { cmd_dispatch "$@"; }
c5_cloud_usage() {
cat <<USAGE
<cmd>
Cloud Management Commands:
create <name> Creates a new cloud
delete <name> Deletes a cloud
Cloud Installation Commands:
install <name> <class> Install packages on cloud hosts
upgrade <name> Upgrade all hosts in cloud
Cloud Backup Commands:
backup <name> <mode> Backs up cloud hosts
restore <name> <mode> Restores cloud hosts
USAGE
}
c5_cloud_list() { cloud_list; }
c5_clouds() { c5_cloud_list "$@"; }
c5_cloud_create() { cloud_create "$@"; }
c5_cloud_delete() { cloud_delete "$@"; }
c5_cloud_install() {
min_args 2 "$@"
local cloud=$1
local class=$2
shift 2
cloud_exists "$cloud" || error "$cloud: does not exist"
case "$class" in
client|server) ;;
*) error "$class: unknown package class" ;;
esac
lib_load 'sys/tool/apt'
apt_install_cloud_class "$cloud" "$class" "$@"
}
c5_cloud_upgrade() {
has_args 1 "$@"
lib_load 'sys/tool/apt'
apt_upgrade_cloud "$1"
}
c5_cloud_backup() {
lib_load 'sys/backup'
backup_cloud "$@"
}
c5_cloud_restore() {
lib_load 'sys/backup'
restore_cloud "$@"
}
######
# Cloud networks
c5_network() { cmd_dispatch "$@"; }
c5_network_usage() {
cat <<USAGE
<cmd>
Cloud Network Commands:
add <name> Adds a host to the cloud
remove <name> Removes a host from the cloud
USAGE
}
######
# Cloud hosts
c5_host() { cmd_dispatch "$@"; }
c5_host_usage() {
cat <<USAGE
<cmd> <name> ...
Cloud Host Commands:
list <cloud> Lists cloud hosts
add <clould> <host>+ Adds hosts to the cloud
remove <cloud> <host>+ Removes hosts from the cloud
enable <cloud> <host>+ Enables hosts in a cloud
disable <cloud> <host>+ Disables hosts in a cloud
USAGE
}
c5_host_add() { cloud_host_add "$@"; }
c5_host_enable() { cloud_host_enable "$@"; }
c5_host_disable() { cloud_host_disable "$@"; }
c5_host_remove() { cloud_host_remove "$@"; }
c5_host_list() { cloud_hosts "$@"; }
c5_hosts() { c5_host_list "$@"; }
######
# Check
c5_check() {
local cloud='c5-test'
local host="${cloud}-host"
c5_cloud_create "$cloud"
c5_host_add "$cloud" "a-$host" "b-$host"
c5_cloud_list
c5_host_list "$cloud"
c5_cloud_backup "$cloud" full
c5_cloud_restore "$cloud" full
c5_host_remove "$cloud" "a-$host" "b-$host"
c5_host_list "$cloud"
c5_cloud_delete "$cloud"
c5_cloud_list
}
######
# Main
c5_desc() { echo "Cloud management helper"; }
c5_usage() {
cat <<USAGE
<cmd>
Cloud Commands:
clouds Lists all clouds
cloud ... Cloud management commands
Host Commands:
hosts <cloud> Lists all hosts for a cloud
host ... Cloud host commands
USAGE
}
app_run "$@"
Generated on Fri Jul 28 14:34:41 PDT 2017 by mcsh d14 v0.23.0.