8 class plc_configure(Test):
10 Configure the myplc from config options in config file
13 def call(self, plc_config_option=None, plc_config_value=None):
15 services = ['API', 'DB', 'WWW', 'BOOT']
17 # Turn off plc (for good measure)
18 command = "/sbin/service plc stop"
19 if self.config.verbose: utils.header(command)
20 (stdout, stderr) = utils.popen(command)
22 # mount plc (need to do this optionally, as we do not want this for myplc-native)
23 command = "/sbin/service plc mount"
24 if self.config.verbose: utils.header(command)
25 (stdout, stderr) = utils.popen(command)
27 # Get plc configuration variables
28 if plc_config_option is not None and \
29 plc_config_value is not None:
30 # Set option passed in from user
31 plc_options.append((plc_config_option, plc_config_value))
33 # Use hostname and ip of host we are running on
34 for service in services:
35 host_option = 'PLC_%(service)s_HOST' % locals()
36 ip_option = 'PLC_%(service)s_IP' % locals()
37 plc_options.append((host_option, self.config.hostname))
38 plc_options.append((ip_option, self.config.ip))
39 # Load any other options found in config file
40 for attr in dir(self.config):
41 if attr.startswith('PLC'):
42 plc_options.append((attr, getattr(self.config, attr)))
44 # Write temporary plc-config file
45 tmpfconf, tmpfname = tempfile.mkstemp(".config","plc-config-tty")
46 if self.config.verbose:
47 utils.header("generating temporary config file %(tmpfname)s"%locals())
48 for (option, value) in plc_options:
49 os.write(tmpfconf, 'e %s\n%s\n' % (option, value))
50 os.write(tmpfconf,'w\nq\n')
54 command = "plc-config-tty < %(tmpfname)s" % locals()
55 if self.config.verbose: utils.header(command)
56 (stdout, stderr) = utils.popen(command)
58 # clean up temporary conf file
59 if self.config.verbose: utils.header("removing %(tmpfname)s"%locals())
62 # umount plc (need to do this optionally, as we do not want this for myplc-native)
63 command = "/sbin/service plc umount"
64 if self.config.verbose: utils.header(command)
65 (stdout, stderr) = utils.popen(command)
69 if __name__ == '__main__':
70 args = tuple(sys.argv[1:])
71 plc_configure()(*args)