Update vmcreate1.sh
This commit is contained in:
31
vmcreate1.sh
31
vmcreate1.sh
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
show_help()
|
show_help()
|
||||||
echo 'Usage:'
|
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 'Arguments:'
|
||||||
echo '-h - show this help;'
|
echo '-h - show this help;'
|
||||||
echo '-a - add hosts to HA affinity rules;'
|
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 "\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'."
|
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
|
if [ $# -eq 0 ] then
|
||||||
touch hosts.tmp
|
touch hosts.tmp
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
@@ -18,9 +31,9 @@ if [ $# -eq 0 ] then
|
|||||||
if [ $? -eq 0 ] then
|
if [ $? -eq 0 ] then
|
||||||
echo -n "$arg " >> ./hosts.tmp
|
echo -n "$arg " >> ./hosts.tmp
|
||||||
echo $arg | cut -d '.' -f 3,4 | sed 's/\.//' >> hosts.tmp
|
echo $arg | cut -d '.' -f 3,4 | sed 's/\.//' >> hosts.tmp
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
}
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
function ip_check() {
|
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
|
cat $file | while read line
|
||||||
@@ -89,7 +94,7 @@ do
|
|||||||
if [ haadd ]
|
if [ haadd ]
|
||||||
then
|
then
|
||||||
ha-manager add vm:$vmnum --state started --max_relocate 2
|
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
|
fi
|
||||||
echo "HA rules added"
|
echo "HA rules added"
|
||||||
|
|||||||
Reference in New Issue
Block a user