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