Commit 1d42c455 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis Committed by Georgios D. Tsoukalas
Browse files

astakos: Automate registration of services

Add script `astakos-register-services' that will help the deployer
register the standard Synnefo services and their resources.
parent 1b469734
#!/bin/bash
declare -A types
types[astakos]=identity
types[cyclades]=compute
types[pithos]=storage
declare -A desc
desc[astakos]='account management service'
desc[cyclades]='compute service'
desc[pithos]='file storage service'
declare -A ex_url
ex_url[astakos]='https://accounts.example.synnefo.org/accounts/im/'
ex_url[cyclades]='https://cyclades.example.synnefo.org/cyclades/ui/'
ex_url[pithos]='https://pithos.example.synnefo.org/pithos/ui/'
declare -A ex_api_url
ex_api_url[astakos]='https://accounts.example.synnefo.org/accounts/v1/'
ex_api_url[cyclades]='https://cyclades.example.synnefo.org/cyclades/v1/'
ex_api_url[pithos]='https://pithos.example.synnefo.org/pithos/v1/'
declare -A resources
resources[astakos]='
{
"resources": [
{
"allow_in_projects": false,
"name": "astakos.pending_app",
"desc": "Number of pending project applications"
}
],
"service": "astakos"
}'
resources[cyclades]='
{
"resources": [
{
"name": "cyclades.vm",
"desc": "Number of virtual machines"
},
{
"name": "cyclades.cpu",
"desc": "Number of virtual machine processors"
},
{
"name": "cyclades.ram",
"unit": "bytes",
"desc": "Virtual machine memory size"
},
{
"name": "cyclades.disk",
"unit": "bytes",
"desc": "Virtual machine disk size"
},
{
"name": "cyclades.network.private",
"desc": "Number of private networks"
}
],
"service": "cyclades"
}'
resources[pithos]='
{
"resources": [
{
"name": "pithos.diskspace",
"unit": "bytes",
"desc": "Pithos account diskspace"
}
],
"service": "pithos"
}'
changed=0
register_resources () {
echo "Registering ${service}'s resources..."
fname=/tmp/${service}_resources.json
echo ${resources[$service]} > $fname
snf-manage resource-import --json $fname
rm $fname
}
register_service () {
service=$1
service_type=${types[$service]}
service_desc=${desc[$service]}
service_ex_url=${ex_url[$service]}
service_ex_api_url=${ex_api_url[$service]}
echo "Registering the $service_desc ($service):"
echo "Give the URL where the $service UI will reside" \
"(e.g. $service_ex_url)"
echo -n 'Service URL: '
read service_url
echo "Give the URL where the $service API will reside" \
"(e.g. $service_ex_api_url)"
echo -n 'API URL: '
read api_url
while true; do
echo -n "Register $service with the given URLs (y/n)? "
read response
case $response in
[Yy]* ) break;;
[Nn]* ) return;;
* ) echo "Please answer yes or no.";;
esac
done
snf-manage service-add $service -f --type $service_type $service_url $api_url
if [ $? -eq 0 ]; then
read -p "Please write down the token and press Enter to continue. "
register_resources $1
changed=1
echo
fi
}
services=(astakos cyclades pithos)
registered=$(snf-manage service-list --output-format=csv --no-headers |
cut -d ',' -f 2)
register_all () {
flag=0
for service in ${services[@]}; do
echo $registered | grep -q -w $service
if [ $? -ne 0 ]; then
flag=1
while true; do
echo -n "Do you want to register the ${desc[$service]}" \
"($service) (y/n)? "
read response
case $response in
[Yy]* )
register_service $service
break;;
[Nn]* )
break;;
* ) echo "Please answer yes or no.";;
esac
done
fi
done
if [ $flag -eq 0 ]; then
echo All standard Synnefo services are already registered.
exit
fi
}
# Attempt to register only the specified service
if [[ $1 ]]; then
echo ${services[@]} | grep -q -w $1
if [ $? -ne 0 ]; then
echo $1 is not a recognized service.
exit
fi
echo $registered | grep -q -w $1
if [ $? -ne 0 ]; then
register_service $1
else
echo $1 is already registered.
fi
else
register_all
fi
if [ $changed -eq 1 ]; then
echo 'Done with registering services and their resources.'
echo 'Now run '
echo " snf-manage resource-modify --limit-interactive"
echo 'to specify the default base quota for each resource provided by' \
'the services.'
fi
......@@ -199,6 +199,7 @@ setup(
dependency_links=['http://www.synnefo.org/packages/pypi'],
scripts=['astakos/scripts/astakos-register-services'],
entry_points={
'synnefo': [
'default_settings = astakos.synnefo_settings',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment