Update vmcreate1.sh
This commit is contained in:
31
vmcreate1.sh
31
vmcreate1.sh
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
show_help()
|
||||
echo 'Usage:'
|
||||
echo 'vmcreate [-h][-a][-k pub_keyfile][-f filename]'
|
||||
echo 'vmcreate [-h][-a rule_name][-k pub_keyfile][-f filename]'
|
||||
echo 'Arguments:'
|
||||
echo '-h - show this help;'
|
||||
echo '-a - add hosts to HA affinity rules;'
|
||||
@@ -10,7 +10,20 @@ show_help()
|
||||
echo "\nIf file not specified, script will use arguments as a list of IP addresses."
|
||||
echo "In this case Hostname will be inherited from 2 last IP octets. Example for 10.10.35.20: 'vm035020'."
|
||||
|
||||
make_file (){
|
||||
# Обрабатываем опции
|
||||
while getopts "a:f:h" opt; do
|
||||
case $opt in
|
||||
a) haadd=true; ;;
|
||||
f) file="$OPTARG" ;;
|
||||
h) show_help ; exit 0;;
|
||||
*) noopts=true
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -f $file ]; then echo "File $file does not exist."; exit 1
|
||||
if [ noargs ]
|
||||
|
||||
# Если нет аргументов, то создаем временный файл
|
||||
if [ $# -eq 0 ] then
|
||||
touch hosts.tmp
|
||||
for arg in "$@"; do
|
||||
@@ -18,9 +31,9 @@ if [ $# -eq 0 ] then
|
||||
if [ $? -eq 0 ] then
|
||||
echo -n "$arg " >> ./hosts.tmp
|
||||
echo $arg | cut -d '.' -f 3,4 | sed 's/\.//' >> hosts.tmp
|
||||
done
|
||||
fi
|
||||
}
|
||||
done
|
||||
fi
|
||||
|
||||
function ip_check() {
|
||||
# Функция написана гуглом
|
||||
@@ -56,14 +69,6 @@ embed_key(){
|
||||
}
|
||||
|
||||
|
||||
while getopts "a:f:h" opt; do
|
||||
case $opt in
|
||||
a) haadd=true ;;
|
||||
f) file="$OPTARG" ;;
|
||||
h) show_help ; exit 0;;
|
||||
*) noargs=true
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
cat $file | while read line
|
||||
@@ -89,7 +94,7 @@ do
|
||||
if [ haadd ]
|
||||
then
|
||||
ha-manager add vm:$vmnum --state started --max_relocate 2
|
||||
ha-manager rules add node-affinity gfx-rule --resources vm:$vmnum --nodes pve1,pve2,pve3 --strict 1
|
||||
ha-manager rules add node-affinity $ha_rule --resources vm:$vmnum --nodes pve1,pve2,pve3 --strict 1
|
||||
# ОБЯЗАТЕЛЬНО ПРОВЕРИТЬ КОМАНДУ!!!
|
||||
fi
|
||||
echo "HA rules added"
|
||||
|
||||
Reference in New Issue
Block a user