(most) all functions now take SessionAuth in addition to PasswordAuth
[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     def call(self, auth, role_id_or_name):
29         roles = Roles(self.api, [role_id_or_name])
30         if not roles:
31             raise PLCInvalidArgument, "No such role"
32         role = roles.values()[0]
33
34         role.delete()
35
36         return 1