- if not cf_rec['ignore_cmd_errors']: return
- logger.log('conf_files: installing file %s' % dest)
- try: os.makedirs(os.path.dirname(dest))
- except OSError: pass
- tools.write_file(dest, lambda f: f.write(contents), mode=mode, uidgid=(uid,gid))
- if self.system(cf_rec['postinstall_cmd']): self.system(err_cmd)
-
- def run(self):
- while True:
- self.cond.acquire()
- while self.data == None: self.cond.wait()
- data = self.data
- self.data = None
- self.cond.release()
- for d in data:
- for f in d['conf_files']:
- try: self.update_conf_file(f)
- except: logger.log_exc()
-
- def callback(self, data):
- if data != None:
- self.cond.acquire()
- self.data = data
- self.cond.notify()
- self.cond.release()
-
-main = conf_files()
-
-def GetSlivers_callback(data): main.callback(data)
-
-def start(options): tools.as_daemon_thread(main.run)
+ if not cf_rec['ignore_cmd_errors']:
+ return
+ logger.log('conf_files: installing file %s from %s' % (dest, url))
+ try:
+ os.makedirs(os.path.dirname(dest))
+ except OSError:
+ pass
+ tools.write_file(dest, lambda f: f.write(contents.decode()),
+ mode=mode, uidgid=(uid, gid))
+ if self.system(cf_rec['postinstall_cmd']):
+ self.system(err_cmd)
+
+ def run_once(self, data):
+ if "conf_files" in data:
+ for file in data['conf_files']:
+ try:
+ self.update_conf_file(file)
+ except:
+ logger.log_exc("conf_files: failed to update conf_file")
+ else:
+ logger.log_missing_data("conf_files.run_once", 'conf_files')
+
+
+def start():
+ pass
+
+
+def GetSlivers(data, config=None, plc=None):
+ logger.log("conf_files: Running.")
+ instance = conf_files()
+ instance.run_once(data)
+ logger.log("conf_files: Done.")
+
+
+def main():
+ from argparse import ArgumentParser
+ parser = ArgumentParser()
+ parser.add_argument('-f', '--config', action='store', dest='config',
+ default='/etc/planetlab/plc_config',
+ help='PLC configuration file')
+ parser.add_argument('-k', '--session', action='store', dest='session',
+ default='/etc/planetlab/session',
+ help='API session key (or file)')
+ parser.add_argument('--noscripts', action='store_true', dest='noscripts',
+ default=False,
+ help='Do not run pre- or post-install scripts')
+ args = parser.parse_args()
+
+ # Load /etc/planetlab/plc_config
+ config = Config(args.config)
+
+ # Load /etc/planetlab/session
+ if os.path.exists(args.session):
+ with open(args.session) as feed:
+ session = feed.read().strip()
+ else:
+ session = args.session
+
+ # Initialize XML-RPC client
+ from plcapi import PLCAPI
+ plc = PLCAPI(config.plc_api_uri, config.cacert, auth=session)
+ data = plc.GetSlivers()
+
+ instance = conf_files(args.noscripts)
+ instance.run_once(data)
+
+
+if __name__ == '__main__':
+ main()