-
Notifications
You must be signed in to change notification settings - Fork 2
/
ironic-assign.sh
executable file
·59 lines (54 loc) · 1.78 KB
/
ironic-assign.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Filename: ironic-assign.sh
# Description: Assign ironic nodes to $name
# Supported Langauge(s): GNU Bash 4.2.x
# Time-stamp: <2017-11-10 07:48:10 fultonj>
# -------------------------------------------------------
if [[ $# -eq 0 ]] ; then
echo "usage: $0 <REGEX> <NAME> <OPT>"
echo " <REGEX> regex matching the nodes to be tagged; e.g. \"730\" or \"630\""
echo " <NAME> name desired for node; e.g. \"osd-compute\" or \"controller\""
echo " <OPT> opt=1 -> node (default) | opt=2 -> profile | opt=3 -> node+profile"
exit 1
fi
regex=$1
name=$2
var=$3
if [[ ${var:+1} ]] ; then
echo "OPT is $var"
opt=$var
else
echo "Defaulting OPT to 1"
opt=1
fi
source ~/stackrc
echo "Assigning nodes from ironic's list that match $regex"
for id in $(ironic node-list | grep available | awk '{print $2}'); do
match=0;
match=$(ironic node-show $id | egrep $regex | wc -l);
if [[ $match -gt 0 ]]; then
echo $id;
fi
done > /tmp/n_nodes
count=$(cat /tmp/n_nodes | wc -l)
echo "$count nodes match $regex"
i=0
for id in $(cat /tmp/n_nodes); do
node="$name-$i"
if [[ $opt -eq 1 ]]; then
ironic node-update $id replace properties/capabilities=node:$node,boot_option:local
fi
if [[ $opt -eq 2 ]]; then
ironic node-update $id replace properties/capabilities=profile:$name,boot_option:local
fi
if [[ $opt -eq 3 ]]; then
ironic node-update $id replace properties/capabilities=profile:$name,node:$node,boot_option:local
fi
i=$(expr $i + 1)
done
echo "Ironic node properties have been set to the following:"
for ironic_id in $(ironic node-list | awk {'print $2'} | grep -v UUID | egrep -v '^$');
do
echo $ironic_id;
ironic node-show $ironic_id | egrep -A 2 "memory_mb|profile|wwn" ;
echo "";
done