Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / scripts / snf-component-register @ 50f74340

History | View | Annotate | Download (3.3 kB)

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