python3 - 2to3 + miscell obvious tweaks
[sfa.git] / sfa / dummy / dummyshell.py
1 import sys
2 import socket
3 from urllib.parse import urlparse
4
5 from sfa.util.sfalogging import logger
6 from sfa.util.py23 import xmlrpc_client
7
8
9 class DummyShell:
10     """
11     A simple xmlrpc shell to the dummy testbed API instance
12
13     """
14
15     direct_calls = ['AddNode', 'AddSlice', 'AddUser', 'AddUserKey', 'AddUserToSlice', 'AddSliceToNodes',
16                     'GetTestbedInfo', 'GetNodes', 'GetSlices', 'GetUsers',
17                     'DeleteNode', 'DeleteSlice', 'DeleteUser', 'DeleteKey', 'DeleteUserFromSlice',
18                     'DeleteSliceFromNodes',
19                     'UpdateNode', 'UpdateSlice', 'UpdateUser',
20                     ]
21
22     def __init__(self, config):
23         url = config.SFA_DUMMY_URL
24         self.proxy = xmlrpc_client.ServerProxy(
25             url, verbose=False, allow_none=True)
26
27     def __getattr__(self, name):
28         def func(*args, **kwds):
29             if not name in DummyShell.direct_calls:
30                 raise Exception(
31                     "Illegal method call %s for DUMMY driver" % (name))
32             result = getattr(self.proxy, name)(*args, **kwds)
33             logger.debug('DummyShell %s returned ... ' % (name))
34             return result
35         return func