Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / scripts / snf-component-register @ f6ff3033

History | View | Annotate | Download (3.1 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 5bbc6340 Giorgos Korfiatis
ex_url[astakos]='https://accounts.example.synnefo.org/astakos'
15 5bbc6340 Giorgos Korfiatis
ex_url[cyclades]='https://compute.example.synnefo.org/cyclades'
16 5bbc6340 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 5bbc6340 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 eb765213 Giorgos Korfiatis
    exists=$2
46 21879b7f Giorgos Korfiatis
    component_desc=${desc[$component]}
47 21879b7f Giorgos Korfiatis
    component_ex_url=${ex_url[$component]}
48 21879b7f Giorgos Korfiatis
    echo "Registering the $component_desc ($component):"
49 21879b7f Giorgos Korfiatis
    echo "Give the URL of $component base installation" \
50 21879b7f Giorgos Korfiatis
        "(e.g. $component_ex_url)"
51 21879b7f Giorgos Korfiatis
    echo -n 'Base URL: '
52 21879b7f Giorgos Korfiatis
    read base_url
53 21879b7f Giorgos Korfiatis
    echo "Give the URL of the $component UI" \
54 129d3848 Giorgos Korfiatis
        "(e.g. $(ex_ui_url $base_url))"
55 21879b7f Giorgos Korfiatis
    echo -n 'UI URL: '
56 21879b7f Giorgos Korfiatis
    read ui_url
57 129d3848 Giorgos Korfiatis
    decide "Register $component with the given URLs (y/n)? "
58 21879b7f Giorgos Korfiatis
    if [ $? -eq 0 ]; then
59 eb765213 Giorgos Korfiatis
        if [ $exists -eq 0 ]; then
60 eb765213 Giorgos Korfiatis
            snf-manage component-add $component --base-url $base_url \
61 eb765213 Giorgos Korfiatis
                --ui-url $ui_url
62 eb765213 Giorgos Korfiatis
            if [ $? -eq 0 ]; then
63 eb765213 Giorgos Korfiatis
                read -p "Please write down the token and press Enter to continue. "
64 eb765213 Giorgos Korfiatis
                changed=1
65 eb765213 Giorgos Korfiatis
            fi
66 eb765213 Giorgos Korfiatis
        else
67 eb765213 Giorgos Korfiatis
            snf-manage component-modify $component --base-url $base_url \
68 eb765213 Giorgos Korfiatis
                --ui-url $ui_url --purge-services
69 129d3848 Giorgos Korfiatis
        fi
70 129d3848 Giorgos Korfiatis
        register_services $component $base_url
71 21879b7f Giorgos Korfiatis
    fi
72 21879b7f Giorgos Korfiatis
}
73 21879b7f Giorgos Korfiatis
74 21879b7f Giorgos Korfiatis
components=(astakos cyclades pithos)
75 21879b7f Giorgos Korfiatis
registered=$(snf-manage component-list --output-format=csv --no-headers |
76 21879b7f Giorgos Korfiatis
    cut -d ',' -f 2)
77 21879b7f Giorgos Korfiatis
78 129d3848 Giorgos Korfiatis
register_one () {
79 129d3848 Giorgos Korfiatis
    component=$1
80 129d3848 Giorgos Korfiatis
    echo $registered | grep -q -w $component
81 129d3848 Giorgos Korfiatis
    if [ $? -ne 0 ]; then
82 129d3848 Giorgos Korfiatis
        decide "Register the ${desc[$component]} ($component) (y/n)? "
83 129d3848 Giorgos Korfiatis
        if [ $? -eq 0 ]; then
84 eb765213 Giorgos Korfiatis
            register_component $component 0
85 129d3848 Giorgos Korfiatis
        fi
86 129d3848 Giorgos Korfiatis
    else
87 129d3848 Giorgos Korfiatis
        echo "The ${desc[$component]} ($component) is registered."
88 eb765213 Giorgos Korfiatis
        decide "Re-register (y/n)? "
89 129d3848 Giorgos Korfiatis
        if [ $? -eq 0 ]; then
90 eb765213 Giorgos Korfiatis
            register_component $component 1
91 21879b7f Giorgos Korfiatis
        fi
92 21879b7f Giorgos Korfiatis
    fi
93 129d3848 Giorgos Korfiatis
}
94 21879b7f Giorgos Korfiatis
95 21879b7f Giorgos Korfiatis
# Attempt to register only the specified service
96 21879b7f Giorgos Korfiatis
if [[ $1 ]]; then
97 21879b7f Giorgos Korfiatis
    echo ${components[@]} | grep -q -w $1
98 21879b7f Giorgos Korfiatis
    if [ $? -ne 0 ]; then
99 21879b7f Giorgos Korfiatis
        echo $1 is not a recognized Synnefo component.
100 21879b7f Giorgos Korfiatis
        exit
101 21879b7f Giorgos Korfiatis
    fi
102 129d3848 Giorgos Korfiatis
    register_one $1
103 21879b7f Giorgos Korfiatis
else
104 129d3848 Giorgos Korfiatis
    for component in ${components[@]}; do
105 129d3848 Giorgos Korfiatis
        register_one $component
106 129d3848 Giorgos Korfiatis
    done
107 21879b7f Giorgos Korfiatis
fi
108 21879b7f Giorgos Korfiatis
109 21879b7f Giorgos Korfiatis
if [ $changed -eq 1 ]; then
110 21879b7f Giorgos Korfiatis
    echo 'Done with registering services and their resources.'
111 21879b7f Giorgos Korfiatis
    echo 'Now run '
112 21879b7f Giorgos Korfiatis
    echo "  snf-manage resource-modify --limit-interactive"
113 21879b7f Giorgos Korfiatis
    echo 'to specify the default base quota for each resource provided by' \
114 21879b7f Giorgos Korfiatis
        'the services.'
115 21879b7f Giorgos Korfiatis
fi