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.Slices import Slice, Slices
6 from PLC.Auth import Auth
7 from PLC.Methods.AddPersonToSlice import AddPersonToSlice
9 class SliceUserAdd(Method):
11 Deprecated. See AddPersonToSlice.
17 roles = ['admin', 'pi']
22 [Person.fields['email']],
25 returns = Parameter(int, '1 if successful')
27 def call(self, auth, slice_name, user_list):
28 # Get account information
29 persons = Persons(self.api, user_list)
31 raise PLCInvalidArgument, "No such account"
33 # Get slice information
34 slices = Slices(self.api, [slice_id_or_name])
36 raise PLCInvalidArgument, "No such slice"
39 if slice['peer_id'] is not None:
40 raise PLCInvalidArgument, "Not a local slice"
42 # If we are not admin, make sure the caller is a PI
43 # of the site associated with the slice
44 if 'admin' not in self.caller['roles']:
45 if slice['site_id'] not in self.caller['site_ids']:
46 raise PLCPermissionDenied, "Not allowed to add users to this slice"
48 for person in persons:
49 if person['person_id'] not in slice['person_ids']:
50 slice.add_person(person, commit = False)
53 self.object_ids = [slice['slice_id']]