Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / scripts / astakos-register-services @ 2c8ce31f

History | View | Annotate | Download (4.6 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 service'
10
desc[cyclades]='compute service'
11
desc[pithos]='file storage service'
12

    
13
declare -A ex_url
14
ex_url[astakos]='https://accounts.example.synnefo.org/accounts/im/'
15
ex_url[cyclades]='https://cyclades.example.synnefo.org/cyclades/ui/'
16
ex_url[pithos]='https://pithos.example.synnefo.org/pithos/ui/'
17

    
18
declare -A ex_api_url
19
ex_api_url[astakos]='https://accounts.example.synnefo.org/accounts/v1/'
20
ex_api_url[cyclades]='https://cyclades.example.synnefo.org/cyclades/v1/'
21
ex_api_url[pithos]='https://pithos.example.synnefo.org/pithos/v1/'
22

    
23
declare -A resources
24
resources[astakos]='
25
{
26
    "resources": [
27
        {
28
            "allow_in_projects": false,
29
            "name": "astakos.pending_app",
30
            "desc": "Number of pending project applications"
31
        }
32
    ],
33
    "service": "astakos"
34
}'
35

    
36
resources[cyclades]='
37
{
38
    "resources": [
39
        {
40
            "name": "cyclades.vm",
41
            "desc": "Number of virtual machines"
42
        },
43
        {
44
            "name": "cyclades.cpu",
45
            "desc": "Number of virtual machine processors"
46
        },
47
        {
48
            "name": "cyclades.ram",
49
            "unit": "bytes",
50
            "desc": "Virtual machine memory size"
51
        },
52
        {
53
            "name": "cyclades.disk",
54
            "unit": "bytes",
55
            "desc": "Virtual machine disk size"
56
        },
57
        {
58
            "name": "cyclades.network.private",
59
            "desc": "Number of private networks"
60
        }
61
    ],
62
    "service": "cyclades"
63
}'
64

    
65
resources[pithos]='
66
{
67
    "resources": [
68
        {
69
            "name": "pithos.diskspace",
70
            "unit": "bytes",
71
            "desc": "Pithos account diskspace"
72
        }
73
    ],
74
    "service": "pithos"
75
}'
76

    
77
changed=0
78

    
79
register_resources () {
80
    echo "Registering ${service}'s resources..."
81
    fname=/tmp/${service}_resources.json
82
    echo ${resources[$service]} > $fname
83
    snf-manage resource-import --json $fname
84
    rm $fname
85
}
86

    
87
register_service () {
88
    service=$1
89
    service_type=${types[$service]}
90
    service_desc=${desc[$service]}
91
    service_ex_url=${ex_url[$service]}
92
    service_ex_api_url=${ex_api_url[$service]}
93
    echo "Registering the $service_desc ($service):"
94
    echo "Give the URL where the $service UI will reside" \
95
        "(e.g. $service_ex_url)"
96
    echo -n 'Service URL: '
97
    read service_url
98
    echo "Give the URL where the $service API will reside" \
99
        "(e.g. $service_ex_api_url)"
100
    echo -n 'API URL: '
101
    read api_url
102
    while true; do
103
        echo -n "Register $service with the given URLs (y/n)? "
104
        read response
105
        case $response in
106
            [Yy]* ) break;;
107
            [Nn]* ) return;;
108
            * ) echo "Please answer yes or no.";;
109
        esac
110
    done
111
    snf-manage service-add $service -f --type $service_type $service_url $api_url
112
    if [ $? -eq 0 ]; then
113
        read -p "Please write down the token and press Enter to continue. "
114
        register_resources $1
115
        changed=1
116
        echo
117
    fi
118
}
119

    
120
services=(astakos cyclades pithos)
121
registered=$(snf-manage service-list --output-format=csv --no-headers |
122
    cut -d ',' -f 2)
123

    
124
register_all () {
125
    flag=0
126
    for service in ${services[@]}; do
127
        echo $registered | grep -q -w $service
128
        if [ $? -ne 0 ]; then
129
            flag=1
130
            while true; do
131
                echo -n "Do you want to register the ${desc[$service]}" \
132
                    "($service) (y/n)? "
133
                read response
134
                case $response in
135
                    [Yy]* )
136
                        register_service $service
137
                        break;;
138
                    [Nn]* )
139
                        break;;
140
                    * ) echo "Please answer yes or no.";;
141
                esac
142
            done
143
        fi
144
    done
145

    
146
    if [ $flag -eq 0 ]; then
147
        echo All standard Synnefo services are already registered.
148
        exit
149
    fi
150
    }
151

    
152
# Attempt to register only the specified service
153
if [[ $1 ]]; then
154
    echo ${services[@]} | grep -q -w $1
155
    if [ $? -ne 0 ]; then
156
        echo $1 is not a recognized service.
157
        exit
158
    fi
159
    echo $registered | grep -q -w $1
160
    if [ $? -ne 0 ]; then
161
        register_service $1
162
    else
163
        echo $1 is already registered.
164
    fi
165
else
166
    register_all
167
fi
168

    
169
if [ $changed -eq 1 ]; then
170
    echo 'Done with registering services and their resources.'
171
    echo 'Now run '
172
    echo "  snf-manage resource-modify --limit-interactive"
173
    echo 'to specify the default base quota for each resource provided by' \
174
        'the services.'
175
fi