1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Persons import Person, Persons
5 from PLC.Sites import Site, Sites
6 from PLC.Auth import Auth
7 import sys ###########################soner
8 sys.path.append('../../../../util')
9 from pl_to_geni import *
13 class AddPersonToSite(Method):
15 Adds the specified person to the specified site. If the person is
16 already a member of the site, no errors are returned. Does not
17 change the person's primary site.
19 Returns 1 if successful, faults otherwise.
26 Mixed(Person.fields['person_id'],
27 Person.fields['email']),
28 Mixed(Site.fields['site_id'],
29 Site.fields['login_base'])
32 returns = Parameter(int, '1 if successful')
34 def call(self, auth, person_id_or_email, site_id_or_login_base):
35 # Get account information
36 persons = Persons(self.api, [person_id_or_email])
38 raise PLCInvalidArgument, "No such account"
41 if person['peer_id'] is not None:
42 raise PLCInvalidArgument, "Not a local account"
44 # Get site information
45 sites = Sites(self.api, [site_id_or_login_base])
47 raise PLCInvalidArgument, "No such site"
50 if site['peer_id'] is not None:
51 raise PLCInvalidArgument, "Not a local site"
53 if site['site_id'] not in person['site_ids']:
54 site.add_person(person)
57 self.event_objects = {'Site': [site['site_id']],
58 'Person': [person['person_id']]}
59 self.message = 'Person %d added to site %d' % \
60 (person['person_id'], site['site_id'])
62 #insert the record into GENI tables ###################soner
63 (global_sr_tree, global_cr_tree) = get_tree_globals()
64 (site_id, site_hrn) = site_to_auth(site_id_or_login_base)
65 dbinfo = determine_dbinfo(site_hrn, global_sr_tree)
67 raise PLCInvalidArgument, "No GENI authority corresponding to the site "+site['name']
71 new_hrn = person_to_user(person['email'])
72 existing = cnx.query("SELECT * FROM "+tablename+" WHERE hrn = '"+new_hrn+"'; ")
74 new_hrn = person_to_user(person['email'], 1)
75 existing = cnx.query("SELECT * FROM "+tablename+" WHERE hrn = '"+new_hrn+"'; ")
77 new_hrn = person_to_user(person['email'], 2)
79 geni_record = {'hrn':''}
80 geni_record["hrn"] = new_hrn
81 geni_record["type"] = 'user'
82 geni_record['pointer'] = person['person_id']
84 querystr = generate_querystr('INSERT', tablename, geni_record)