Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (3.3 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
    component_desc=${desc[$component]}
46
    component_ex_url=${ex_url[$component]}
47
    echo "Registering the $component_desc ($component):"
48
    echo "Give the URL of $component base installation" \
49
        "(e.g. $component_ex_url)"
50
    echo -n 'Base URL: '
51
    read base_url
52
    echo "Give the URL of the $component UI" \
53
        "(e.g. $(ex_ui_url $base_url))"
54
    echo -n 'UI URL: '
55
    read ui_url
56
    decide "Register $component with the given URLs (y/n)? "
57
    if [ $? -eq 0 ]; then
58
        snf-manage component-add $component $ui_url
59
        if [ $? -eq 0 ]; then
60
            read -p "Please write down the token and press Enter to continue. "
61
            register_services $component $base_url
62
            changed=1
63
            echo
64
        fi
65
    fi
66
}
67

    
68
register_comp_serv () {
69
    component=$1
70
    component_desc=${desc[$component]}
71
    component_ex_url=${ex_url[$component]}
72
    echo "Registering services for $component:"
73
    echo "Give the URL of $component base installation" \
74
        "(e.g. $component_ex_url)"
75
    echo -n 'Base URL: '
76
    read base_url
77
    decide "Register ${component}'s services with the given URL (y/n)? "
78
    if [ $? -eq 0 ]; then
79
        register_services $component $base_url
80
        echo
81
    fi
82
}
83

    
84
components=(astakos cyclades pithos)
85
registered=$(snf-manage component-list --output-format=csv --no-headers |
86
    cut -d ',' -f 2)
87

    
88
register_one () {
89
    component=$1
90
    echo $registered | grep -q -w $component
91
    if [ $? -ne 0 ]; then
92
        decide "Register the ${desc[$component]} ($component) (y/n)? "
93
        if [ $? -eq 0 ]; then
94
            register_component $component
95
        fi
96
    else
97
        echo "The ${desc[$component]} ($component) is registered."
98
        decide "Update its registered services (y/n)? "
99
        if [ $? -eq 0 ]; then
100
            register_comp_serv $component
101
        fi
102
    fi
103
}
104

    
105
# Attempt to register only the specified service
106
if [[ $1 ]]; then
107
    echo ${components[@]} | grep -q -w $1
108
    if [ $? -ne 0 ]; then
109
        echo $1 is not a recognized Synnefo component.
110
        exit
111
    fi
112
    register_one $1
113
else
114
    for component in ${components[@]}; do
115
        register_one $component
116
    done
117
fi
118

    
119
if [ $changed -eq 1 ]; then
120
    echo 'Done with registering services and their resources.'
121
    echo 'Now run '
122
    echo "  snf-manage resource-modify --limit-interactive"
123
    echo 'to specify the default base quota for each resource provided by' \
124
        'the services.'
125
fi