Commit 7e095c1d authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

astakos: Automate registering components

Add script snf-register-components and helper snf-service-export.
parent 87b9fa74
......@@ -6,101 +6,42 @@ types[cyclades]=compute
types[pithos]=storage
declare -A desc
desc[astakos]='account management service'
desc[cyclades]='compute service'
desc[pithos]='file storage service'
desc[astakos]='account management component'
desc[cyclades]='compute component'
desc[pithos]='file storage component'
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/'
ex_url[astakos]='https://accounts.example.synnefo.org/'
ex_url[cyclades]='https://compute.example.synnefo.org/compute/'
ex_url[pithos]='https://object-store.example.synnefo.org/pithos/'
declare -A ex_api_url
ex_api_url[astakos]='https://accounts.example.synnefo.org/accounts/'
ex_api_url[cyclades]='https://cyclades.example.synnefo.org/cyclades/compute/v1.1/'
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_services () {
echo "Registering ${component}'s services and resources..."
snf-service-export $component $base_url | snf-manage service-import --json -
}
ex_ui_url () {
echo "$(echo $base_url | sed -e 's/\/*$//g')/ui/"
}
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
register_component () {
component=$1
component_desc=${desc[$component]}
component_ex_url=${ex_url[$component]}
echo "Registering the $component_desc ($component):"
echo "Give the URL of $component base installation" \
"(e.g. $component_ex_url)"
echo -n 'Base URL: '
read base_url
echo "Give the URL of the $component UI" \
"(e.g. $(ex_ui_url))"
echo -n 'UI URL: '
read ui_url
while true; do
echo -n "Register $service with the given URLs (y/n)? "
echo -n "Register $component with the given URLs (y/n)? "
read response
case $response in
[Yy]* ) break;;
......@@ -108,32 +49,32 @@ register_service () {
* ) echo "Please answer yes or no.";;
esac
done
snf-manage service-add $service -f --type $service_type $service_url $api_url
snf-manage component-add $component $ui_url
if [ $? -eq 0 ]; then
read -p "Please write down the token and press Enter to continue. "
register_resources $1
register_services $1
changed=1
echo
fi
}
services=(astakos cyclades pithos)
registered=$(snf-manage service-list --output-format=csv --no-headers |
components=(astakos cyclades pithos)
registered=$(snf-manage component-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
for component in ${components[@]}; do
echo $registered | grep -q -w $component
if [ $? -ne 0 ]; then
flag=1
while true; do
echo -n "Do you want to register the ${desc[$service]}" \
"($service) (y/n)? "
echo -n "Do you want to register the ${desc[$component]}" \
"($component) (y/n)? "
read response
case $response in
[Yy]* )
register_service $service
register_component $component
break;;
[Nn]* )
break;;
......@@ -144,21 +85,21 @@ register_all () {
done
if [ $flag -eq 0 ]; then
echo All standard Synnefo services are already registered.
echo All standard Synnefo components are already registered.
exit
fi
}
# Attempt to register only the specified service
if [[ $1 ]]; then
echo ${services[@]} | grep -q -w $1
echo ${components[@]} | grep -q -w $1
if [ $? -ne 0 ]; then
echo $1 is not a recognized service.
echo $1 is not a recognized Synnefo component.
exit
fi
echo $registered | grep -q -w $1
if [ $? -ne 0 ]; then
register_service $1
register_component $1
else
echo $1 is already registered.
fi
......
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'synnefo.settings'
from optparse import OptionParser
from synnefo.lib.services import fill_endpoints, filter_public
from django.utils import simplejson as json
astakos_services = {
'astakos_account': {
'type': 'account',
'component': 'astakos',
'prefix': 'account',
'public': True,
'endpoints': [
{'versionId': 'v1.0',
'publicURL': None},
],
'resources': {
'pending_app': {
'desc': "Number of pending project applications",
'name': "astakos.pending_app",
'service_type': "account",
'service_origin': "astakos_account",
'allow_in_projects': False},
},
},
'astakos_keystone': {
'type': 'identity',
'component': 'astakos',
'prefix': 'identity',
'public': True,
'endpoints': [
{'versionId': 'v2.0',
'publicURL': None},
],
'resources': {},
},
'astakos_ui': {
'type': 'astakos_ui',
'component': 'astakos',
'prefix': 'ui',
'public': False,
'endpoints': [
{'versionId': '',
'publicURL': None},
],
},
}
cyclades_services = {
'cyclades_compute': {
'type': 'compute',
'component': 'cyclades',
'prefix': 'compute',
'public': True,
'endpoints': [
{'versionId': 'v2.0',
'publicURL': None},
],
'resources': {
'vm': {
"name": "cyclades.vm",
"desc": "Number of virtual machines",
"service_type": "compute",
"service_origin": "cyclades_compute",
},
'cpu': {
"name": "cyclades.cpu",
"desc": "Number of virtual machine processors",
"service_type": "compute",
"service_origin": "cyclades_compute",
},
'ram': {
"name": "cyclades.ram",
"desc": "Virtual machine memory size",
"unit": "bytes",
"service_type": "compute",
"service_origin": "cyclades_compute",
},
'disk': {
"name": "cyclades.disk",
"desc": "Virtual machine disk size",
"unit": "bytes",
"service_type": "compute",
"service_origin": "cyclades_compute",
},
'network-private': {
"name": "cyclades.network.private",
"desc": "Number of private networks",
"service_type": "compute",
"service_origin": "cyclades_compute",
},
},
},
'cyclades_plankton': {
'type': 'image',
'component': 'cyclades',
'prefix': 'image',
'public': True,
'endpoints': [
{'versionId': 'v1.0',
'publicURL': None},
],
'resources': {},
},
'cyclades_vmapi': {
'type': 'cyclades_vmapi',
'component': 'cyclades',
'prefix': 'vmapi',
'public': True,
'endpoints': [
{'versionId': 'v1.0',
'publicURL': None},
],
'resources': {},
},
'cyclades_helpdesk': {
'type': 'cyclades_helpdesk',
'component': 'cyclades',
'prefix': 'helpdesk',
'public': False,
'endpoints': [
{'versionId': '',
'publicURL': None},
],
},
'cyclades_userdata': {
'type': 'cyclades_userdata',
'component': 'cyclades',
'prefix': 'userdata',
'public': False,
'endpoints': [
{'versionId': '',
'publicURL': None},
],
'resources': {},
},
'cyclades_ui': {
'type': 'cyclades_ui',
'component': 'cyclades',
'prefix': 'ui',
'public': False,
'endpoints': [
{'versionId': '',
'publicURL': None},
],
'resources': {},
},
}
pithos_services = {
'pithos_object-store': {
'type': 'object-store',
'component': 'pithos',
'prefix': 'object-store',
'public': True,
'endpoints': [
{'versionId': 'v1',
'publicURL': None},
],
'resources': {
'diskspace': {
"desc": "Pithos account diskspace",
"name": "pithos.diskspace",
"unit": "bytes",
"service_type": "object-store",
"service_origin": "pithos_object-store",
},
},
},
'pithos_public': {
'type': 'public',
'component': 'pithos',
'prefix': 'public',
'public': True,
'endpoints': [
{'versionId': 'v2.0',
'publicURL': None},
],
'resources': {},
},
'pithos_ui': {
'type': 'pithos_ui',
'component': 'pithos',
'prefix': 'ui',
'public': False,
'endpoints': [
{'versionId': '',
'publicURL': None},
],
'resources': {},
},
}
definitions = {
'astakos': astakos_services,
'cyclades': cyclades_services,
'pithos': pithos_services,
}
def print_definitions(d, base_url):
fill_endpoints(d, base_url)
print json.dumps(filter_public(d), indent=4)
usage = "usage: %prog <component_name> <base_url>"
parser = OptionParser(usage=usage)
def main():
(options, args) = parser.parse_args()
if len(args) != 2:
parser.error("Wrong number of arguments.")
component = args[0]
try:
services = definitions[component]
except KeyError:
print "Unrecognized component %s" % component
exit(1)
base_url = args[1]
print_definitions(services, base_url)
if __name__ == '__main__':
main()
......@@ -199,7 +199,7 @@ setup(
dependency_links=['http://www.synnefo.org/packages/pypi'],
scripts=['astakos/scripts/astakos-register-services'],
scripts=['astakos/scripts/snf-register-components'],
entry_points={
'synnefo': [
'default_settings = astakos.synnefo_settings',
......@@ -210,7 +210,8 @@ setup(
'web_static = astakos.synnefo_settings:static_files'
],
'console_scripts': [
'astakos-migrate-0.14 = astakos.scripts.upgrade.migrate_014:main'
'astakos-migrate-0.14 = astakos.scripts.upgrade.migrate_014:main',
'snf-service-export = astakos.scripts.snf_service_export:main',
],
}
)
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