Commit c89c8fca authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

Move resource data away from astakos settings

UI-related presentation data go to presentation.py.
Remove load_service_resources call and related astakos-init
management command.
parent 8a5fa377
......@@ -65,7 +65,8 @@ from astakos.im.settings import (
PASSWORD_RESET_EMAIL_SUBJECT, NEWPASSWD_INVALIDATE_TOKEN,
MODERATION_ENABLED, PROJECT_MEMBER_JOIN_POLICIES,
PROJECT_MEMBER_LEAVE_POLICIES, EMAILCHANGE_ENABLED,
RESOURCES_PRESENTATION_DATA)
)
from astakos.im.presentation import RESOURCES_PRESENTATION_DATA
from astakos.im.widgets import DummyWidget, RecaptchaWidget
from astakos.im.functions import (
send_change_email, submit_application, accept_membership_checks)
......
# encoding: utf-8
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from optparse import make_option
from astakos.im.models import load_service_resources
from django.core.management.base import BaseCommand, CommandError
from synnefo.lib.db.transaction import commit_on_success_strict
import logging
logger = logging.getLogger(__name__)
class Command(BaseCommand):
args = ""
help = "Register service resources"
option_list = BaseCommand.option_list + (
make_option('--load-service-resources',
action='store_true',
dest='load',
default=False,
help=("Load initial data for services and their resources "
"on quotaholder")),
)
@commit_on_success_strict()
def handle(self, *args, **options):
if options['load']:
load_service_resources()
......@@ -68,7 +68,7 @@ from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
from astakos.im.settings import (
DEFAULT_USER_LEVEL, INVITATIONS_PER_LEVEL,
AUTH_TOKEN_DURATION, EMAILCHANGE_ACTIVATION_DAYS, LOGGING_LEVEL,
SITENAME, SERVICES, MODERATION_ENABLED, RESOURCES_PRESENTATION_DATA,
SITENAME, MODERATION_ENABLED,
PROJECT_MEMBER_JOIN_POLICIES, PROJECT_MEMBER_LEAVE_POLICIES, PROJECT_ADMINS)
from astakos.im import settings as astakos_settings
from astakos.im import auth_providers as auth
......@@ -79,6 +79,7 @@ from synnefo.lib.db.managers import ForUpdateManager
from astakos.quotaholder.api import QH_PRACTICALLY_INFINITE
from synnefo.lib.db.intdecimalfield import intDecimalField
from synnefo.util.text import uenc, udec
from astakos.im.presentation import RESOURCES_PRESENTATION_DATA
logger = logging.getLogger(__name__)
......@@ -216,46 +217,6 @@ class Resource(models.Model):
return '%ss' % self.display_name
return self.display_name
def load_service_resources():
ss = []
rs = []
counter = 0
for service_name, data in sorted(SERVICES.iteritems()):
url = data.get('url')
order = data.get('order', counter)
counter = order + 1
resources = data.get('resources') or ()
service, created = Service.objects.get_or_create(
name=service_name,
defaults={'url': url, 'order': order}
)
if not created and url is not None:
service.url = url
service.save()
ss.append(service)
for resource in resources:
try:
resource_name = resource.pop('name', '')
r, created = Resource.objects.get_or_create(
service=service, name=resource_name,
defaults=resource)
if not created:
r.desc = resource['desc']
r.unit = resource.get('unit', None)
r.group = resource['group']
r.uplimit = resource['uplimit']
r.save()
rs.append(r)
except Exception, e:
print "Cannot create resource ", resource_name
import traceback; traceback.print_exc()
continue
def get_resource_names():
_RESOURCE_NAMES = []
resources = Resource.objects.select_related('service').all()
......
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
RESOURCES_PRESENTATION_DATA = {
'groups': {
'compute': {
'help_text': ('Compute resources '
'(amount of VMs, CPUs, RAM, System disk) '),
'is_abbreviation': False,
'report_desc': '',
'verbose_name': 'compute',
},
'storage': {
'help_text': ('Storage resources '
'(amount of space to store files on Pithos) '),
'is_abbreviation': False,
'report_desc': '',
'verbose_name': 'storage',
},
'network': {
'help_text': ' Network resources (number of Private Networks) ',
'is_abbreviation': False,
'report_desc': '',
'verbose_name': 'network',
},
},
'resources': {
'pithos+.diskspace': {
'help_text': ('This is the space on Pithos for storing files '
'and VM Images. '),
'help_text_input_each': ('This is the total amount of space on '
'Pithos that will be granted to each '
'user of this Project '),
'is_abbreviation': False,
'report_desc': 'Storage Space',
'placeholder': 'eg. 10GB',
'verbose_name': 'Storage Space',
},
'cyclades.disk': {
'help_text': ('This is the System Disk that the VMs have that '
'run the OS '),
'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) "),
'is_abbreviation': False,
'report_desc': 'System Disk',
'placeholder': 'eg. 5GB, 2GB etc',
'verbose_name': 'System Disk'
},
'cyclades.ram': {
'help_text': 'RAM used by VMs ',
'help_text_input_each': ('This is the total amount of RAM that '
'will be granted to each user of this '
'Project (on all VMs) '),
'is_abbreviation': True,
'report_desc': 'RAM',
'placeholder': 'eg. 4GB',
'verbose_name': 'ram'
},
'cyclades.cpu': {
'help_text': 'CPUs used by VMs ',
'help_text_input_each': ('This is the total number of CPUs that '
'will be granted to each user of this '
'Project (on all VMs) '),
'is_abbreviation': True,
'report_desc': 'CPUs',
'placeholder': 'eg. 1',
'verbose_name': 'cpu'
},
'cyclades.vm': {
'help_text': ('These are the VMs one can create on the '
'Cyclades UI '),
'help_text_input_each': ('This is the total number of VMs that '
'will be granted to each user of this '
'Project '),
'is_abbreviation': True,
'report_desc': 'Virtual Machines',
'placeholder': 'eg. 2',
'verbose_name': 'vm',
},
'cyclades.network.private': {
'help_text': ('These are the Private Networks one can create on '
'the Cyclades UI. '),
'help_text_input_each': ('This is the total number of Private '
'Networks that will be granted to each '
'user of this Project '),
'is_abbreviation': False,
'report_desc': 'Private Networks',
'placeholder': 'eg. 1',
'verbose_name': 'Private Network'
}
},
'groups_order': ['storage', 'compute', 'network'],
'resources_order': ['pithos+.diskspace',
'cyclades.disk',
'cyclades.cpu',
'cyclades.ram',
'cyclades.vm',
'cyclades.network.private'
]
}
......@@ -162,59 +162,6 @@ QUOTAHOLDER_URL = getattr(settings, 'ASTAKOS_QUOTAHOLDER_URL', '')
QUOTAHOLDER_TOKEN = getattr(settings, 'ASTAKOS_QUOTAHOLDER_TOKEN', '')
QUOTAHOLDER_POOLSIZE = getattr(settings, 'ASTAKOS_QUOTAHOLDER_POOLSIZE', 50)
# Set the cloud service properties
SERVICES = getattr(settings, 'ASTAKOS_SERVICES', {
'cyclades': {
# # Specifying the key 'url' will overwrite it.
# # Use this to (re)set service URL.
# 'url': 'https://cyclades.example.synnefo.org/ui/',
# # order services in listings, cloudbar, etc.
# 'order' : 1
'resources': [{
'name': 'disk',
'group': 'compute',
'uplimit': 30*1024*1024*1024,
'unit': 'bytes',
'desc': 'Virtual machine disk size'
}, {
'name': 'cpu',
'group': 'compute',
'uplimit': 6,
'desc': 'Number of virtual machine processors'
}, {
'name': 'ram',
'group': 'compute',
'uplimit': 6*1024*1024*1024,
'unit': 'bytes',
'desc': 'Virtual machine memory size'
}, {
'name': 'vm',
'group': 'compute',
'uplimit': 2,
'desc': 'Number of virtual machines'
}, {
'name': 'network.private',
'group': 'network',
'uplimit': 1,
'desc': 'Private networks'
}
]
},
'pithos+': {
# # Use this to (re)set service URL.
# 'url': 'https://pithos.example.synnefo.org/ui/',
# # order services in listings, cloudbar, etc.
# 'order' : 2
'resources':[{
'name': 'diskspace',
'group': 'storage',
'uplimit': 5*1024*1024*1024,
'unit': 'bytes',
'desc': 'Pithos account diskspace'
}]
}
})
# Set the billing URI
AQUARIUM_URL = getattr(settings, 'ASTAKOS_AQUARIUM_URL', '')
......@@ -230,87 +177,6 @@ NEWPASSWD_INVALIDATE_TOKEN = getattr(
USAGE_UPDATE_INTERVAL = getattr(settings, 'ASTAKOS_USAGE_UPDATE_INTERVAL', 5000)
RESOURCES_PRESENTATION_DATA = getattr(
settings, 'ASTAKOS_RESOURCES_PRESENTATION_DATA', {
'groups': {
'compute': {
'help_text':'Compute resources (amount of VMs, CPUs, RAM, System disk) ',
'is_abbreviation':False,
'report_desc':'',
'verbose_name':'compute',
},
'storage': {
'help_text':'Storage resources (amount of space to store files on Pithos) ',
'is_abbreviation':False,
'report_desc':'',
'verbose_name':'storage',
},
'network': {
'help_text':' Network resources (number of Private Networks) ',
'is_abbreviation':False,
'report_desc':'',
'verbose_name':'network',
},
},
'resources': {
'pithos+.diskspace': {
'help_text':'This is the space on Pithos for storing files and VM Images. ',
'help_text_input_each':'This is the total amount of space on Pithos that will be granted to each user of this Project ',
'is_abbreviation':False,
'report_desc':'Storage Space',
'placeholder':'eg. 10GB',
'verbose_name':'Storage Space',
},
'cyclades.disk': {
'help_text':'This is the System Disk that the VMs have that run the OS ',
'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) ",
'is_abbreviation':False,
'report_desc':'System Disk',
'placeholder':'eg. 5GB, 2GB etc',
'verbose_name':'System Disk'
},
'cyclades.ram': {
'help_text':'RAM used by VMs ',
'help_text_input_each':'This is the total amount of RAM that will be granted to each user of this Project (on all VMs) ',
'is_abbreviation':True,
'report_desc':'RAM',
'placeholder':'eg. 4GB',
'verbose_name':'ram'
},
'cyclades.cpu': {
'help_text':'CPUs used by VMs ',
'help_text_input_each':'This is the total number of CPUs that will be granted to each user of this Project (on all VMs) ',
'is_abbreviation':True,
'report_desc':'CPUs',
'placeholder':'eg. 1',
'verbose_name':'cpu'
},
'cyclades.vm': {
'help_text':'These are the VMs one can create on the Cyclades UI ',
'help_text_input_each':'This is the total number of VMs that will be granted to each user of this Project ',
'is_abbreviation':True,
'report_desc':'Virtual Machines',
'placeholder':'eg. 2',
'verbose_name':'vm',
},
'cyclades.network.private': {
'help_text':'These are the Private Networks one can create on the Cyclades UI. ',
'help_text_input_each':'This is the total number of Private Networks that will be granted to each user of this Project ',
'is_abbreviation':False,
'report_desc':'Private Networks',
'placeholder':'eg. 1',
'verbose_name':'Private Network'
}
},
'groups_order': ['storage', 'compute', 'network'],
'resources_order': ['pithos+.diskspace', 'cyclades.disk',
'cyclades.cpu', 'cyclades.ram', 'cyclades.vm',
'cyclades.network.private']
})
# Permit local account migration
ENABLE_LOCAL_ACCOUNT_MIGRATION = getattr(settings, 'ASTAKOS_ENABLE_LOCAL_ACCOUNT_MIGRATION', True)
......
......@@ -42,7 +42,8 @@ from django.core.paginator import Paginator, EmptyPage
from django.db.models.query import QuerySet
from astakos.im.settings import PAGINATE_BY, RESOURCES_PRESENTATION_DATA
from astakos.im.settings import PAGINATE_BY
from astakos.im.presentation import RESOURCES_PRESENTATION_DATA
from astakos.im.models import RESOURCE_SEPARATOR, ProjectResourceGrant
register = template.Library()
......
......@@ -107,9 +107,10 @@ from astakos.im.functions import (
from astakos.im.settings import (
COOKIE_DOMAIN, LOGOUT_NEXT,
LOGGING_LEVEL, PAGINATE_BY,
RESOURCES_PRESENTATION_DATA, PAGINATE_BY_ALL,
PAGINATE_BY_ALL,
ACTIVATION_REDIRECT_URL,
MODERATION_ENABLED)
from astakos.im.presentation import RESOURCES_PRESENTATION_DATA
from astakos.im.api import get_services_dict
from astakos.im import settings as astakos_settings
from astakos.im.api.callpoint import AstakosCallpoint
......
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