Revision 4161cb70

b/snf-astakos-app/astakos/im/forms.py
65 65
    PASSWORD_RESET_EMAIL_SUBJECT, NEWPASSWD_INVALIDATE_TOKEN,
66 66
    MODERATION_ENABLED, PROJECT_MEMBER_JOIN_POLICIES,
67 67
    PROJECT_MEMBER_LEAVE_POLICIES, EMAILCHANGE_ENABLED,
68
    RESOURCES_PRESENTATION_DATA)
68
    )
69
from astakos.im.presentation import RESOURCES_PRESENTATION_DATA
69 70
from astakos.im.widgets import DummyWidget, RecaptchaWidget
70 71
from astakos.im.functions import (
71 72
    send_change_email, submit_application, accept_membership_checks)
/dev/null
1
# encoding: utf-8
2

  
3
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
4
#
5
# Redistribution and use in source and binary forms, with or
6
# without modification, are permitted provided that the following
7
# conditions are met:
8
#
9
#   1. Redistributions of source code must retain the above
10
#      copyright notice, this list of conditions and the following
11
#      disclaimer.
12
#
13
#   2. Redistributions in binary form must reproduce the above
14
#      copyright notice, this list of conditions and the following
15
#      disclaimer in the documentation and/or other materials
16
#      provided with the distribution.
17
#
18
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
19
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
22
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
# POSSIBILITY OF SUCH DAMAGE.
30
#
31
# The views and conclusions contained in the software and
32
# documentation are those of the authors and should not be
33
# interpreted as representing official policies, either expressed
34
# or implied, of GRNET S.A.
35

  
36
from optparse import make_option
37

  
38
from astakos.im.models import load_service_resources
39
from django.core.management.base import BaseCommand, CommandError
40
from synnefo.lib.db.transaction import commit_on_success_strict
41
import logging
42

  
43
logger = logging.getLogger(__name__)
44

  
45

  
46
class Command(BaseCommand):
47
    args = ""
48
    help = "Register service resources"
49

  
50
    option_list = BaseCommand.option_list + (
51
        make_option('--load-service-resources',
52
                    action='store_true',
53
                    dest='load',
54
                    default=False,
55
                    help=("Load initial data for services and their resources "
56
                          "on quotaholder")),
57
    )
58

  
59
    @commit_on_success_strict()
60
    def handle(self, *args, **options):
61
        if options['load']:
62
            load_service_resources()
b/snf-astakos-app/astakos/im/models.py
68 68
from astakos.im.settings import (
69 69
    DEFAULT_USER_LEVEL, INVITATIONS_PER_LEVEL,
70 70
    AUTH_TOKEN_DURATION, EMAILCHANGE_ACTIVATION_DAYS, LOGGING_LEVEL,
71
    SITENAME, SERVICES, MODERATION_ENABLED, RESOURCES_PRESENTATION_DATA,
71
    SITENAME, MODERATION_ENABLED,
72 72
    PROJECT_MEMBER_JOIN_POLICIES, PROJECT_MEMBER_LEAVE_POLICIES, PROJECT_ADMINS)
73 73
from astakos.im import settings as astakos_settings
74 74
from astakos.im import auth_providers as auth
......
79 79
from astakos.quotaholder.api import QH_PRACTICALLY_INFINITE
80 80
from synnefo.lib.db.intdecimalfield import intDecimalField
81 81
from synnefo.util.text import uenc, udec
82
from astakos.im.presentation import RESOURCES_PRESENTATION_DATA
82 83

  
83 84
logger = logging.getLogger(__name__)
84 85

  
......
216 217
            return '%ss' % self.display_name
217 218
        return self.display_name
218 219

  
219
def load_service_resources():
220
    ss = []
221
    rs = []
222
    counter = 0
223
    for service_name, data in sorted(SERVICES.iteritems()):
224
        url = data.get('url')
225
        order = data.get('order', counter)
226
        counter = order + 1
227
        resources = data.get('resources') or ()
228
        service, created = Service.objects.get_or_create(
229
            name=service_name,
230
            defaults={'url': url, 'order': order}
231
        )
232
        if not created and url is not None:
233
            service.url = url
234
            service.save()
235

  
236
        ss.append(service)
237

  
238
        for resource in resources:
239
            try:
240
                resource_name = resource.pop('name', '')
241
                r, created = Resource.objects.get_or_create(
242
                        service=service, name=resource_name,
243
                        defaults=resource)
244
                if not created:
245
                    r.desc = resource['desc']
246
                    r.unit = resource.get('unit', None)
247
                    r.group = resource['group']
248
                    r.uplimit = resource['uplimit']
249
                    r.save()
250

  
251
                rs.append(r)
252

  
253
            except Exception, e:
254
                print "Cannot create resource ", resource_name
255
                import traceback; traceback.print_exc()
256
                continue
257

  
258

  
259 220
def get_resource_names():
260 221
    _RESOURCE_NAMES = []
261 222
    resources = Resource.objects.select_related('service').all()
b/snf-astakos-app/astakos/im/presentation.py
1
# Copyright 2012, 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
RESOURCES_PRESENTATION_DATA = {
35
    'groups': {
36
        'compute': {
37
            'help_text': ('Compute resources '
38
                          '(amount of VMs, CPUs, RAM, System disk) '),
39
            'is_abbreviation': False,
40
            'report_desc': '',
41
            'verbose_name': 'compute',
42
        },
43
        'storage': {
44
            'help_text': ('Storage resources '
45
                          '(amount of space to store files on Pithos) '),
46
            'is_abbreviation': False,
47
            'report_desc': '',
48
            'verbose_name': 'storage',
49
        },
50
        'network': {
51
            'help_text': ' Network resources (number of Private Networks)  ',
52
            'is_abbreviation': False,
53
            'report_desc': '',
54
            'verbose_name': 'network',
55
        },
56
    },
57
    'resources': {
58
        'pithos+.diskspace': {
59
            'help_text': ('This is the space on Pithos for storing files '
60
                          'and VM Images. '),
61
            'help_text_input_each': ('This is the total amount of space on '
62
                                     'Pithos that will be granted to each '
63
                                     'user of this Project '),
64
            'is_abbreviation': False,
65
            'report_desc': 'Storage Space',
66
            'placeholder': 'eg. 10GB',
67
            'verbose_name': 'Storage Space',
68
        },
69
        'cyclades.disk': {
70
            'help_text': ('This is the System Disk that the VMs have that '
71
                          'run the OS '),
72
            'help_text_input_each': ("This is the total amount of System Disk "
73
                                     "that will be granted to each user of "
74
                                     "this Project (this refers to the total "
75
                                     "System Disk of all VMs, not each VM's "
76
                                     "System Disk)  "),
77
            'is_abbreviation': False,
78
            'report_desc': 'System Disk',
79
            'placeholder': 'eg. 5GB, 2GB etc',
80
            'verbose_name': 'System Disk'
81
        },
82
        'cyclades.ram': {
83
            'help_text': 'RAM used by VMs ',
84
            'help_text_input_each': ('This is the total amount of RAM that '
85
                                     'will be granted to each user of this '
86
                                     'Project (on all VMs)  '),
87
            'is_abbreviation': True,
88
            'report_desc': 'RAM',
89
            'placeholder': 'eg. 4GB',
90
            'verbose_name': 'ram'
91
        },
92
        'cyclades.cpu': {
93
            'help_text': 'CPUs used by VMs ',
94
            'help_text_input_each': ('This is the total number of CPUs that '
95
                                     'will be granted to each user of this '
96
                                     'Project (on all VMs)  '),
97
            'is_abbreviation': True,
98
            'report_desc': 'CPUs',
99
            'placeholder': 'eg. 1',
100
            'verbose_name': 'cpu'
101
        },
102
        'cyclades.vm': {
103
            'help_text': ('These are the VMs one can create on the '
104
                          'Cyclades UI '),
105
            'help_text_input_each': ('This is the total number of VMs that '
106
                                     'will be granted to each user of this '
107
                                     'Project '),
108
            'is_abbreviation': True,
109
            'report_desc': 'Virtual Machines',
110
            'placeholder': 'eg. 2',
111
            'verbose_name': 'vm',
112
        },
113
        'cyclades.network.private': {
114
            'help_text': ('These are the Private Networks one can create on '
115
                          'the Cyclades UI. '),
116
            'help_text_input_each': ('This is the total number of Private '
117
                                     'Networks that will be granted to each '
118
                                     'user of this Project '),
119
            'is_abbreviation': False,
120
            'report_desc': 'Private Networks',
121
            'placeholder': 'eg. 1',
122
            'verbose_name': 'Private Network'
123
        }
124
    },
125
    'groups_order': ['storage', 'compute', 'network'],
126
    'resources_order': ['pithos+.diskspace',
127
                        'cyclades.disk',
128
                        'cyclades.cpu',
129
                        'cyclades.ram',
130
                        'cyclades.vm',
131
                        'cyclades.network.private'
132
                        ]
133
}
b/snf-astakos-app/astakos/im/settings.py
162 162
QUOTAHOLDER_TOKEN = getattr(settings, 'ASTAKOS_QUOTAHOLDER_TOKEN', '')
163 163
QUOTAHOLDER_POOLSIZE = getattr(settings, 'ASTAKOS_QUOTAHOLDER_POOLSIZE', 50)
164 164

  
165
# Set the cloud service properties
166
SERVICES = getattr(settings, 'ASTAKOS_SERVICES', {
167
    'cyclades': {
168
#        # Specifying the key 'url' will overwrite it.
169
#        # Use this to (re)set service URL.
170
#        'url': 'https://cyclades.example.synnefo.org/ui/',
171
#        # order services in listings, cloudbar, etc.
172
#        'order' : 1
173
        'resources': [{
174
            'name': 'disk',
175
            'group': 'compute',
176
            'uplimit': 30*1024*1024*1024,
177
            'unit': 'bytes',
178
            'desc': 'Virtual machine disk size'
179
            }, {
180
            'name': 'cpu',
181
            'group': 'compute',
182
            'uplimit': 6,
183
            'desc': 'Number of virtual machine processors'
184
            }, {
185
            'name': 'ram',
186
            'group': 'compute',
187
            'uplimit': 6*1024*1024*1024,
188
            'unit': 'bytes',
189
            'desc': 'Virtual machine memory size'
190
            }, {
191
            'name': 'vm',
192
            'group': 'compute',
193
            'uplimit': 2,
194
            'desc': 'Number of virtual machines'
195
            }, {
196
            'name': 'network.private',
197
            'group': 'network',
198
            'uplimit': 1,
199
            'desc': 'Private networks'
200
            }
201
        ]
202
    },
203
    'pithos+': {
204
#        # Use this to (re)set service URL.
205
#        'url': 'https://pithos.example.synnefo.org/ui/',
206
#        # order services in listings, cloudbar, etc.
207
#        'order' : 2
208
        'resources':[{
209
            'name': 'diskspace',
210
            'group': 'storage',
211
            'uplimit': 5*1024*1024*1024,
212
            'unit': 'bytes',
213
            'desc': 'Pithos account diskspace'
214
            }]
215
    }
216
})
217

  
218 165
# Set the billing URI
219 166
AQUARIUM_URL = getattr(settings, 'ASTAKOS_AQUARIUM_URL', '')
220 167

  
......
230 177

  
231 178
USAGE_UPDATE_INTERVAL = getattr(settings, 'ASTAKOS_USAGE_UPDATE_INTERVAL', 5000)
232 179

  
233
RESOURCES_PRESENTATION_DATA = getattr(
234
    settings, 'ASTAKOS_RESOURCES_PRESENTATION_DATA', {
235
        'groups': {
236
             'compute': {
237
                'help_text':'Compute resources (amount of VMs, CPUs, RAM, System disk) ',
238
                'is_abbreviation':False,
239
                'report_desc':'',
240
                 'verbose_name':'compute',
241
            },
242
            'storage': {
243
                'help_text':'Storage resources (amount of space to store files on Pithos) ',
244
                'is_abbreviation':False,
245
                'report_desc':'',
246
                 'verbose_name':'storage',
247
            },
248
            'network': {
249
                'help_text':' Network resources (number of Private Networks)  ',
250
                'is_abbreviation':False,
251
                'report_desc':'',
252
                'verbose_name':'network',
253
            },
254
        },
255
        'resources': {
256
            'pithos+.diskspace': {
257
                'help_text':'This is the space on Pithos for storing files and VM Images. ',
258
                'help_text_input_each':'This is the total amount of space on Pithos that will be granted to each user of this Project ',
259
                'is_abbreviation':False,
260
                'report_desc':'Storage Space',
261
                'placeholder':'eg. 10GB',
262
                'verbose_name':'Storage Space',
263
            },
264
            'cyclades.disk': {
265
                'help_text':'This is the System Disk that the VMs have that run the OS ',
266
                'help_text_input_each':"This is the total amount of System Disk that will be granted to each user of this Project (this refers to the total System Disk of all VMs, not each VM's System Disk)  ",
267
                'is_abbreviation':False,
268
                'report_desc':'System Disk',
269
                'placeholder':'eg. 5GB, 2GB etc',
270
                'verbose_name':'System Disk'
271
            },
272
            'cyclades.ram': {
273
                'help_text':'RAM used by VMs ',
274
                'help_text_input_each':'This is the total amount of RAM that will be granted to each user of this Project (on all VMs)  ',
275
                'is_abbreviation':True,
276
                'report_desc':'RAM',
277
                'placeholder':'eg. 4GB',
278
                'verbose_name':'ram'
279
            },
280
            'cyclades.cpu': {
281
                'help_text':'CPUs used by VMs ',
282
                'help_text_input_each':'This is the total number of CPUs that will be granted to each user of this Project (on all VMs)  ',
283
                'is_abbreviation':True,
284
                'report_desc':'CPUs',
285
                'placeholder':'eg. 1',
286
                'verbose_name':'cpu'
287
            },
288
            'cyclades.vm': {
289
                'help_text':'These are the VMs one can create on the Cyclades UI ',
290
                'help_text_input_each':'This is the total number of VMs that will be granted to each user of this Project ',
291
                'is_abbreviation':True,
292
                'report_desc':'Virtual Machines',
293
                'placeholder':'eg. 2',
294
                'verbose_name':'vm',
295
            },
296
            'cyclades.network.private': {
297
                'help_text':'These are the Private Networks one can create on the Cyclades UI. ',
298
                'help_text_input_each':'This is the total number of Private Networks that will be granted to each user of this Project ',
299
                'is_abbreviation':False,
300
                'report_desc':'Private Networks',
301
                'placeholder':'eg. 1',
302
                'verbose_name':'Private Network'
303
            }
304

  
305
        },
306

  
307
        'groups_order': ['storage', 'compute', 'network'],
308
        'resources_order': ['pithos+.diskspace', 'cyclades.disk',
309
                            'cyclades.cpu', 'cyclades.ram', 'cyclades.vm',
310
                            'cyclades.network.private']
311

  
312
    })
313

  
314 180
# Permit local account migration
315 181
ENABLE_LOCAL_ACCOUNT_MIGRATION = getattr(settings, 'ASTAKOS_ENABLE_LOCAL_ACCOUNT_MIGRATION', True)
316 182

  
b/snf-astakos-app/astakos/im/templatetags/filters.py
42 42
from django.db.models.query import QuerySet
43 43

  
44 44

  
45
from astakos.im.settings import PAGINATE_BY, RESOURCES_PRESENTATION_DATA
45
from astakos.im.settings import PAGINATE_BY
46
from astakos.im.presentation import RESOURCES_PRESENTATION_DATA
46 47
from astakos.im.models import RESOURCE_SEPARATOR, ProjectResourceGrant
47 48

  
48 49
register = template.Library()
b/snf-astakos-app/astakos/im/views.py
107 107
from astakos.im.settings import (
108 108
    COOKIE_DOMAIN, LOGOUT_NEXT,
109 109
    LOGGING_LEVEL, PAGINATE_BY,
110
    RESOURCES_PRESENTATION_DATA, PAGINATE_BY_ALL,
110
    PAGINATE_BY_ALL,
111 111
    ACTIVATION_REDIRECT_URL,
112 112
    MODERATION_ENABLED)
113
from astakos.im.presentation import RESOURCES_PRESENTATION_DATA
113 114
from astakos.im.api import get_services_dict
114 115
from astakos.im import settings as astakos_settings
115 116
from astakos.im.api.callpoint import AstakosCallpoint

Also available in: Unified diff