Commit 00d5fa49 authored by Marco Mariani's avatar Marco Mariani

node register: use logging

parent 93f77978
...@@ -98,22 +98,18 @@ def get_computer_name(certificate): ...@@ -98,22 +98,18 @@ def get_computer_name(certificate):
def save_former_config(conf): def save_former_config(conf):
"""Save former configuration if found""" """Save former configuration if found"""
# Check for config file in /etc/opt/slapos/ former = '/etc/opt/slapos'
if os.path.exists('/etc/opt/slapos/slapos.cfg'): if not os.path.exists(os.path.join(former, 'slapos.cfg')):
former = '/etc/opt/slapos'
else:
return return
saved = former + '.old' saved = former + '.old'
while True: while os.path.exists(saved):
if os.path.exists(saved): conf.logger.info('Slapos configuration detected in %s', saved)
print "Slapos configuration detected in %s" % saved if saved[-1] == 'd':
if saved[-1] != 'd': saved += '.1'
saved = saved[:-1] + str(int(saved[-1]) + 1)
else:
saved += '.1'
else: else:
break # XXX this goes from 19 to 110
saved = saved[:-1] + str(int(saved[-1]) + 1)
conf.logger.info('Former slapos configuration detected ' conf.logger.info('Former slapos configuration detected '
'in %s moving to %s', former, saved) 'in %s moving to %s', former, saved)
shutil.move(former, saved) shutil.move(former, saved)
...@@ -292,15 +288,15 @@ def do_register(conf): ...@@ -292,15 +288,15 @@ def do_register(conf):
# Prepare Slapos Configuration # Prepare Slapos Configuration
slapconfig(conf) slapconfig(conf)
print "Node has successfully been configured as %s." % COMP conf.logger.info('Node has successfully been configured as %s.', COMP)
# XXX hardcoded value, relying on package installation # XXX hardcoded value, relying on package installation
# We shall fix that later # We shall fix that later
print "Running starting script" conf.logger.info('Running starting script')
if os.path.isfile("/usr/sbin/slapos-start"): if os.path.isfile("/usr/sbin/slapos-start"):
try: try:
subprocess.check_call("/usr/sbin/slapos-start") subprocess.check_call("/usr/sbin/slapos-start")
except CalledProcessError: except CalledProcessError:
print "Error while trying to run /usr/sbin/slapos-start" conf.logger.error('Error while trying to run /usr/sbin/slapos-start')
else: else:
print "Missing file /usr/sbin/slapos-start" conf.logger.warning('Missing file /usr/sbin/slapos-start')
return 0 return 0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment