root / snf-astakos-app / astakos / scripts / snf-register-components @ 21879b7f
History | View | Annotate | Download (3.1 kB)
1 |
#!/bin/bash |
---|---|
2 |
|
3 |
declare -A types |
4 |
types[astakos]=identity |
5 |
types[cyclades]=compute |
6 |
types[pithos]=storage |
7 |
|
8 |
declare -A desc |
9 |
desc[astakos]='account management component' |
10 |
desc[cyclades]='compute component' |
11 |
desc[pithos]='file storage component' |
12 |
|
13 |
declare -A ex_url |
14 |
ex_url[astakos]='https://accounts.example.synnefo.org/' |
15 |
ex_url[cyclades]='https://compute.example.synnefo.org/compute/' |
16 |
ex_url[pithos]='https://object-store.example.synnefo.org/pithos/' |
17 |
|
18 |
|
19 |
changed=0 |
20 |
|
21 |
register_services () { |
22 |
echo "Registering ${component}'s services and resources..." |
23 |
snf-service-export $component $base_url | snf-manage service-import --json - |
24 |
} |
25 |
|
26 |
ex_ui_url () { |
27 |
echo "$(echo $base_url | sed -e 's/\/*$//g')/ui/" |
28 |
} |
29 |
|
30 |
register_component () { |
31 |
component=$1 |
32 |
component_desc=${desc[$component]} |
33 |
component_ex_url=${ex_url[$component]} |
34 |
echo "Registering the $component_desc ($component):" |
35 |
echo "Give the URL of $component base installation" \ |
36 |
"(e.g. $component_ex_url)" |
37 |
echo -n 'Base URL: ' |
38 |
read base_url |
39 |
echo "Give the URL of the $component UI" \ |
40 |
"(e.g. $(ex_ui_url))" |
41 |
echo -n 'UI URL: ' |
42 |
read ui_url |
43 |
while true; do |
44 |
echo -n "Register $component with the given URLs (y/n)? " |
45 |
read response |
46 |
case $response in |
47 |
[Yy]* ) break;; |
48 |
[Nn]* ) return;; |
49 |
* ) echo "Please answer yes or no.";; |
50 |
esac |
51 |
done |
52 |
snf-manage component-add $component $ui_url |
53 |
if [ $? -eq 0 ]; then |
54 |
read -p "Please write down the token and press Enter to continue. " |
55 |
register_services $1 |
56 |
changed=1 |
57 |
echo |
58 |
fi |
59 |
} |
60 |
|
61 |
components=(astakos cyclades pithos) |
62 |
registered=$(snf-manage component-list --output-format=csv --no-headers | |
63 |
cut -d ',' -f 2) |
64 |
|
65 |
register_all () { |
66 |
flag=0 |
67 |
for component in ${components[@]}; do |
68 |
echo $registered | grep -q -w $component |
69 |
if [ $? -ne 0 ]; then |
70 |
flag=1 |
71 |
while true; do |
72 |
echo -n "Do you want to register the ${desc[$component]}" \ |
73 |
"($component) (y/n)? " |
74 |
read response |
75 |
case $response in |
76 |
[Yy]* ) |
77 |
register_component $component |
78 |
break;; |
79 |
[Nn]* ) |
80 |
break;; |
81 |
* ) echo "Please answer yes or no.";; |
82 |
esac |
83 |
done |
84 |
fi |
85 |
done |
86 |
|
87 |
if [ $flag -eq 0 ]; then |
88 |
echo All standard Synnefo components are already registered. |
89 |
exit |
90 |
fi |
91 |
} |
92 |
|
93 |
# Attempt to register only the specified service |
94 |
if [[ $1 ]]; then |
95 |
echo ${components[@]} | grep -q -w $1 |
96 |
if [ $? -ne 0 ]; then |
97 |
echo $1 is not a recognized Synnefo component. |
98 |
exit |
99 |
fi |
100 |
echo $registered | grep -q -w $1 |
101 |
if [ $? -ne 0 ]; then |
102 |
register_component $1 |
103 |
else |
104 |
echo $1 is already registered. |
105 |
fi |
106 |
else |
107 |
register_all |
108 |
fi |
109 |
|
110 |
if [ $changed -eq 1 ]; then |
111 |
echo 'Done with registering services and their resources.' |
112 |
echo 'Now run ' |
113 |
echo " snf-manage resource-modify --limit-interactive" |
114 |
echo 'to specify the default base quota for each resource provided by' \ |
115 |
'the services.' |
116 |
fi |