Revision 21879b7f

/dev/null
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/'
20
ex_api_url[cyclades]='https://cyclades.example.synnefo.org/cyclades/compute/v1.1/'
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
b/snf-astakos-app/astakos/scripts/snf-register-components
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/'
15
ex_url[cyclades]='https://compute.example.synnefo.org/compute/'
16
ex_url[pithos]='https://object-store.example.synnefo.org/pithos/'
17

  
18

  
19
changed=0
20

  
21
register_services () {
22
    echo "Registering ${component}'s services and resources..."
23
    snf-service-export $component $base_url | snf-manage service-import --json -
24
}
25

  
26
ex_ui_url () {
27
    echo "$(echo $base_url | sed -e 's/\/*$//g')/ui/"
28
}
29

  
30
register_component () {
31
    component=$1
32
    component_desc=${desc[$component]}
33
    component_ex_url=${ex_url[$component]}
34
    echo "Registering the $component_desc ($component):"
35
    echo "Give the URL of $component base installation" \
36
        "(e.g. $component_ex_url)"
37
    echo -n 'Base URL: '
38
    read base_url
39
    echo "Give the URL of the $component UI" \
40
        "(e.g. $(ex_ui_url))"
41
    echo -n 'UI URL: '
42
    read ui_url
43
    while true; do
44
        echo -n "Register $component with the given URLs (y/n)? "
45
        read response
46
        case $response in
47
            [Yy]* ) break;;
48
            [Nn]* ) return;;
49
            * ) echo "Please answer yes or no.";;
50
        esac
51
    done
52
    snf-manage component-add $component $ui_url
53
    if [ $? -eq 0 ]; then
54
        read -p "Please write down the token and press Enter to continue. "
55
        register_services $1
56
        changed=1
57
        echo
58
    fi
59
}
60

  
61
components=(astakos cyclades pithos)
62
registered=$(snf-manage component-list --output-format=csv --no-headers |
63
    cut -d ',' -f 2)
64

  
65
register_all () {
66
    flag=0
67
    for component in ${components[@]}; do
68
        echo $registered | grep -q -w $component
69
        if [ $? -ne 0 ]; then
70
            flag=1
71
            while true; do
72
                echo -n "Do you want to register the ${desc[$component]}" \
73
                    "($component) (y/n)? "
74
                read response
75
                case $response in
76
                    [Yy]* )
77
                        register_component $component
78
                        break;;
79
                    [Nn]* )
80
                        break;;
81
                    * ) echo "Please answer yes or no.";;
82
                esac
83
            done
84
        fi
85
    done
86

  
87
    if [ $flag -eq 0 ]; then
88
        echo All standard Synnefo components are already registered.
89
        exit
90
    fi
91
    }
92

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

  
110
if [ $changed -eq 1 ]; then
111
    echo 'Done with registering services and their resources.'
112
    echo 'Now run '
113
    echo "  snf-manage resource-modify --limit-interactive"
114
    echo 'to specify the default base quota for each resource provided by' \
115
        'the services.'
116
fi
b/snf-astakos-app/astakos/scripts/snf_service_export.py
1
import os
2
os.environ['DJANGO_SETTINGS_MODULE'] = 'synnefo.settings'
3
from optparse import OptionParser
4
from synnefo.lib.services import fill_endpoints, filter_public
5
from django.utils import simplejson as json
6

  
7

  
8
astakos_services = {
9
    'astakos_account': {
10
        'type': 'account',
11
        'component': 'astakos',
12
        'prefix': 'account',
13
        'public': True,
14
        'endpoints': [
15
            {'versionId': 'v1.0',
16
             'publicURL': None},
17
        ],
18
        'resources': {
19
            'pending_app': {
20
                'desc': "Number of pending project applications",
21
                'name': "astakos.pending_app",
22
                'service_type': "account",
23
                'service_origin': "astakos_account",
24
                'allow_in_projects': False},
25
        },
26
    },
27

  
28
    'astakos_keystone': {
29
        'type': 'identity',
30
        'component': 'astakos',
31
        'prefix': 'identity',
32
        'public': True,
33
        'endpoints': [
34
            {'versionId': 'v2.0',
35
             'publicURL': None},
36
        ],
37
        'resources': {},
38
    },
39

  
40
    'astakos_ui': {
41
        'type': 'astakos_ui',
42
        'component': 'astakos',
43
        'prefix': 'ui',
44
        'public': False,
45
        'endpoints': [
46
            {'versionId': '',
47
             'publicURL': None},
48
        ],
49
    },
50
}
51

  
52
cyclades_services = {
53
    'cyclades_compute': {
54
        'type': 'compute',
55
        'component': 'cyclades',
56
        'prefix': 'compute',
57
        'public': True,
58
        'endpoints': [
59
            {'versionId': 'v2.0',
60
             'publicURL': None},
61
        ],
62
        'resources': {
63
            'vm': {
64
                "name": "cyclades.vm",
65
                "desc": "Number of virtual machines",
66
                "service_type": "compute",
67
                "service_origin": "cyclades_compute",
68
            },
69
            'cpu': {
70
                "name": "cyclades.cpu",
71
                "desc": "Number of virtual machine processors",
72
                "service_type": "compute",
73
                "service_origin": "cyclades_compute",
74
            },
75
            'ram': {
76
                "name": "cyclades.ram",
77
                "desc": "Virtual machine memory size",
78
                "unit": "bytes",
79
                "service_type": "compute",
80
                "service_origin": "cyclades_compute",
81
            },
82
            'disk': {
83
                "name": "cyclades.disk",
84
                "desc": "Virtual machine disk size",
85
                "unit": "bytes",
86
                "service_type": "compute",
87
                "service_origin": "cyclades_compute",
88
            },
89
            'network-private': {
90
                "name": "cyclades.network.private",
91
                "desc": "Number of private networks",
92
                "service_type": "compute",
93
                "service_origin": "cyclades_compute",
94
            },
95
        },
96
    },
97

  
98
    'cyclades_plankton': {
99
        'type': 'image',
100
        'component': 'cyclades',
101
        'prefix': 'image',
102
        'public': True,
103
        'endpoints': [
104
            {'versionId': 'v1.0',
105
             'publicURL': None},
106
        ],
107
        'resources': {},
108
    },
109

  
110
    'cyclades_vmapi': {
111
        'type': 'cyclades_vmapi',
112
        'component': 'cyclades',
113
        'prefix': 'vmapi',
114
        'public': True,
115
        'endpoints': [
116
            {'versionId': 'v1.0',
117
             'publicURL': None},
118
        ],
119
        'resources': {},
120
    },
121

  
122
    'cyclades_helpdesk': {
123
        'type': 'cyclades_helpdesk',
124
        'component': 'cyclades',
125
        'prefix': 'helpdesk',
126
        'public': False,
127
        'endpoints': [
128
            {'versionId': '',
129
             'publicURL': None},
130
        ],
131
    },
132

  
133
    'cyclades_userdata': {
134
        'type': 'cyclades_userdata',
135
        'component': 'cyclades',
136
        'prefix': 'userdata',
137
        'public': False,
138
        'endpoints': [
139
            {'versionId': '',
140
             'publicURL': None},
141
        ],
142
        'resources': {},
143
    },
144

  
145
    'cyclades_ui': {
146
        'type': 'cyclades_ui',
147
        'component': 'cyclades',
148
        'prefix': 'ui',
149
        'public': False,
150
        'endpoints': [
151
            {'versionId': '',
152
             'publicURL': None},
153
        ],
154
        'resources': {},
155
    },
156
}
157

  
158
pithos_services = {
159
    'pithos_object-store': {
160
        'type': 'object-store',
161
        'component': 'pithos',
162
        'prefix': 'object-store',
163
        'public': True,
164
        'endpoints': [
165
            {'versionId': 'v1',
166
             'publicURL': None},
167
        ],
168
        'resources': {
169
            'diskspace': {
170
                "desc": "Pithos account diskspace",
171
                "name": "pithos.diskspace",
172
                "unit": "bytes",
173
                "service_type": "object-store",
174
                "service_origin": "pithos_object-store",
175
            },
176
        },
177
    },
178

  
179
    'pithos_public': {
180
        'type': 'public',
181
        'component': 'pithos',
182
        'prefix': 'public',
183
        'public': True,
184
        'endpoints': [
185
            {'versionId': 'v2.0',
186
             'publicURL': None},
187
        ],
188
        'resources': {},
189
    },
190

  
191
    'pithos_ui': {
192
        'type': 'pithos_ui',
193
        'component': 'pithos',
194
        'prefix': 'ui',
195
        'public': False,
196
        'endpoints': [
197
            {'versionId': '',
198
             'publicURL': None},
199
        ],
200
        'resources': {},
201
    },
202
}
203

  
204

  
205
definitions = {
206
    'astakos': astakos_services,
207
    'cyclades': cyclades_services,
208
    'pithos': pithos_services,
209
}
210

  
211

  
212
def print_definitions(d, base_url):
213
    fill_endpoints(d, base_url)
214
    print json.dumps(filter_public(d), indent=4)
215

  
216

  
217
usage = "usage: %prog <component_name> <base_url>"
218
parser = OptionParser(usage=usage)
219

  
220

  
221
def main():
222
    (options, args) = parser.parse_args()
223
    if len(args) != 2:
224
        parser.error("Wrong number of arguments.")
225
    component = args[0]
226
    try:
227
        services = definitions[component]
228
    except KeyError:
229
        print "Unrecognized component %s" % component
230
        exit(1)
231
    base_url = args[1]
232
    print_definitions(services, base_url)
233

  
234
if __name__ == '__main__':
235
    main()
b/snf-astakos-app/setup.py
199 199

  
200 200
    dependency_links=['http://www.synnefo.org/packages/pypi'],
201 201

  
202
    scripts=['astakos/scripts/astakos-register-services'],
202
    scripts=['astakos/scripts/snf-register-components'],
203 203
    entry_points={
204 204
        'synnefo': [
205 205
            'default_settings = astakos.synnefo_settings',
......
210 210
            'web_static = astakos.synnefo_settings:static_files'
211 211
        ],
212 212
        'console_scripts': [
213
            'astakos-migrate-0.14 = astakos.scripts.upgrade.migrate_014:main'
213
            'astakos-migrate-0.14 = astakos.scripts.upgrade.migrate_014:main',
214
            'snf-service-export = astakos.scripts.snf_service_export:main',
214 215
        ],
215 216
    }
216 217
)

Also available in: Unified diff