Commit eae82002 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

astakos: Store base URL in component

Deployer should provide it when adding a new component. Service endpoints
originating from a component are expected to match its base URL; otherwise,
a warning is issued during service registration. Re-registration with
`snf-component-register' affects both the base and the ui URLs.

`component-list' now lists by default the base URL.
parent 97602dd9
......@@ -30,6 +30,16 @@ Astakos
* Implement API calls for projects.
* Store the base URL of a component. Deployer should provide it when adding
a new component. Service endpoints originating from a component are
expected to match its base URL; otherwise, a warning is issued.
Re-registration with `snf-component-register' affects both the base and
the ui URL.
* Management commands:
* Changed commands:
* component-add got options --base-url and --ui-url
Cyclades
--------
......
......@@ -917,9 +917,9 @@ offered by the services.
.. code-block:: console
astakos-host$ snf-manage component-add astakos astakos_ui_url
astakos-host$ snf-manage component-add cyclades cyclades_ui_url
astakos-host$ snf-manage component-add pithos pithos_ui_url
astakos-host$ snf-manage component-add astakos --base-url astakos_base_url --ui-url astakos_ui_url
astakos-host$ snf-manage component-add cyclades --base-url cyclades_base_url --ui-url cyclades_ui_url
astakos-host$ snf-manage component-add pithos --base-url pithos_base_url --ui-url pithos_ui_url
astakos-host$ snf-manage service-export-astakos > astakos.json
astakos-host$ snf-manage service-import --json astakos.json
cyclades-host$ snf-manage service-export-cyclades > cyclades.json
......
......@@ -7,7 +7,9 @@ The upgrade to v0.15 consists in the following steps:
2. Upgrade packages, migrate the databases and configure settings.
3. Bring up all services.
3. Re-register components and services in astakos.
4. Bring up all services.
.. warning::
......@@ -100,7 +102,19 @@ The upgrade to v0.15 consists in the following steps:
pithos-host$ pithos-migrate upgrade head
3. Bring all services up
3. Re-register components and services in astakos
=================================================
Component registration has changed; you will thus need to repeat the
process. On the astakos node, run::
astakos-host$ snf-component-register
This will detect that the Synnefo components are already registered and ask
to re-register. Answer positively. You need to enter the base URL and the UI
URL for each component, just like during the initial registration.
4. Bring all services up
========================
After the upgrade is finished, we bring up all services:
......
......@@ -31,34 +31,44 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from astakos.im.models import Component
class Command(BaseCommand):
args = "<name> <component URL>"
args = "<name>"
help = "Register a component"
option_list = BaseCommand.option_list + (
make_option('--ui-url',
dest='ui_url',
default=None,
help="Set UI URL"),
make_option('--base-url',
dest='base_url',
default=None,
help="Set base URL"),
)
def handle(self, *args, **options):
if len(args) < 2:
if len(args) != 1:
raise CommandError("Invalid number of arguments")
name = args[0]
url = args[1]
base_url = options['base_url']
ui_url = options['ui_url']
try:
s = Component.objects.get(name=name)
Component.objects.get(name=name)
m = "There already exists a component named '%s'." % name
raise CommandError(m)
except Component.DoesNotExist:
pass
components = list(Component.objects.filter(url=url))
if components:
m = "Component URL '%s' is registered for another service." % url
raise CommandError(m)
try:
c = Component.objects.create(name=name, url=url)
c = Component.objects.create(
name=name, url=ui_url, base_url=base_url)
except BaseException:
raise CommandError("Failed to register component.")
else:
......
......@@ -42,9 +42,10 @@ class Command(ListCommand):
FIELDS = {
"id": ("id", "Component ID"),
"name": ("name", "Component Name"),
"url": ("url", "Component URL"),
"base url": ("base_url", "Component base URL"),
"ui url": ("url", "Component UI URL"),
"token": ("auth_token", "Authentication token"),
"token created": ("auth_token_created", "Token creation date"),
}
fields = ["id", "name", "url", "token"]
fields = ["id", "name", "base url"]
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -43,10 +43,13 @@ class Command(BaseCommand):
help = "Modify component attributes"
option_list = BaseCommand.option_list + (
make_option('--url',
dest='url',
make_option('--ui-url',
dest='ui_url',
default=None,
help="Set component url"),
help="Set UI URL"),
make_option('--base-url',
dest='base_url',
help="Set base URL"),
make_option('--auth-token',
dest='auth_token',
default=None,
......@@ -79,16 +82,21 @@ class Command(BaseCommand):
"Component does not exist. You may run snf-manage "
"component-list for available component IDs.")
url = options.get('url')
ui_url = options.get('ui_url')
base_url = options.get('base_url')
auth_token = options.get('auth_token')
renew_token = options.get('renew_token')
purge_services = options.get('purge_services')
if not any([url, auth_token, renew_token, purge_services]):
if not any([ui_url, base_url, auth_token, renew_token,
purge_services]):
raise CommandError("No option specified.")
if url:
component.url = url
if ui_url:
component.url = ui_url
if base_url:
component.base_url = base_url
if auth_token:
component.auth_token = auth_token
......
......@@ -90,7 +90,8 @@ class Command(BaseCommand):
raise CommandError(m)
try:
existed = add_service(component, name, service_type, endpoints)
existed = add_service(component, name, service_type, endpoints,
out=self.stdout)
except RegisterException as e:
raise CommandError(e.message)
......
......@@ -124,6 +124,7 @@ class Component(models.Model):
db_index=True)
url = models.CharField(_('Component url'), max_length=1024, null=True,
help_text=_("URL the component is accessible from"))
base_url = models.CharField(max_length=1024, null=True)
auth_token = models.CharField(_('Authentication Token'), max_length=64,
null=True, blank=True, unique=True)
auth_token_created = models.DateTimeField(_('Token creation date'),
......
......@@ -121,14 +121,19 @@ def get_resources(resources=None, services=None):
return resource_dict
def add_endpoint(service, endpoint_dict):
def add_endpoint(component, service, endpoint_dict, out=None):
endpoint = Endpoint.objects.create(service=service)
for key, value in endpoint_dict.iteritems():
base_url = component.base_url
if key == "publicURL" and not value.startswith(base_url):
warn = out.write if out is not None else logger.warning
warn("Warning: Endpoint URL '%s' does not start with "
"assumed component base URL '%s'.\n" % (value, base_url))
EndpointData.objects.create(
endpoint=endpoint, key=key, value=value)
def add_service(component, name, service_type, endpoints):
def add_service(component, name, service_type, endpoints, out=None):
defaults = {'component': component,
'type': service_type,
}
......@@ -146,6 +151,6 @@ def add_service(component, name, service_type, endpoints):
service.save()
for endpoint in endpoints:
add_endpoint(service, endpoint)
add_endpoint(component, service, endpoint, out=out)
return not created
......@@ -42,6 +42,7 @@ decide () {
register_component () {
component=$1
exists=$2
component_desc=${desc[$component]}
component_ex_url=${ex_url[$component]}
echo "Registering the $component_desc ($component):"
......@@ -55,29 +56,18 @@ register_component () {
read ui_url
decide "Register $component with the given URLs (y/n)? "
if [ $? -eq 0 ]; then
snf-manage component-add $component $ui_url
if [ $? -eq 0 ]; then
read -p "Please write down the token and press Enter to continue. "
register_services $component $base_url
changed=1
echo
if [ $exists -eq 0 ]; then
snf-manage component-add $component --base-url $base_url \
--ui-url $ui_url
if [ $? -eq 0 ]; then
read -p "Please write down the token and press Enter to continue. "
changed=1
fi
else
snf-manage component-modify $component --base-url $base_url \
--ui-url $ui_url --purge-services
fi
fi
}
register_comp_serv () {
component=$1
component_desc=${desc[$component]}
component_ex_url=${ex_url[$component]}
echo "Registering services for $component:"
echo "Give the URL of $component base installation" \
"(e.g. $component_ex_url)"
echo -n 'Base URL: '
read base_url
decide "Register ${component}'s services with the given URL (y/n)? "
if [ $? -eq 0 ]; then
register_services $component $base_url
echo
fi
}
......@@ -91,13 +81,13 @@ register_one () {
if [ $? -ne 0 ]; then
decide "Register the ${desc[$component]} ($component) (y/n)? "
if [ $? -eq 0 ]; then
register_component $component
register_component $component 0
fi
else
echo "The ${desc[$component]} ($component) is registered."
decide "Update its registered services (y/n)? "
decide "Re-register (y/n)? "
if [ $? -eq 0 ]; then
register_comp_serv $component
register_component $component 1
fi
fi
}
......
......@@ -600,15 +600,15 @@ def astakos_loaddata():
def astakos_register_components():
debug(env.host, " * Register services in astakos...")
cyclades_base_url = "https://%s/cyclades/" % env.env.cyclades.fqdn
pithos_base_url = "https://%s/pithos/" % env.env.pithos.fqdn
astakos_base_url = "https://%s/astakos/" % env.env.accounts.fqdn
cyclades_base_url = "https://%s/cyclades" % env.env.cyclades.fqdn
pithos_base_url = "https://%s/pithos" % env.env.pithos.fqdn
astakos_base_url = "https://%s/astakos" % env.env.accounts.fqdn
cmd = """
snf-manage component-add "home" https://{0} home-icon.png
snf-manage component-add "cyclades" {1}ui/
snf-manage component-add "pithos" {2}ui/
snf-manage component-add "astakos" {3}ui/
snf-manage component-add "home" --ui-url https://{0}
snf-manage component-add "cyclades" --base-url {1} --ui-url {1}/ui
snf-manage component-add "pithos" --base-url {2} --ui-url {2}/ui
snf-manage component-add "astakos" --base-url {3} --ui-url {3}/ui
""".format(env.env.cms.fqdn, cyclades_base_url,
pithos_base_url, astakos_base_url)
try_run(cmd)
......
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