Revision 30096a2e

b/Changelog
32 32
  which is equivalent to 'reconcile-resources-cyclades --fix'.
33 33
* Rename 'cyclades-reconcile-commissions' management command to
34 34
  'reconcile-commissions-cyclades'.
35
* Remove obsolete 'MAX_VMS_PER_USER', 'MAX_NETWORKS_PER_USER',
36
  "VMS_USER_QUOTA" and "NETWORKS_USER_QUOTA" settings, since their usage
37
  is covered by Quotaholder.
35 38

  
36 39

  
37 40
Pithos
b/docs/scale/i-cyclades.rst
45 45
    MAX_CIDR_BLOCK = 21
46 46
    PUBLIC_USE_POOL = True
47 47

  
48
    MAX_VMS_PER_USER = 5
49
    VMS_USER_QUOTA = {
50
        'user@example.com': 20,
51
    }
52
    MAX_NETWORKS_PER_USER = 3
53
    NETWORKS_USER_QUOTA = { 'user@example.com': 10 }
54

  
55 48
    CPU_BAR_GRAPH_URL = 'https://cyclades.example.com/stats/%s/cpu-bar.png'
56 49
    CPU_TIMESERIES_GRAPH_URL = 'https://cyclades.example.com/stats/%s/cpu-ts.png'
57 50
    NET_BAR_GRAPH_URL = 'https://cyclades.example.com/stats/%s/net-bar.png'
b/snf-cyclades-app/conf/20-snf-cyclades-app-api.conf
70 70
## List of backend IDs used *only* for archipelago.
71 71
#ARCHIPELAGO_BACKENDS = []
72 72
#
73
## Quota
74
## Maximum number of VMs a user is allowed to have.
75
#MAX_VMS_PER_USER = 3
76
#
77
## Override maximum number of VMs for specific users.
78
## e.g. VMS_USER_QUOTA = {'user1@grnet.gr': 5, 'user2@grnet.gr': 10}
79
#VMS_USER_QUOTA = {}
80
#
81
## Maximum number of networks a user is allowed to have.
82
#MAX_NETWORKS_PER_USER = 5
83
#
84
## Override maximum number of private networks for specific users.
85
## e.g. NETWORKS_USER_QUOTA = {'user1@grnet.gr': 5, 'user2@grnet.gr': 10}
86
#NETWORKS_USER_QUOTA = {}
87 73
#
88 74
## URL templates for the stat graphs.
89 75
## The API implementation replaces '%s' with the encrypted backend id.
/dev/null
1
# Copyright 2013 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

  
34
from django.core.management.base import NoArgsCommand, CommandError
35
from optparse import make_option
36
from synnefo import settings
37
from os import path
38

  
39

  
40
class Command(NoArgsCommand):
41
    help = "Export account quota policies"
42
    option_list = NoArgsCommand.option_list + (
43
        make_option(
44
            '--location',
45
            dest='location',
46
            default='exported_quota',
47
            help="Where to save the output file"),
48
    )
49

  
50
    def handle_noargs(self, **options):
51
        try:
52
            vms_per_user = settings.VMS_USER_QUOTA
53
            nets_per_user = settings.NETWORKS_USER_QUOTA
54
        except AttributeError as e:
55
            raise CommandError(e)
56
        location = path.abspath(options['location'])
57

  
58
        try:
59
            f = open(location, 'w')
60
        except IOError as e:
61
            raise CommandError(e)
62

  
63
        INF = str(10**30)
64
        for user, value in vms_per_user.items():
65
            f.write(' '.join([user, "cyclades.vm", "%s" % value, '0', INF,
66
                              INF]))
67
            f.write('\n')
68
        for user, value in nets_per_user.items():
69
            f.write(' '.join([user, "cyclades.network.private", "%s" % value,
70
                              '0', INF, INF]))
71
            f.write('\n')
72

  
73
        f.close()
74

  
75
        self.stdout.write("Successfully exported cyclades per-user-quotas to"
76
                          " file '%s'\n" % location)
b/snf-cyclades-app/synnefo/app_settings/default/api.py
70 70
# List of backend IDs used *only* for archipelago.
71 71
ARCHIPELAGO_BACKENDS = []
72 72

  
73
# Quota
74
# Maximum number of VMs a user is allowed to have.
75
MAX_VMS_PER_USER = 3
76

  
77
# Override maximum number of VMs for specific users.
78
# e.g. VMS_USER_QUOTA = {'user1@grnet.gr': 5, 'user2@grnet.gr': 10}
79
VMS_USER_QUOTA = {}
80

  
81
# Maximum number of networks a user is allowed to have.
82
MAX_NETWORKS_PER_USER = 5
83

  
84
# Override maximum number of private networks for specific users.
85
# e.g. NETWORKS_USER_QUOTA = {'user1@grnet.gr': 5, 'user2@grnet.gr': 10}
86
NETWORKS_USER_QUOTA = {}
87 73

  
88 74
# URL templates for the stat graphs.
89 75
# The API implementation replaces '%s' with the encrypted backend id.
b/snf-cyclades-app/synnefo/ui/views.py
258 258
def user_quota(request):
259 259
    get_user(request, settings.ASTAKOS_URL, usage=True)
260 260

  
261
    if request.user and 'usage' in request.user:
262
        response = json.dumps(request.user['usage'])
263
    else:
264
        # hmmm, old astakos ???
265
        # try to mimic astakos response using cyclades quota settings
266
        networks_limit_for_user = \
267
            settings.NETWORKS_USER_QUOTA.get(request.user_uniq,
268
                                             settings.MAX_NETWORKS_PER_USER)
269
        vms_limit_for_user = \
270
            settings.VMS_USER_QUOTA.get(request.user_uniq,
271
                                        settings.MAX_NETWORKS_PER_USER)
272
        usage = [{'name': 'cyclades.vm',
273
                  'maxValue': vms_limit_for_user},
274
                 {'name': 'cyclades.network.private',
275
                  'maxValue': networks_limit_for_user}]
276
        response = json.dumps(usage)
261
    response = json.dumps(request.user['usage'])
277 262

  
278 263
    return HttpResponse(response, mimetype="application/json")
279 264

  

Also available in: Unified diff