Initial checkin of deprecated API implementation
[plcapi.git] / PLC / Methods / SliceUserAdd.py
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
8
9 class SliceUserAdd(Method):
10     """
11     Deprecated. See AddPersonToSlice.
12
13     """
14
15     status = "deprecated"
16
17     roles = ['admin', 'pi']
18
19     accepts = [
20         Auth(),
21         Slice.fields['name'],
22         [Person.fields['email']],
23         ]
24
25     returns = Parameter(int, '1 if successful')
26
27     def call(self, auth, slice_name, user_list):
28         # Get account information
29         persons = Persons(self.api, user_list)
30         if not persons:
31             raise PLCInvalidArgument, "No such account"
32
33         # Get slice information
34         slices = Slices(self.api, [slice_id_or_name])
35         if not slices:
36             raise PLCInvalidArgument, "No such slice"
37
38         slice = slices[0]
39         if slice['peer_id'] is not None:
40             raise PLCInvalidArgument, "Not a local slice"
41
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"
47         
48         for person in persons:
49             if person['person_id'] not in slice['person_ids']:
50                 slice.add_person(person, commit = False)
51         
52         slice.sync()
53         self.object_ids = [slice['slice_id']]
54
55         return 1