From 952c09791d8a4c6e4ff8067fad45d6e1e8a0ce56 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Mon, 5 Nov 2012 15:08:19 +0200 Subject: [PATCH] Set additional default resource information (description, unit) --- snf-astakos-app/README | 38 +++++++++++---- .../0024_auto__chg_field_astakosgroupquota_lim.py | 16 +++---- ...urce_data.py => 0030_populate_resource_data.py} | 50 ++++++++++++-------- snf-astakos-app/astakos/im/settings.py | 43 +++++++++++++++-- 4 files changed, 106 insertions(+), 41 deletions(-) rename snf-astakos-app/astakos/im/migrations/{0023_populate_resource_data.py => 0030_populate_resource_data.py} (88%) diff --git a/snf-astakos-app/README b/snf-astakos-app/README index 842e632..61651a8 100644 --- a/snf-astakos-app/README +++ b/snf-astakos-app/README @@ -85,21 +85,41 @@ ASTAKOS_INVITATION_EMAIL_SUBJECT 'Invitation to %s alpha2 testing' % ASTAKOS_GREETING_EMAIL_SUBJECT 'Welcome to %s alpha2 testing' % SITENAME Welcome email subject ASTAKOS_FEEDBACK_EMAIL_SUBJECT 'Feedback from %s alpha2 testing' % SITENAME Feedback email subject ASTAKOS_VERIFICATION_EMAIL_SUBJECT '%s alpha2 testing account activation is needed' % SITENAME Account activation email subject -ASTAKOS_ACCOUNT_CREATION_SUBJECT = getattr(settings, 'ASTAKOS_ACCOUNT_CREATION_SUBJECT', - '%s alpha2 testing account created (%%(user)s)' % SITENAME) -ASTAKOS_GROUP_CREATION_SUBJECT = getattr(settings, 'ASTAKOS_', - '%s alpha2 testing group created (%%(group)s)' % SITENAME) +ASTAKOS_ACCOUNT_CREATION_SUBJECT '%s alpha2 testing account created (%%(user)s)' % SITENAME Account creation email subject +ASTAKOS_GROUP_CREATION_SUBJECT '%s alpha2 testing group created (%%(group)s)' % SITENAME Group creation email subject ASTAKOS_HELPDESK_NOTIFICATION_EMAIL_SUBJECT '%s alpha2 testing account activated (%%(user)s)' % SITENAME Account activation helpdesk notification email subject ASTAKOS_EMAIL_CHANGE_EMAIL_SUBJECT 'Email change on %s alpha2 testing' % SITENAME Email change subject ASTAKOS_PASSWORD_RESET_EMAIL_SUBJECT 'Password reset on %s alpha2 testing' % SITENAME Password change email subject ASTAKOS_QUOTA_HOLDER_URL '' The quota holder URI - e.g. ``http://localhost:8080/api/quotaholder/v`` -ASTAKOS_SERVICES {'cyclades': {'url':'https://node1.example.com/ui/', 'quota': {'vm': 2}}, Cloud service default url and quota - 'pithos+': {'url':'https://node2.example.com/ui/', 'quota': { - 'diskspace': 50 * 1024 * 1024 * 1024}}}) + e.g. ``http://localhost:8080/api/quotaholder/v`` +ASTAKOS_SERVICES {'cyclades': {'resources': [{'desc': 'Number of virtual machines', Default cloud service information + 'group': 'storage', + 'name': 'vm', + 'uplimit': 2}, + {'desc': 'Virtual machine disk size', + 'group': 'storage', + 'name': 'disksize', + 'unit': 'GB', + 'uplimit': 5}, + {'desc': 'Number of virtual machine processors', + 'group': 'storage', + 'name': 'cpu', + 'uplimit': 1}, + {'desc': 'Virtual machines', + 'group': 'storage', + 'name': 'ram', + 'unit': 'MB', + 'uplimit': 1024}], + 'url': 'https://node1.example.com/ui/'}, + 'pithos+': {'resources': [{'desc': 'Pithos account diskspace', + 'group': 'compute', + 'name': 'diskspace', + 'unit': 'bytes', + 'uplimit': 5368709120}], + 'url': 'https://node2.example.com/ui/'}} ASTAKOS_AQUARIUM_URL '' The billing (aquarium) URI - e.g. ``http://localhost:8888/user`` + e.g. ``http://localhost:8888/user`` ASTAKOS_PAGINATE_BY 10 Number of object to be displayed per page ASTAKOS_NEWPASSWD_INVALIDATE_TOKEN True Enforce token renewal on password change/reset. If set to False, user can optionally decide diff --git a/snf-astakos-app/astakos/im/migrations/0024_auto__chg_field_astakosgroupquota_lim.py b/snf-astakos-app/astakos/im/migrations/0024_auto__chg_field_astakosgroupquota_lim.py index 9cfdf29..e4fe68a 100644 --- a/snf-astakos-app/astakos/im/migrations/0024_auto__chg_field_astakosgroupquota_lim.py +++ b/snf-astakos-app/astakos/im/migrations/0024_auto__chg_field_astakosgroupquota_lim.py @@ -18,14 +18,14 @@ class Migration(SchemaMigration): 'django.db.models.fields.PositiveIntegerField')(null=True)) def backwards(self, orm): - - # Changing field 'AstakosGroupQuota.limit' - db.alter_column('im_astakosgroupquota', 'limit', self.gf( - 'django.db.models.fields.PositiveIntegerField')(default=None)) - - # Changing field 'AstakosUserQuota.limit' - db.alter_column('im_astakosuserquota', 'limit', self.gf( - 'django.db.models.fields.PositiveIntegerField')(default=None)) + pass +# # Changing field 'AstakosGroupQuota.limit' +# db.alter_column('im_astakosgroupquota', 'limit', self.gf( +# 'django.db.models.fields.PositiveIntegerField')(default=None)) +# +# # Changing field 'AstakosUserQuota.limit' +# db.alter_column('im_astakosuserquota', 'limit', self.gf( +# 'django.db.models.fields.PositiveIntegerField')(default=None)) models = { 'auth.group': { diff --git a/snf-astakos-app/astakos/im/migrations/0023_populate_resource_data.py b/snf-astakos-app/astakos/im/migrations/0030_populate_resource_data.py similarity index 88% rename from snf-astakos-app/astakos/im/migrations/0023_populate_resource_data.py rename to snf-astakos-app/astakos/im/migrations/0030_populate_resource_data.py index b9554ba..599494e 100644 --- a/snf-astakos-app/astakos/im/migrations/0023_populate_resource_data.py +++ b/snf-astakos-app/astakos/im/migrations/0030_populate_resource_data.py @@ -4,6 +4,9 @@ from south.v2 import DataMigration from astakos.im.settings import SERVICES +import logging + +logger = logging.getLogger(__name__) class Migration(DataMigration): @@ -18,26 +21,30 @@ class Migration(DataMigration): def create_policies(args): sn, dict = args url = dict.get('url') - policy = dict.get('quota') or () + resources = dict.get('resources') or () s, created = orm.Service.objects.get_or_create(name=sn, defaults={'url': url}) if not created and not s.url: s.url = url s.save() - for rn, l in policy.iteritems(): + for r in resources: try: + rn = r.pop('name', '') + uplimit = r.pop('uplimit', None) r, created = orm.Resource.objects.get_or_create( service=s, - name=rn) + name=rn, + defaults=r) except Exception, e: - print "Cannot create policy ", policy + logger.exception(e) + print "Cannot create resource ", rn continue q, created = orm.AstakosGroupQuota.objects.get_or_create( group=default, resource=r, - uplimit=l, + uplimit=uplimit, limit=0) map(create_policies, SERVICES.iteritems()) @@ -50,14 +57,13 @@ class Migration(DataMigration): def destroy_policies(args): sn, dict = args url = dict.get('url') - policy = dict.get('quota') or () - for rn, l in policy.iteritems(): + resources = dict.get('resources') or () + for r in resources: + rn = r.get('name', '') try: - q = orm.AstakosGroupQuota.objects.get( - group=default, - resource__name=rn) + q = orm.Resource.objects.get(service__name=sn, name=rn) q.delete() - except orm.AstakosGroupQuota.DoesNotExist: + except orm.Resource.DoesNotExist: continue map(destroy_policies, SERVICES.iteritems()) @@ -107,20 +113,22 @@ class Migration(DataMigration): }, 'im.approvalterms': { 'Meta': {'object_name': 'ApprovalTerms'}, - 'date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 8, 9, 11, 14, 9, 289091)', 'db_index': 'True'}), + 'date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 11, 5, 12, 47, 39, 465319)', 'db_index': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'location': ('django.db.models.fields.CharField', [], {'max_length': '255'}) }, 'im.astakosgroup': { 'Meta': {'object_name': 'AstakosGroup', '_ormbases': ['auth.Group']}, 'approval_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), - 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 8, 9, 11, 14, 9, 283154)'}), + 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 11, 5, 12, 47, 39, 456067)'}), 'desc': ('django.db.models.fields.TextField', [], {'null': 'True'}), - 'estimated_participants': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}), + 'estimated_participants': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}), 'expiration_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), 'group_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.Group']", 'unique': 'True', 'primary_key': 'True'}), + 'homepage': ('django.db.models.fields.URLField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'issue_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), 'kind': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.GroupKind']"}), + 'max_participants': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}), 'moderation_enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'policy': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['im.Resource']", 'null': 'True', 'through': "orm['im.AstakosGroupQuota']", 'blank': 'True'}) }, @@ -128,7 +136,7 @@ class Migration(DataMigration): 'Meta': {'unique_together': "(('resource', 'group'),)", 'object_name': 'AstakosGroupQuota'}, 'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosGroup']", 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'limit': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'limit': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}), 'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Resource']"}), 'uplimit': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}) }, @@ -141,6 +149,7 @@ class Migration(DataMigration): 'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), 'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}), 'date_signed_terms': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'disturbed_quota': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}), 'email_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'has_credits': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'has_signed_terms': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), @@ -157,7 +166,7 @@ class Migration(DataMigration): 'im.astakosuserquota': { 'Meta': {'unique_together': "(('resource', 'user'),)", 'object_name': 'AstakosUserQuota'}, 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'limit': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'limit': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}), 'resource': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Resource']"}), 'uplimit': ('django.db.models.fields.BigIntegerField', [], {'null': 'True'}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"}) @@ -167,7 +176,7 @@ class Migration(DataMigration): 'activation_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40', 'db_index': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'new_email_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}), - 'requested_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 8, 9, 11, 14, 9, 290713)'}), + 'requested_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 11, 5, 12, 47, 39, 466946)'}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'emailchange_user'", 'unique': 'True', 'to': "orm['im.AstakosUser']"}) }, 'im.groupkind': { @@ -189,17 +198,20 @@ class Migration(DataMigration): 'im.membership': { 'Meta': {'unique_together': "(('person', 'group'),)", 'object_name': 'Membership'}, 'date_joined': ('django.db.models.fields.DateField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), - 'date_requested': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime(2012, 8, 9, 11, 14, 9, 286925)', 'blank': 'True'}), + 'date_requested': ('django.db.models.fields.DateField', [], {'default': 'datetime.datetime(2012, 11, 5, 12, 47, 39, 462857)', 'blank': 'True'}), 'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosGroup']"}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'person': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"}) }, 'im.resource': { 'Meta': {'object_name': 'Resource'}, + 'desc': ('django.db.models.fields.TextField', [], {'null': 'True'}), + 'group': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'meta': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['im.ResourceMetadata']", 'symmetrical': 'False'}), 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}), - 'service': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Service']"}) + 'service': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.Service']"}), + 'unit': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True'}) }, 'im.resourcemetadata': { 'Meta': {'object_name': 'ResourceMetadata'}, diff --git a/snf-astakos-app/astakos/im/settings.py b/snf-astakos-app/astakos/im/settings.py index 13495de..bfa0f51 100644 --- a/snf-astakos-app/astakos/im/settings.py +++ b/snf-astakos-app/astakos/im/settings.py @@ -132,11 +132,44 @@ PASSWORD_RESET_EMAIL_SUBJECT = getattr( QUOTA_HOLDER_URL = getattr(settings, 'ASTAKOS_QUOTA_HOLDER_URL', '') # Set the cloud service properties -SERVICES = getattr(settings, 'ASTAKOS_SERVICES', - {'cyclades': {'url': 'https://node1.example.com/ui/', - 'quota': {'vm': 2}}, - 'pithos+': {'url': 'https://node2.example.com/ui/', - 'quota': {'diskspace': 50 * 1024 * 1024 * 1024}}}) +SERVICES = getattr(settings, 'ASTAKOS_SERVICES',{ + 'cyclades': { + 'url': 'https://node1.example.com/ui/', + 'resources': [{ + 'name':'vm', + 'group':'storage', + 'uplimit':2, + 'desc': 'Number of virtual machines' + },{ + 'name':'disksize', + 'group':'storage', + 'uplimit':5, + 'unit':'GB', + 'desc': 'Virtual machine disk size' + },{ + 'name':'cpu', + 'group':'storage', + 'uplimit':1, + 'desc': 'Number of virtual machine processors' + },{ + 'name':'ram', + 'group':'storage', + 'uplimit':1024, + 'unit':'MB', + 'desc': 'Virtual machines' + }] + }, + 'pithos+': { + 'url': 'https://node2.example.com/ui/', + 'resources':[{ + 'name':'diskspace', + 'group':'compute', + 'uplimit':5 * 1024 * 1024 * 1024, + 'unit':'bytes', + 'desc': 'Pithos account diskspace' + }] + } +}) # Set the billing URI AQUARIUM_URL = getattr(settings, 'ASTAKOS_AQUARIUM_URL', '') -- 1.7.10.4