Commit 07cb2d04 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

astakos: Fix args reading in service-add

Service URL and API URL where set the other way around.
Also add checks for the URLs being in use.
parent bc3b8a5f
...@@ -53,21 +53,32 @@ class Command(BaseCommand): ...@@ -53,21 +53,32 @@ class Command(BaseCommand):
if len(args) < 2: if len(args) < 2:
raise CommandError("Invalid number of arguments") raise CommandError("Invalid number of arguments")
kwargs = dict(name=args[0], api_url=args[1], url=args[2]) name = args[0]
url = args[1]
api_url = args[2]
kwargs = dict(name=name, url=url, api_url=api_url)
if options['type']: if options['type']:
kwargs['type'] = options['type'] kwargs['type'] = options['type']
services = list(Service.objects.filter(api_url=kwargs['api_url'])) try:
s = Service.objects.get(name=name)
m = "There already exists service named '%s'." % name
raise CommandError(m)
except Service.DoesNotExist:
pass
services = list(Service.objects.filter(url=url))
if services: if services:
m = "URL '%s' is registered for another service." %\ m = "Service URL '%s' is registered for another service." % url
kwargs['api_url'] raise CommandError(m)
services = list(Service.objects.filter(api_url=api_url))
if services:
m = "API URL '%s' is registered for another service." % api_url
raise CommandError(m) raise CommandError(m)
try: try:
s = Service.objects.create(**kwargs) s = Service.objects.create(**kwargs)
except IntegrityError:
m = "There already exists service named '%s'." % kwargs['name']
raise CommandError(m)
except BaseException: except BaseException:
raise CommandError("Failed to create service.") raise CommandError("Failed to create service.")
else: else:
......
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