5 from Remote import Remote
6 from Table import Table
8 class PLC(dict, Remote):
10 'name': 'TestPLC', # PLC Name
11 'host': 'localhost', # Node Hostname
12 'ip': '127.0.0.1', # IP
13 'chroot': None, # Path to the chroot
14 'vserver': None, # Vserver where this PLC lives
15 'rootkey': None, # Root Key
16 'api_path': '/PLCAPI/', # PLCAPI path
17 'port': '443' # PLCAPI port
21 def __init__(self, config, fields = {}):
22 # XX Filter out fields not specified in fields
23 dict.__init__(self, self.fields)
25 # Merge defined fields with defaults
34 command = "/sbin/ifconfig eth0 | grep -v inet6 | grep inet | awk '{print$2;}'"
35 (status, output) = self.commands(command)
36 ip = re.findall(r'[0-9\.]+', output)[0]
39 self['ip'] = ip.strip()
44 # If plc is specified, find its configuration
47 name, ip, port, path = self['name'], self['ip'], self['port'], self['api_path']
48 if self.config.verbose:
49 utils.header("Updating %(name)s's api to https://%(ip)s:%(port)s/%(path)s" % locals())
50 api_server = "https://%(ip)s:%(port)s/%(path)s" % locals()
51 self.config.api = xmlrpclib.Server(api_server, allow_none = 1)
52 self.config.api_type = 'xmlrpc'
54 class PLCs(list, Table):
56 def __init__(self, config, plcs):
57 plclist = [PLC(config, plc) for plc in plcs]
58 list.__init__(self, plclist)