remove sfa upcalls
[plcapi.git] / PLC / Methods / DeleteSlice.py
1 # $Id$
2 # $URL$
3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Slices import Slice, Slices
7 from PLC.Auth import Auth
8
9 class DeleteSlice(Method):
10     """
11     Deletes the specified slice.
12
13     Users may only delete slices of which they are members. PIs may
14     delete any of the slices at their sites, or any slices of which
15     they are members. Admins may delete any slice.
16
17     Returns 1 if successful, faults otherwise.
18     """
19
20     roles = ['admin', 'pi', 'user']
21
22     accepts = [
23         Auth(),
24         Mixed(Slice.fields['slice_id'],
25               Slice.fields['name']),
26         ]
27
28     returns = Parameter(int, '1 if successful')
29
30     def call(self, auth, slice_id_or_name):
31         slices = Slices(self.api, [slice_id_or_name])
32         if not slices:
33             raise PLCInvalidArgument, "No such slice"
34         slice = slices[0]
35
36         if slice['peer_id'] is not None:
37             raise PLCInvalidArgument, "Not a local slice"
38
39         if 'admin' not in self.caller['roles']:
40             if self.caller['person_id'] in slice['person_ids']:
41                 pass
42             elif 'pi' not in self.caller['roles']:
43                 raise PLCPermissionDenied, "Not a member of the specified slice"
44             elif slice['site_id'] not in self.caller['site_ids']:
45                 raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
46
47         slice.delete()
48         self.event_objects = {'Slice': [slice['slice_id']]}
49
50         return 1