git://git.onelab.eu
/
nodemanager.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cleanup leftovers from debian
[nodemanager.git]
/
conf_files.py
diff --git
a/conf_files.py
b/conf_files.py
index
bccf20a
..
7b0cada
100644
(file)
--- a/
conf_files.py
+++ b/
conf_files.py
@@
-1,19
+1,22
@@
-# $Id$
-# $URL$
-
"""configuration files"""
import grp
import os
import pwd
"""configuration files"""
import grp
import os
import pwd
-import sha
+try:
+ from hashlib import sha1 as sha
+except ImportError:
+ from sha import sha
import string
import curlwrapper
import logger
import tools
import string
import curlwrapper
import logger
import tools
-import xmlrpclib
-from config import Config
+import xmlrpc.client
+from config import Config
+
+# right after net
+priority = 2
class conf_files:
def __init__(self, noscripts=False):
class conf_files:
def __init__(self, noscripts=False):
@@
-24,7
+27,7
@@
class conf_files:
def checksum(self, path):
try:
f = open(path)
def checksum(self, path):
try:
f = open(path)
- try: return sha
.new
(f.read()).digest()
+ try: return sha(f.read()).digest()
finally: f.close()
except IOError: return None
finally: f.close()
except IOError: return None
@@
-42,12
+45,12
@@
class conf_files:
try:
uid = pwd.getpwnam(cf_rec['file_owner'])[2]
except:
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:
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
return
url = 'https://%s/%s' % (self.config.PLC_BOOT_HOST, cf_rec['source'])
# set node_id at the end of the request - hacky
@@
-56,14
+59,14
@@
class conf_files:
else: url += '?'
url += "node_id=%d"%tools.node_id()
else:
else: url += '?'
url += "node_id=%d"%tools.node_id()
else:
- logger.log('%s -- WARNING, cannot add node_id to request'%dest)
+ logger.log('
conf_files:
%s -- WARNING, cannot add node_id to request'%dest)
try:
try:
- logger.verbose("retrieving URL=%s"%url)
+ logger.verbose("
conf_files:
retrieving URL=%s"%url)
contents = curlwrapper.retrieve(url, self.config.cacert)
contents = curlwrapper.retrieve(url, self.config.cacert)
- except xmlrpc
lib.ProtocolError,
e:
+ except xmlrpc
.client.ProtocolError as
e:
logger.log('conf_files: failed to retrieve %s from %s, skipping' % (dest, url))
return
logger.log('conf_files: failed to retrieve %s from %s, skipping' % (dest, url))
return
- if not cf_rec['always_update'] and sha
.new
(contents).digest() == self.checksum(dest):
+ if not cf_rec['always_update'] and sha(contents).digest() == self.checksum(dest):
return
if self.system(cf_rec['preinstall_cmd']):
self.system(err_cmd)
return
if self.system(cf_rec['preinstall_cmd']):
self.system(err_cmd)
@@
-71,18
+74,19
@@
class conf_files:
logger.log('conf_files: installing file %s from %s' % (dest, url))
try: os.makedirs(os.path.dirname(dest))
except OSError: pass
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 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)
for f in data['conf_files']:
try: self.update_conf_file(f)
- except: logger.log_exc("failed to update conf_file")
- else: logger.log("conf_files: No conf_files found or API failure. Skipping")
+ except: logger.log_exc("conf_files: failed to update conf_file")
+ else:
+ logger.log_missing_data("conf_files.run_once", 'conf_files')
-def start(
options, config
): pass
+def start(): pass
def GetSlivers(data, config = None, plc = None):
logger.log("conf_files: Running.")
def GetSlivers(data, config = None, plc = None):
logger.log("conf_files: Running.")
@@
-103,7
+107,8
@@
if __name__ == '__main__':
# Load /etc/planetlab/session
if os.path.exists(options.session):
# 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
else:
session = options.session