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