a75ebc5216f8d5aa57bb13415c70e99ad8f83c96
[plcapi.git] / PLC / Methods / DeleteRole.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.Roles import Role, Roles
7 from PLC.Auth import Auth
8
9 class DeleteRole(Method):
10     """
11     Deletes a role.
12
13     WARNING: This will remove the specified role from all accounts
14     that possess it, and from all node and slice attributes that refer
15     to it.
16
17     Returns 1 if successful, faults otherwise.
18     """
19
20     roles = ['admin']
21
22     accepts = [
23         Auth(),
24         Mixed(Role.fields['role_id'],
25               Role.fields['name'])
26         ]
27
28     returns = Parameter(int, '1 if successful')
29
30
31     def call(self, auth, role_id_or_name):
32         roles = Roles(self.api, [role_id_or_name])
33         if not roles:
34             raise PLCInvalidArgument, "No such role"
35         role = roles[0]
36
37         role.delete()
38         self.event_objects = {'Role': [role['role_id']]}
39
40         return 1