import curlwrapper
import logger
import tools
-
+import xmlrpclib
class conf_files:
def __init__(self, config, noscripts=False):
def system(self, cmd):
if not self.noscripts and cmd:
- logger.log('conf_files: running command %s' % cmd)
- return os.system(cmd)
+ logger.verbose('conf_files: running command %s' % cmd)
+ return tools.fork_as(None, os.system, cmd)
else: return 0
def update_conf_file(self, cf_rec):
if not cf_rec['enabled']: return
dest = cf_rec['dest']
- # XXX Remove once old Node Manager is out of service
- if dest == '/etc/proper/propd.conf': return
err_cmd = cf_rec['error_cmd']
mode = string.atoi(cf_rec['file_permissions'], base=8)
- uid = pwd.getpwnam(cf_rec['file_owner'])[2]
- gid = grp.getgrnam(cf_rec['file_group'])[2]
+ 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))
+ 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))
+ return
url = 'https://%s/%s' % (self.config.PLC_BOOT_HOST, cf_rec['source'])
- contents = curlwrapper.retrieve(url, self.config.cacert)
+ # set node_id at the end of the request - hacky
+ if tools.node_id():
+ if url.find('?') >0: url += '&'
+ else: url += '?'
+ url += "node_id=%d"%tools.node_id()
+ else:
+ logger.log('%s -- WARNING, cannot add node_id to request'%dest)
+ # pass slicefamily as well, as stored in /etc/planetlab/slicefamily ont the node
+ if tools.slicefamily():
+ if url.find('?') >0: url += '&'
+ else: url += '?'
+ url += "slicefamily=%s"%tools.slicefamily()
+ try:
+ logger.verbose("retrieving URL=%s"%url)
+ contents = curlwrapper.retrieve(url, self.config.cacert)
+ except xmlrpclib.ProtocolError,e:
+ 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):
return
if self.system(cf_rec['preinstall_cmd']):
parser = optparse.OptionParser()
parser.add_option('-f', '--config', action='store', dest='config', default='/etc/planetlab/plc_config', help='PLC configuration file')
parser.add_option('-k', '--session', action='store', dest='session', default='/etc/planetlab/session', help='API session key (or file)')
- parser.add_option('--noscripts', action='store', dest='noscripts', default=False, help='Do not run pre- or post-install scripts')
+ parser.add_option('--noscripts', action='store_true', dest='noscripts', default=False, help='Do not run pre- or post-install scripts')
(options, args) = parser.parse_args()
# Load /etc/planetlab/plc_config