Statistics
| Branch: | Tag: | Revision:

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

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/astakos'
15
ex_url[cyclades]='https://compute.example.synnefo.org/cyclades'
16
ex_url[pithos]='https://storage.example.synnefo.org/pithos'
17

    
18

    
19
register_services () {
20
    echo "Registering ${component}'s services and resources..."
21
    snf-service-export $1 $2 | snf-manage service-import --json -
22
}
23

    
24
ex_ui_url () {
25
    echo "$(echo $1 | sed -e 's/\/*$//g')/ui"
26
}
27

    
28
changed=0
29

    
30
decide () {
31
    while true; do
32
        echo -n "$1"
33
        read response
34
        case $response in
35
            [Yy]* ) return 0;;
36
            [Nn]* ) return 1;;
37
            * ) echo "Please answer yes or no.";;
38
        esac
39
    done
40

    
41
}
42

    
43
register_component () {
44
    component=$1
45
    exists=$2
46
    component_desc=${desc[$component]}
47
    component_ex_url=${ex_url[$component]}
48
    echo "Registering the $component_desc ($component):"
49
    echo "Give the URL of $component base installation" \
50
        "(e.g. $component_ex_url)"
51
    echo -n 'Base URL: '
52
    read base_url
53
    echo "Give the URL of the $component UI" \
54
        "(e.g. $(ex_ui_url $base_url))"
55
    echo -n 'UI URL: '
56
    read ui_url
57
    decide "Register $component with the given URLs (y/n)? "
58
    if [ $? -eq 0 ]; then
59
        if [ $exists -eq 0 ]; then
60
            snf-manage component-add $component --base-url $base_url \
61
                --ui-url $ui_url
62
            if [ $? -eq 0 ]; then
63
                read -p "Please write down the token and press Enter to continue. "
64
                changed=1
65
            fi
66
        else
67
            snf-manage component-modify $component --base-url $base_url \
68
                --ui-url $ui_url --purge-services
69
        fi
70
        register_services $component $base_url
71
    fi
72
}
73

    
74
components=(astakos cyclades pithos)
75
registered=$(snf-manage component-list --output-format=csv --no-headers |
76
    cut -d ',' -f 2)
77

    
78
register_one () {
79
    component=$1
80
    echo $registered | grep -q -w $component
81
    if [ $? -ne 0 ]; then
82
        decide "Register the ${desc[$component]} ($component) (y/n)? "
83
        if [ $? -eq 0 ]; then
84
            register_component $component 0
85
        fi
86
    else
87
        echo "The ${desc[$component]} ($component) is registered."
88
        decide "Re-register (y/n)? "
89
        if [ $? -eq 0 ]; then
90
            register_component $component 1
91
        fi
92
    fi
93
}
94

    
95
# Attempt to register only the specified service
96
if [[ $1 ]]; then
97
    echo ${components[@]} | grep -q -w $1
98
    if [ $? -ne 0 ]; then
99
        echo $1 is not a recognized Synnefo component.
100
        exit
101
    fi
102
    register_one $1
103
else
104
    for component in ${components[@]}; do
105
        register_one $component
106
    done
107
fi
108

    
109
if [ $changed -eq 1 ]; then
110
    echo 'Done with registering services and their resources.'
111
    echo 'Now run '
112
    echo "  snf-manage resource-modify --limit-interactive"
113
    echo 'to specify the default base quota for each resource provided by' \
114
        'the services.'
115
fi