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):
if len(args) < 2:
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']:
kwargs['type'] = options['type']
services = list(Service.objects.filter(api_url=kwargs['api_url']))
s = Service.objects.get(name=name)
m = "There already exists service named '%s'." % name
raise CommandError(m)
except Service.DoesNotExist:
services = list(Service.objects.filter(url=url))
if services:
m = "URL '%s' is registered for another service." %\
m = "Service URL '%s' is registered for another service." % 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)
s = Service.objects.create(**kwargs)
except IntegrityError:
m = "There already exists service named '%s'." % kwargs['name']
raise CommandError(m)
except BaseException:
raise CommandError("Failed to create service.")
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