X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=conf_files.py;h=da4c313e8e56013d769c550ad4aeeb2435d8c592;hb=188be188d60d2999bd4577d686c60a0e7f2b27f8;hp=c16639f1e2337ba9aa50e0443e73563bcb389822;hpb=08d6f2b70b86a10b222a5afe80945598296196ad;p=nodemanager.git diff --git a/conf_files.py b/conf_files.py index c16639f..da4c313 100644 --- a/conf_files.py +++ b/conf_files.py @@ -1,6 +1,3 @@ -# $Id$ -# $URL$ - """configuration files""" import grp @@ -10,12 +7,11 @@ try: from hashlib import sha1 as sha except ImportError: from sha import sha -import string import curlwrapper import logger import tools -import xmlrpclib +import xmlrpc.client from config import Config # right after net @@ -44,16 +40,16 @@ class conf_files: if not cf_rec['enabled']: return dest = cf_rec['dest'] err_cmd = cf_rec['error_cmd'] - mode = string.atoi(cf_rec['file_permissions'], base=8) + mode = int(cf_rec['file_permissions'], base=8) try: uid = pwd.getpwnam(cf_rec['file_owner'])[2] except: - logger.log('conf_files: cannot find user %s -- %s not updated'%(cf_rec['file_owner'],dest)) + logger.log('conf_files: cannot find user %s -- %s not updated'%(cf_rec['file_owner'], dest)) return try: gid = grp.getgrnam(cf_rec['file_group'])[2] except: - logger.log('conf_files: cannot find group %s -- %s not updated'%(cf_rec['file_group'],dest)) + logger.log('conf_files: cannot find group %s -- %s not updated'%(cf_rec['file_group'], dest)) return url = 'https://%s/%s' % (self.config.PLC_BOOT_HOST, cf_rec['source']) # set node_id at the end of the request - hacky @@ -66,7 +62,7 @@ class conf_files: try: logger.verbose("conf_files: retrieving URL=%s"%url) contents = curlwrapper.retrieve(url, self.config.cacert) - except xmlrpclib.ProtocolError,e: + except xmlrpc.client.ProtocolError as e: logger.log('conf_files: failed to retrieve %s from %s, skipping' % (dest, url)) return if not cf_rec['always_update'] and sha(contents).digest() == self.checksum(dest): @@ -77,16 +73,16 @@ class conf_files: 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), mode=mode, uidgid=(uid,gid)) + 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_once(self, data): - if data.has_key("conf_files"): + if "conf_files" in data: for f in data['conf_files']: try: self.update_conf_file(f) except: logger.log_exc("conf_files: failed to update conf_file") else: - logger.log_missing_data("conf_files.run_once",'conf_files') + logger.log_missing_data("conf_files.run_once", 'conf_files') def start(): pass @@ -110,7 +106,8 @@ if __name__ == '__main__': # Load /etc/planetlab/session if os.path.exists(options.session): - session = file(options.session).read().strip() + with open(options.session) as f: + session = f.read().strip() else: session = options.session