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