2to3 -f raise
[sfa.git] / sfa / nitos / nitosshell.py
1 import sys
2 import xmlrpclib
3 import socket
4 from urlparse import urlparse
5
6 from sfa.util.sfalogging import logger
7
8 class NitosShell:
9     """
10     A simple xmlrpc shell to a NITOS Scheduler instance
11     This class can receive all NITOS API  calls to the underlying testbed
12     For safety this is limited to a set of hard-coded calls
13     """
14     
15     direct_calls = ['getNodes','getChannels','getSlices','getUsers','getReservedNodes',
16                     'getReservedChannels','getTestbedInfo',
17                     'reserveNodes','reserveChannels','addSlice','addUser','addUserToSlice',
18                     'addUserKey','addNode', 'addChannel',
19                     'updateReservedNodes','updateReservedChannels','updateSlice','updateUser',
20                     'updateNode', 'updateChannel',
21                     'deleteNode','deleteChannel','deleteSlice','deleteUser', 'deleteUserFromSLice',
22                     'deleteKey', 'releaseNodes', 'releaseChannels'
23                     ]
24
25
26     # use the 'capability' auth mechanism for higher performance when the PLC db is local    
27     def __init__ ( self, config ) :
28         url = config.SFA_NITOS_URL
29         self.proxy = xmlrpclib.Server(url, verbose = False, allow_none = True)
30
31     def __getattr__(self, name):
32         def func(*args, **kwds):
33             actual_name=None
34             if name in NitosShell.direct_calls: actual_name=name
35             if not actual_name:
36                 raise Exception("Illegal method call %s for NITOS driver"%(name))
37             actual_name = "scheduler.server." + actual_name
38             result=getattr(self.proxy, actual_name)(*args, **kwds)
39             logger.debug('NitosShell %s (%s) returned ... '%(name,actual_name))
40             return result
41         return func
42