Revision e1a80257 snf-astakos-app/astakos/im/migrations/0017_populate_resource_data.py
b/snf-astakos-app/astakos/im/migrations/0017_populate_resource_data.py | ||
---|---|---|
9 | 9 |
logger = logging.getLogger(__name__) |
10 | 10 |
|
11 | 11 |
class Migration(DataMigration): |
12 |
|
|
12 |
"Obsolete migration." |
|
13 |
|
|
13 | 14 |
def forwards(self, orm): |
14 |
"Write your forwards methods here." |
|
15 |
|
|
16 |
try: |
|
17 |
default = orm.AstakosGroup.objects.get(name='default') |
|
18 |
except orm.AstakosGroup.DoesNotExist: |
|
19 |
return |
|
20 |
|
|
21 |
def create_policies(args): |
|
22 |
sn, dict = args |
|
23 |
url = dict.get('url') |
|
24 |
resources = dict.get('resources') or () |
|
25 |
s, created = orm.Service.objects.get_or_create( |
|
26 |
name=sn, |
|
27 |
defaults={'url': url} |
|
28 |
) |
|
29 |
|
|
30 |
for r in resources: |
|
31 |
try: |
|
32 |
rn = r.pop('name', '') |
|
33 |
uplimit = r.pop('uplimit', None) |
|
34 |
r, created = orm.Resource.objects.get_or_create( |
|
35 |
service=s, |
|
36 |
name=rn, |
|
37 |
defaults=r) |
|
38 |
except Exception, e: |
|
39 |
print "Cannot create resource ", rn |
|
40 |
continue |
|
41 |
else: |
|
42 |
q, created = orm.AstakosGroupQuota.objects.get_or_create( |
|
43 |
group=default, |
|
44 |
resource=r, |
|
45 |
defaults={ |
|
46 |
'uplimit':uplimit, |
|
47 |
} |
|
48 |
) |
|
49 |
map(create_policies, SERVICES.iteritems()) |
|
15 |
pass |
|
50 | 16 |
|
51 | 17 |
def backwards(self, orm): |
52 |
try: |
|
53 |
default = orm.AstakosGroup.objects.get(name='default') |
|
54 |
except orm.AstakosGroup.DoesNotExist: |
|
55 |
return |
|
56 |
|
|
57 |
def destroy_policies(args): |
|
58 |
sn, dict = args |
|
59 |
url = dict.get('url') |
|
60 |
resources = dict.get('resources') or () |
|
61 |
for r in resources: |
|
62 |
rn = r.get('name', '') |
|
63 |
try: |
|
64 |
q = orm.AstakosGroupQuota.objects.get( |
|
65 |
group=default, |
|
66 |
resource__name=rn) |
|
67 |
q.delete() |
|
68 |
q = orm.Resource.objects.get(service__name=sn, name=rn) |
|
69 |
q.delete() |
|
70 |
except Exception, e: |
|
71 |
print "Cannot create resource ", rn |
|
72 |
continue |
|
73 |
|
|
74 |
map(destroy_policies, SERVICES.iteritems()) |
|
75 |
|
|
18 |
pass |
|
19 |
|
|
76 | 20 |
models = { |
77 | 21 |
'auth.group': { |
78 | 22 |
'Meta': {'object_name': 'Group'}, |
Also available in: Unified diff