deploypkg.zsh: Take a list of machines to install on
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
parent
0ca7ac8d86
commit
54d5c4784c
|
@ -2,6 +2,7 @@ import termcolor
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
prefix = sys.argv[1] if len(sys.argv) > 1 else None
|
||||||
pacman_colors = dict()
|
pacman_colors = dict()
|
||||||
pacman_attrs = dict()
|
pacman_attrs = dict()
|
||||||
|
|
||||||
|
@ -13,9 +14,13 @@ add_color_attr("==>", "green", "bold")
|
||||||
add_color_attr("->", "blue", "bold")
|
add_color_attr("->", "blue", "bold")
|
||||||
|
|
||||||
for line in sys.stdin:
|
for line in sys.stdin:
|
||||||
|
if prefix:
|
||||||
|
print(prefix, end=" ")
|
||||||
if "==>" in line or "->" in line:
|
if "==>" in line or "->" in line:
|
||||||
for part in re.split(r'(\s+)', line):
|
for part in re.split(r'(\s+)', line):
|
||||||
color = pacman_colors.get(part, "white")
|
color = pacman_colors.get(part, "white")
|
||||||
attrs = pacman_attrs.get(part, ["bold"])
|
attrs = pacman_attrs.get(part, ["bold"])
|
||||||
|
|
||||||
termcolor.cprint(part, color, attrs=attrs, end="")
|
termcolor.cprint(part, color, attrs=attrs, end="")
|
||||||
|
else:
|
||||||
|
print(line, end="")
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
import sys
|
||||||
|
import termcolor
|
||||||
|
|
||||||
|
VMs = sys.argv[1:]
|
||||||
|
pad = max([ len(vm) for vm in VMs ])
|
||||||
|
colors = [ "green", "yellow", "blue", "magenta", "cyan", "red", "grey", "white" ]
|
||||||
|
|
||||||
|
|
||||||
|
for i, vm in enumerate(sys.argv[1:]):
|
||||||
|
open = termcolor.colored("[", attrs=["bold"])
|
||||||
|
name = termcolor.colored(vm.rjust(pad), colors[i%len(colors)], attrs=["bold"])
|
||||||
|
close = termcolor.colored("]", attrs=["bold"])
|
||||||
|
print(f"{open}{name}{close}")
|
|
@ -3,7 +3,7 @@
|
||||||
function _deploypkg.zsh() {
|
function _deploypkg.zsh() {
|
||||||
_arguments \
|
_arguments \
|
||||||
'1:package:_files -g "**/*.pkg.tar.*"' \
|
'1:package:_files -g "**/*.pkg.tar.*"' \
|
||||||
':destination: _alternative
|
'*:destination: _alternative
|
||||||
"hosts:hosts: _ssh_hosts"
|
"hosts:hosts: _ssh_hosts"
|
||||||
"domains:domains:($(virsh list --all --name))"'
|
"domains:domains:($(virsh list --all --name))"'
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,23 @@
|
||||||
#!/bin/zsh
|
#!/bin/zsh
|
||||||
|
colors="/home/anna/bin/colors"
|
||||||
|
|
||||||
if [ "$#" -ne 2 ]; then
|
if [ "$#" -lt 2 ]; then
|
||||||
echo "Usage: $0 /path/to/package {libvirt VM}"
|
echo "Usage: $0 /path/to/package {remote host, ...}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ssh.zsh $2 "mkdir -p pkg"
|
pkg=$(basename $1)
|
||||||
scp $1 $2:pkg/
|
shift
|
||||||
ssh.zsh $2 "sudo pacman --noconfirm -U pkg/$(basename $1)" | python /home/anna/bin/colors/pacman.py
|
|
||||||
|
function deploy_package() {
|
||||||
|
ssh.zsh $1 "mkdir -pv pkg" 2>&1 | sed -e "s/^/$2 /"
|
||||||
|
script -q -c "scp $pkg $1:pkg/ 2>&1" 2>&1 | sed -e "s/^/$2 /"
|
||||||
|
ssh.zsh $1 "sudo pacman --noconfirm -U pkg/$pkg" | python $colors/pacman.py $2
|
||||||
|
}
|
||||||
|
|
||||||
|
tags=($(python $colors/vm.py $*))
|
||||||
|
for ((i=1; i<=$#; i++)); do
|
||||||
|
deploy_package ${@[i]} ${tags[i]} &
|
||||||
|
done
|
||||||
|
|
||||||
|
wait $(jobs -pr)
|
||||||
|
|
Loading…
Reference in New Issue