added start_xmlrpc_server() which is used to start a standalone xmlrpc server alterna...
[tests.git] / qaapi / qa / PLCs.py
1 import os
2 import copy     
3 from Remote import Remote
4 from Table import Table
5
6 class PLC(dict, Remote):
7     fields = {
8         'name': 'TestPLC',                              # PLC Name                      
9         'host': 'localhost',                            # Node Hostname
10         'ip':   '127.0.0.1',                            # IP
11         'chroot': None,
12         'vserver': None,                                # Vserver where this PLC lives
13         'rootkey': '/home/tmack/.ssh/plc-root',         # Root Key
14         'api_path': '/PLCAPI/',                                 # PLCAPI path 
15         'port': '443'                                   # PLCAPI port
16         
17         }
18
19     def __init__(self, config, fields = {}):
20         # XX Filter out fields not specified in fields
21         dict.__init__(self, self.fields)
22         
23         # Merge defined fields with defaults
24         self.update(fields)
25         
26         # init config
27         self.config = config
28         self.config.update_api(self)
29
30     def start_xmlrpc_server(self):
31         """
32         PLCAPI comes with a SimpleServer script that allows you to run a 
33         standalone http server that listens on the specified port.
34         This is useful for running multiple api servers on the same machine.
35         """
36         if 'host' in self and not host in ['localhost', None]:
37             server_script = "/usr/share/plc_api/Server.py" 
38             self.commands("%s -p %s" % (server_script, self['port']))    
39  
40
41 class PLCs(list, Table):
42
43     def __init__(self, config, plcs):
44         plclist = [PLC(config, plc) for plc in plcs]
45         list.__init__(self, plclist)