fd15c0fe2c2e50e0b5887a251842fa0946bb0680
[sfa.git] / sfa / client / client_helper.py
1 ###
2 #
3 # Thierry - 2012 sept 21
4 #
5 # it seems terribly wrong that the client should decide to use PG- or PL- related code
6 # esp. in a context where we're trying to have more and more kinds of testbeds involved
7 #
8 # also, the 'users' field that CreateSliver is expecting (the key point here is to get this right)
9 # is specified to have at least a urn and a list of keys, both of these being supported natively
10 # in the sfa db
11 # So long story short, it seems to me that we should have a common code that fills in 'urn' and 'keys'
12 # and then code that tentatively tries to add as much extra info that we can get on these users
13 #
14 # the fact e.g. that PlanetLab insists on getting a first_name and last_name is not
15 # exactly consistent with the GENI spec. of CreateSliver
16 #
17
18
19 def pg_users_arg(records):
20     users = []
21     for record in records:
22         if record['type'] != 'user':
23             continue
24         user = {'urn': record['reg-urn'],
25                 'keys': record['reg-keys'],
26                 'email': record['email']}
27         users.append(user)
28     return users
29
30
31 def sfa_users_arg(records, slice_record):
32     users = []
33     for record in records:
34         if record['type'] != 'user':
35             continue
36         user = {'urn': record['reg-urn'],
37                 'keys': record['reg-keys'],
38                 'slice_record': slice_record,
39                 }
40         # fill as much stuff as possible from planetlab or similar
41         # note that reg-email is not yet available
42         pl_fields = ['email', 'person_id',
43                      'first_name', 'last_name', 'key_ids']
44         nitos_fields = ['email', 'user_id']
45         extra_fields = list(set(pl_fields).union(set(nitos_fields)))
46         # try to fill all these in
47         for field in extra_fields:
48             if field in record:
49                 user[field] = record[field]
50         users.append(user)
51
52     return users
53
54
55 def sfa_to_pg_users_arg(users):
56
57     new_users = []
58     fields = ['urn', 'keys']
59     for user in users:
60         new_user = dict([item for item in user.items()
61                          if item[0] in fields])
62         new_users.append(new_user)
63     return new_users