5 from Remote import Remote
6 from Table import Table
7 from logger import Logfile
9 class PLC(dict, Remote):
11 'name': 'TestPLC', # PLC Name
12 'host': 'localhost', # Node Hostname
13 'ip': '127.0.0.1', # IP
14 'chroot': None, # Path to the chroot
15 'vserver': None, # Vserver where this PLC lives
16 'host_rootkey': None, # Root Key
17 'api_path': '/PLCAPI/', # PLCAPI path
18 'port': '443' # PLCAPI port
22 def __init__(self, config, fields = {}):
23 # XX Filter out fields not specified in fields
24 dict.__init__(self, self.fields)
26 # Merge defined fields with defaults
31 self.__init_logfile__()
33 def __init_logfile__(self, filename = None):
35 filename = '%s/qaapi.log' % (self.config.logdir)
36 self.logfile = Logfile(filename)
40 command = "/sbin/ifconfig eth0 | grep -v inet6 | grep inet | awk '{print$2;}'"
41 (status, output) = self.commands(command)
42 ip = re.findall(r'[0-9\.]+', output)[0]
45 self['ip'] = ip.strip()
50 # If plc is specified, find its configuration
53 name, ip, port, path = self['name'], self['ip'], self['port'], self['api_path']
54 if self.config.verbose:
55 utils.header("Updating %(name)s's api to https://%(ip)s:%(port)s/%(path)s" % locals(), logfile = self.config.logfile)
56 api_server = "https://%(ip)s:%(port)s/%(path)s" % locals()
57 self.config.api = xmlrpclib.Server(api_server, allow_none = 1)
58 self.config.api_type = 'xmlrpc'
60 def update_node_images(self):
63 def scp_to_webroot(self, localfiles, recursive = False):
64 if self.config.verbose:
65 utils.header("Copying %s to %s webroot" % (localfiles, self['name']), logfile = self.config.logfile)
66 self.scp_to("%(localfiles)s" % locals(), "/var/www/html/")
67 url = 'http://%s/%s' % (self['ip'], localfiles)
73 def __init__(self, config, plcs):
74 plclist = [PLC(config, plc) for plc in plcs]
75 Table.__init__(self, plclist)