Revision d8c7557c

b/snf-astakos-app/astakos/im/management/commands/service-add.py
53 53
        if len(args) < 2:
54 54
            raise CommandError("Invalid number of arguments")
55 55

  
56
        kwargs = dict(name=args[0], api_url=args[1], url=args[2])
56
        name = args[0]
57
        url = args[1]
58
        api_url = args[2]
59
        kwargs = dict(name=name, url=url, api_url=api_url)
57 60
        if options['type']:
58 61
            kwargs['type'] = options['type']
59 62

  
60
        services = list(Service.objects.filter(api_url=kwargs['api_url']))
63
        try:
64
            s = Service.objects.get(name=name)
65
            m = "There already exists service named '%s'." % name
66
            raise CommandError(m)
67
        except Service.DoesNotExist:
68
            pass
69

  
70
        services = list(Service.objects.filter(url=url))
61 71
        if services:
62
            m = "URL '%s' is registered for another service." %\
63
                kwargs['api_url']
72
            m = "Service URL '%s' is registered for another service." % url
73
            raise CommandError(m)
74

  
75
        services = list(Service.objects.filter(api_url=api_url))
76
        if services:
77
            m = "API URL '%s' is registered for another service." % api_url
64 78
            raise CommandError(m)
65 79

  
66 80
        try:
67 81
            s = Service.objects.create(**kwargs)
68
        except IntegrityError:
69
            m = "There already exists service named '%s'." % kwargs['name']
70
            raise CommandError(m)
71 82
        except BaseException:
72 83
            raise CommandError("Failed to create service.")
73 84
        else:

Also available in: Unified diff