svn keywords
[plcapi.git] / PLC / Methods / DeleteSession.py
1 # $Id$
2 # $URL$
3 import time
4
5 from PLC.Method import Method
6 from PLC.Parameter import Parameter, Mixed
7 from PLC.Auth import SessionAuth
8 from PLC.Sessions import Session, Sessions
9
10 class DeleteSession(Method):
11     """
12     Invalidates the current session.
13
14     Returns 1 if successful.
15     """
16
17     roles = ['admin', 'pi', 'user', 'tech', 'node']
18     accepts = [SessionAuth()]
19     returns = Parameter(int, '1 if successful')
20
21
22     def call(self, auth):
23         assert auth.has_key('session')
24
25         sessions = Sessions(self.api, [auth['session']])
26         if not sessions:
27             raise PLCAPIError, "No such session"
28         session = sessions[0]
29
30         session.delete()
31
32         return 1