Commit 66c9dd1f authored by Marco Mariani's avatar Marco Mariani

whitespace, except..as syntax, typos

parent 54ea0de7
...@@ -30,12 +30,12 @@ from optparse import OptionParser, Option ...@@ -30,12 +30,12 @@ from optparse import OptionParser, Option
import ConfigParser import ConfigParser
import os import os
import pkg_resources import pkg_resources
import pwd
import socket import socket
import subprocess import subprocess
import sys import sys
import time import time
import urllib2 import urllib2
from pwd import getpwnam
import iniparse import iniparse
...@@ -73,7 +73,6 @@ class Parser(OptionParser): ...@@ -73,7 +73,6 @@ class Parser(OptionParser):
return options return options
class SlapError(Exception): class SlapError(Exception):
""" """
Slap error Slap error
...@@ -81,14 +80,15 @@ class SlapError(Exception): ...@@ -81,14 +80,15 @@ class SlapError(Exception):
def __init__(self, message): def __init__(self, message):
self.msg = message self.msg = message
class UsageError(SlapError): class UsageError(SlapError):
pass pass
class ExecError(SlapError): class ExecError(SlapError):
pass pass
def _call(cmd_args, stdout=None, stderr=None, dry_run=False): def _call(cmd_args, stdout=None, stderr=None, dry_run=False):
""" """
Wrapper for subprocess.call() which'll secure the usage of external program's. Wrapper for subprocess.call() which'll secure the usage of external program's.
...@@ -103,15 +103,15 @@ def _call(cmd_args, stdout=None, stderr=None, dry_run=False): ...@@ -103,15 +103,15 @@ def _call(cmd_args, stdout=None, stderr=None, dry_run=False):
if subprocess.call(cmd_args, stdout=stdout, stderr=stderr) != 0: if subprocess.call(cmd_args, stdout=stdout, stderr=stderr) != 0:
raise ValueError('Issues during running %r' % cmd_args) raise ValueError('Issues during running %r' % cmd_args)
except OSError as e: except OSError as e:
raise ExecError('Process respond:"%s" when calling "%s"' % \ raise ExecError('Process responded: "%s" when calling "%s"' %
(str(e), ' '.join(cmd_args))) (e, ' '.join(cmd_args)))
# Utility function to get yes/no answers # Utility function to get yes/no answers
def get_yes_no(prompt, default=None): def get_yes_no(prompt, default=None):
if default: if default:
def_value = '/ Default yes' def_value = '/ Default yes'
elif default == False: elif default is False:
def_value = '/ Default no' def_value = '/ Default no'
else: else:
def_value = '' def_value = ''
...@@ -190,7 +190,7 @@ def get_ssh(temp_dir): ...@@ -190,7 +190,7 @@ def get_ssh(temp_dir):
gotten = True gotten = True
except ValueError: except ValueError:
# add http:// if it is missing (needed by urllib2) # add http:// if it is missing (needed by urllib2)
ssh_web = """http://"""+ssh_web ssh_web = """http://""" + ssh_web
ssh_key_all = urllib2.urlopen(''.join(ssh_web)) ssh_key_all = urllib2.urlopen(''.join(ssh_web))
gotten = True gotten = True
except urllib2.URLError: except urllib2.URLError:
...@@ -268,7 +268,6 @@ def slapserver(config): ...@@ -268,7 +268,6 @@ def slapserver(config):
pkg_resources.resource_stream(__name__, pkg_resources.resource_stream(__name__,
'template/ifcfg-br0.in').read()) 'template/ifcfg-br0.in').read())
# Creating default limits config # Creating default limits config
limits_conf_path = os.path.join(mount_dir_path, limits_conf_path = os.path.join(mount_dir_path,
'etc', 'security', 'limits.conf') 'etc', 'security', 'limits.conf')
...@@ -335,7 +334,6 @@ def slapserver(config): ...@@ -335,7 +334,6 @@ def slapserver(config):
return 0 return 0
def prepare_scripts(config): def prepare_scripts(config):
""" """
Will prepare script for slapos dedicated computer Will prepare script for slapos dedicated computer
...@@ -348,9 +346,9 @@ def prepare_scripts(config): ...@@ -348,9 +346,9 @@ def prepare_scripts(config):
else: else:
# Check for config file in /etc/slapos/ # Check for config file in /etc/slapos/
if os.path.exists('/etc/slapos/slapos.cfg'): if os.path.exists('/etc/slapos/slapos.cfg'):
slapos_configuration='/etc/slapos/' slapos_configuration = '/etc/slapos/'
else: else:
slapos_configuration='/etc/opt/slapos/' slapos_configuration = '/etc/opt/slapos/'
# Creating boot script # Creating boot script
path = os.path.join('/', 'usr', 'sbin', 'slapos-boot-dedicated') path = os.path.join('/', 'usr', 'sbin', 'slapos-boot-dedicated')
...@@ -359,7 +357,7 @@ def prepare_scripts(config): ...@@ -359,7 +357,7 @@ def prepare_scripts(config):
open(path, 'w').write( open(path, 'w').write(
pkg_resources.resource_stream(__name__, pkg_resources.resource_stream(__name__,
'script/%s' % 'slapos').read() 'script/%s' % 'slapos').read()
% dict(slapos_configuration=slapos_configuration) ) % {'slapos_configuration': slapos_configuration})
os.chmod(path, 0755) os.chmod(path, 0755)
path = os.path.join('/', 'etc', path = os.path.join('/', 'etc',
...@@ -396,7 +394,7 @@ def configureNtp(): ...@@ -396,7 +394,7 @@ def configureNtp():
continue continue
new_ntp.write(line) new_ntp.write(line)
new_ntp.write(SLAPOS_MARK) new_ntp.write(SLAPOS_MARK)
new_ntp.write(server+'\n') new_ntp.write(server + '\n')
new_ntp.close() new_ntp.close()
_call(['chkconfig', '--add', 'ntp']) _call(['chkconfig', '--add', 'ntp'])
_call(['chkconfig', 'ntp', 'on']) _call(['chkconfig', 'ntp', 'on'])
...@@ -404,8 +402,6 @@ def configureNtp(): ...@@ -404,8 +402,6 @@ def configureNtp():
_call(['systemctl', 'restart', 'ntp.service']) _call(['systemctl', 'restart', 'ntp.service'])
class Config: class Config:
def setConfig(self, option_dict): def setConfig(self, option_dict):
""" """
...@@ -415,7 +411,6 @@ class Config: ...@@ -415,7 +411,6 @@ class Config:
for option, value in option_dict.__dict__.items(): for option, value in option_dict.__dict__.items():
setattr(self, option, value) setattr(self, option, value)
def slaposConfig(self, def slaposConfig(self,
mount_dir_path, mount_dir_path,
slapos_configuration, slapos_configuration,
...@@ -436,7 +431,6 @@ class Config: ...@@ -436,7 +431,6 @@ class Config:
self.temp_dir = temp_dir self.temp_dir = temp_dir
self.computer_id = computer_id self.computer_id = computer_id
def userConfig(self): def userConfig(self):
# XXX-Testme: test each possible scenario # XXX-Testme: test each possible scenario
# XXX don't use self.xx but return a dict so that it is stateless # XXX don't use self.xx but return a dict so that it is stateless
...@@ -477,7 +471,6 @@ class Config: ...@@ -477,7 +471,6 @@ class Config:
return True return True
def displayUserConfig(self): def displayUserConfig(self):
# XXX print everything from configuration, not arbitrary members # XXX print everything from configuration, not arbitrary members
if self.certificates: if self.certificates:
...@@ -550,7 +543,7 @@ def prepare_from_scratch(config): ...@@ -550,7 +543,7 @@ def prepare_from_scratch(config):
print "Your Computer is : %s" % computer_id print "Your Computer is : %s" % computer_id
config.slaposConfig(mount_dir_path = '/', config.slaposConfig(mount_dir_path='/',
slapos_configuration=slapos_configuration, slapos_configuration=slapos_configuration,
hostname_path='/etc/HOSTNAME', hostname_path='/etc/HOSTNAME',
host_path='/etc/hosts', host_path='/etc/hosts',
...@@ -570,19 +563,17 @@ def prepare_from_scratch(config): ...@@ -570,19 +563,17 @@ def prepare_from_scratch(config):
_call(['zypper', '--gpg-auto-import-keys', 'install', '-fy', 'slapos.node']) _call(['zypper', '--gpg-auto-import-keys', 'install', '-fy', 'slapos.node'])
_call(['systemctl', 'stop', 'slapos-node.service']) _call(['systemctl', 'stop', 'slapos-node.service'])
return_code = 0 return_code = 0
except ExecError, err: except ExecError as err:
print >>sys.stderr, err.msg print >>sys.stderr, err.msg
return_code = 16 return_code = 16
except SystemExit, err: except SystemExit as err:
# Catch exception raise by optparse # Catch exception raise by optparse
return_code = err return_code = err
if os.path.exists(temp_directory): if os.path.exists(temp_directory):
print "Deleting directory: %s" % temp_directory print "Deleting directory: %s" % temp_directory
_call(['rm', '-rf', temp_directory]) _call(['rm', '-rf', temp_directory])
# Add/remove VPN file forcing/forbidding start of VPN. # Add/remove VPN file forcing/forbidding start of VPN.
if not config.dry_run: if not config.dry_run:
openvpn_needed_file_path = os.path.join(slapos_configuration, openvpn_needed_file_path = os.path.join(slapos_configuration,
...@@ -609,26 +600,30 @@ def chownSlaposDirectory(): ...@@ -609,26 +600,30 @@ def chownSlaposDirectory():
path = slapos_slapgrid_instance path = slapos_slapgrid_instance
print "Changing owners of software directory and partitions directories…" print "Changing owners of software directory and partitions directories…"
for i in range(int(slapformat_partition)): for i in range(int(slapformat_partition)):
uid = getpwnam('%s%s' % (slapformat_user_base_name, i) )[2] uid = pwd.getpwnam('%s%s' % (slapformat_user_base_name, i))[2]
gid = getpwnam('%s%s' % (slapformat_user_base_name, i) )[3] gid = pwd.getpwnam('%s%s' % (slapformat_user_base_name, i))[3]
item = '%s%s' % (slapformat_partition_base_name, i) item = '%s%s' % (slapformat_partition_base_name, i)
if not os.path.islink(os.path.join(path, item)): if not os.path.islink(os.path.join(path, item)):
os.chown(os.path.join(path, item), uid, gid) os.chown(os.path.join(path, item), uid, gid)
for i in range(int(slapformat_partition)): for i in range(int(slapformat_partition)):
path = "%s/%s%s" % ( slapos_slapgrid_instance, slapformat_partition_base_name, i) path = "%s/%s%s" % (slapos_slapgrid_instance, slapformat_partition_base_name, i)
for root, dirs, files in os.walk(path): for root, dirs, files in os.walk(path):
for items in dirs, files: for items in dirs, files:
for item in items: for item in items:
if not os.path.islink(os.path.join(root, item)): if not os.path.islink(os.path.join(root, item)):
os.chown(os.path.join(root, item), getpwnam('%s%s' % (slapformat_user_base_name, i) )[2], getpwnam('%s%s' % (slapformat_user_base_name, i) )[3]) os.chown(os.path.join(root, item),
pwd.getpwnam('%s%s' % (slapformat_user_base_name, i))[2],
pwd.getpwnam('%s%s' % (slapformat_user_base_name, i))[3])
# chown of software root (/opt/slapgrid) # chown of software root (/opt/slapgrid)
for root, dirs, files in os.walk(slapos_slapgrid_software): for root, dirs, files in os.walk(slapos_slapgrid_software):
for items in dirs, files: for items in dirs, files:
for item in items: for item in items:
if not os.path.islink(os.path.join(root, item)): if not os.path.islink(os.path.join(root, item)):
os.chown(os.path.join(root, item), getpwnam('slapsoft')[2], getpwnam('slapsoft')[3]) os.chown(os.path.join(root, item),
pwd.getpwnam('slapsoft')[2],
pwd.getpwnam('slapsoft')[3])
def slapprepare(): def slapprepare():
...@@ -642,8 +637,8 @@ def slapprepare(): ...@@ -642,8 +637,8 @@ def slapprepare():
# Install/update slapos # Install/update slapos
try: try:
_call(['zypper', 'addrepo', '-fc', '-n', '"SlapOS Official repo"' _call(['zypper', 'addrepo', '-fc', '-n', '"SlapOS Official repo"',
,'http://download.opensuse.org/repositories/home:/VIFIBnexedi/openSUSE_%s/' % suse_version(), 'slapos']) 'http://download.opensuse.org/repositories/home:/VIFIBnexedi/openSUSE_%s/' % suse_version(), 'slapos'])
except: except:
pass pass
_call(['zypper', '--gpg-auto-import-keys', 'install', '-y', 'slapos.node']) _call(['zypper', '--gpg-auto-import-keys', 'install', '-y', 'slapos.node'])
...@@ -671,14 +666,14 @@ def slapprepare(): ...@@ -671,14 +666,14 @@ def slapprepare():
_call(['systemctl', 'start', 'slapos-boot-dedicated.service']) _call(['systemctl', 'start', 'slapos-boot-dedicated.service'])
return_code = 0 return_code = 0
except UsageError, err: except UsageError as err:
print >>sys.stderr, err.msg print >>sys.stderr, err.msg
print >>sys.stderr, "For help use --help" print >>sys.stderr, "For help use --help"
return_code = 16 return_code = 16
except ExecError, err: except ExecError as err:
print >>sys.stderr, err.msg print >>sys.stderr, err.msg
return_code = 16 return_code = 16
except SystemExit, err: except SystemExit as err:
# Catch exception raise by optparse # Catch exception raise by optparse
return_code = err return_code = err
sys.exit(return_code) sys.exit(return_code)
...@@ -686,4 +681,3 @@ def slapprepare(): ...@@ -686,4 +681,3 @@ def slapprepare():
def main(): def main():
slapprepare() slapprepare()
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
import ConfigParser import ConfigParser
import datetime import datetime
import logging import logging
from slapos.networkcachehelper import helper_download_network_cached_to_file
from optparse import OptionParser, Option from optparse import OptionParser, Option
import os import os
import subprocess as sub import subprocess as sub
...@@ -39,6 +38,9 @@ import sys ...@@ -39,6 +38,9 @@ import sys
import tempfile import tempfile
import autoupdate import autoupdate
from slapos.networkcachehelper import helper_download_network_cached_to_file
# create console handler and set level to warning # create console handler and set level to warning
ch = logging.StreamHandler() ch = logging.StreamHandler()
ch.setLevel(logging.WARNING) ch.setLevel(logging.WARNING)
...@@ -64,7 +66,7 @@ class Parser(OptionParser): ...@@ -64,7 +66,7 @@ class Parser(OptionParser):
Option("--srv-file", Option("--srv-file",
default='/srv/slapupdate', default='/srv/slapupdate',
help="Server status file."), help="Server status file."),
Option("-v","--verbose", Option("-v", "--verbose",
default=False, default=False,
action="store_true", action="store_true",
help="Verbose output."), help="Verbose output."),
...@@ -74,7 +76,6 @@ class Parser(OptionParser): ...@@ -74,7 +76,6 @@ class Parser(OptionParser):
action="store_true"), action="store_true"),
]) ])
def check_args(self): def check_args(self):
""" """
Check arguments Check arguments
...@@ -84,19 +85,19 @@ class Parser(OptionParser): ...@@ -84,19 +85,19 @@ class Parser(OptionParser):
class NetworkCache (): class NetworkCache ():
def __init__(self,slapos_conf): def __init__(self, slapos_conf):
if os.path.exists(slapos_conf): if os.path.exists(slapos_conf):
network_cache_info = ConfigParser.RawConfigParser() network_cache_info = ConfigParser.RawConfigParser()
network_cache_info.read(slapos_conf) network_cache_info.read(slapos_conf)
self.download_binary_cache_url = network_cache_info.get('networkcache','download-binary-cache-url') self.download_binary_cache_url = network_cache_info.get('networkcache', 'download-binary-cache-url')
self.download_cache_url = network_cache_info.get('networkcache','download-cache-url') self.download_cache_url = network_cache_info.get('networkcache', 'download-cache-url')
self.download_binary_dir_url = network_cache_info.get('networkcache','download-binary-dir-url') self.download_binary_dir_url = network_cache_info.get('networkcache', 'download-binary-dir-url')
self.signature_certificate_list = network_cache_info.get('networkcache','signature-certificate-list') self.signature_certificate_list = network_cache_info.get('networkcache', 'signature-certificate-list')
else: else:
self.download_binary_cache_url = "http://www.shacache.org/shacache" self.download_binary_cache_url = "http://www.shacache.org/shacache"
self.download_cache_url = "https://www.shacache.org/shacache" self.download_cache_url = "https://www.shacache.org/shacache"
self.download_binary_dir_url = "http://www.shacache.org/shadir" self.download_binary_dir_url = "http://www.shacache.org/shadir"
self.signature_certificate_list ="" self.signature_certificate_list = ""
self.signature_certificate_list = """ self.signature_certificate_list = """
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
...@@ -115,8 +116,6 @@ jlD7tZ2DbRKHu5FadsKWNZpqC9H0BRLjBwY= ...@@ -115,8 +116,6 @@ jlD7tZ2DbRKHu5FadsKWNZpqC9H0BRLjBwY=
""" + self.signature_certificate_list """ + self.signature_certificate_list
def _call(cmd_args, stdout=sub.PIPE, stderr=sub.PIPE, dry_run=False): def _call(cmd_args, stdout=sub.PIPE, stderr=sub.PIPE, dry_run=False):
""" """
Wrapper for subprocess.call() which'll secure the usage of external program's. Wrapper for subprocess.call() which'll secure the usage of external program's.
...@@ -128,56 +127,57 @@ def _call(cmd_args, stdout=sub.PIPE, stderr=sub.PIPE, dry_run=False): ...@@ -128,56 +127,57 @@ def _call(cmd_args, stdout=sub.PIPE, stderr=sub.PIPE, dry_run=False):
""" """
print ("Calling: %s" % ' '.join(cmd_args)) print ("Calling: %s" % ' '.join(cmd_args))
if not dry_run : if not dry_run:
p = sub.Popen(cmd_args,stdout=stdout,stderr=stderr) p = sub.Popen(cmd_args, stdout=stdout, stderr=stderr)
output,err = p.communicate() output, err = p.communicate()
return output,err return output, err
def suse_version(): def suse_version():
""" """
Return OpenSUSE version if it is SuSE Return OpenSUSE version if it is SuSE
""" """
if os.path.exists('/etc/SuSE-release') : if os.path.exists('/etc/SuSE-release'):
with open('/etc/SuSE-release') as f : with open('/etc/SuSE-release') as f:
for line in f: for line in f:
if "VERSION" in line: if "VERSION" in line:
dist = line.split() dist = line.split()
return float(dist[2]) return float(dist[2])
else : else:
return 0 return 0
def repositories_purge (): def repositories_purge():
""" """
Remove all repositories Remove all repositories
""" """
listing,err = _call(['zypper','lr']) listing, err = _call(['zypper', 'lr'])
while listing.count('\n') > 2 : while listing.count('\n') > 2:
output,err = _call(['zypper','rr','1'],stdout=None) output, err = _call(['zypper', 'rr', '1'], stdout=None)
listing,err = _call(['zypper','lr']) listing, err = _call(['zypper', 'lr'])
def repositories_add (url,alias): def repositories_add(url, alias):
""" Add a repository """ """ Add a repository """
output,err = _call(['zypper','ar','-fc',url,alias],stdout=None) output, err = _call(['zypper', 'ar', '-fc', url, alias], stdout=None)
def update_software (): def update_software():
""" Upgrade softwares """ """ Upgrade softwares """
_call(['zypper','--gpg-auto-import-keys','up','-ly'] _call(['zypper', '--gpg-auto-import-keys', 'up', '-ly'], stdout=None)
, stdout=None)
def update_system ():
def update_system():
""" Dist-Upgrade of system """ """ Dist-Upgrade of system """
_call(['zypper','--gpg-auto-import-keys','dup','-ly'], stdout = None) _call(['zypper', '--gpg-auto-import-keys', 'dup', '-ly'], stdout=None)
def update_slapprepare_scripts (): def update_slapprepare_scripts():
""" Run slapprepare -u (script that upgrade boot scripts and so on) """ """ Run slapprepare -u (script that upgrade boot scripts and so on) """
_call(['slapprepare','-u'], stdout = None) _call(['slapprepare', '-u'], stdout=None)
def download_info_from_networkcache(path,slapos_conf):
def download_info_from_networkcache(path, slapos_conf):
""" """
Download a tar of the repository from cache, and untar it. Download a tar of the repository from cache, and untar it.
""" """
...@@ -213,28 +213,30 @@ def get_info_from_master(config): ...@@ -213,28 +213,30 @@ def get_info_from_master(config):
info, path = tempfile.mkstemp() info, path = tempfile.mkstemp()
if not download_info_from_networkcache( if not download_info_from_networkcache(
path, config.slapos_configuration) == False: path, config.slapos_configuration) == False:
print open(path,'r').read() print open(path).read()
return path return path
else : else:
raise ValueError("No result from shacache") raise ValueError("No result from shacache")
def repositories_process(repositories): def repositories_process(repositories):
""" """
Remove and then add needed repositories Remove and then add needed repositories
""" """
repositories_purge() repositories_purge()
for key in repositories : for key in repositories:
repositories_add(repositories[key],key) repositories_add(repositories[key], key)
def save_current_state(current_state,config): def save_current_state(current_state, config):
""" """
Will save ConfigParser to config file Will save ConfigParser to config file
""" """
file = open(config.srv_file,"w") file = open(config.srv_file, "w")
current_state.write(file) current_state.write(file)
file.close() file.close()
def update_machine(config): def update_machine(config):
""" """
Will fetch information from web and update and/or reboot Will fetch information from web and update and/or reboot
...@@ -253,15 +255,15 @@ def update_machine(config): ...@@ -253,15 +255,15 @@ def update_machine(config):
next_state_file = get_info_from_master(config) next_state_file = get_info_from_master(config)
next_state.read(next_state_file) next_state.read(next_state_file)
os.remove(next_state_file) os.remove(next_state_file)
config.getSystemInfo(current_state,next_state) config.getSystemInfo(current_state, next_state)
config.displayConfig() config.displayConfig()
# Check if run for first time # Check if run for first time
if config.first_time: if config.first_time:
current_state.add_section('system') current_state.add_section('system')
current_state.set('system','reboot',config.today.isoformat()) current_state.set('system', 'reboot', config.today.isoformat())
current_state.set('system','upgrade',config.today.isoformat()) current_state.set('system', 'upgrade', config.today.isoformat())
save_current_state(current_state,config) save_current_state(current_state, config)
# Purge repositories list and add new ones # Purge repositories list and add new ones
repositories_process(dict(next_state.items('repositories'))) repositories_process(dict(next_state.items('repositories')))
# Check if dist-upgrade is needed # Check if dist-upgrade is needed
...@@ -270,17 +272,17 @@ def update_machine(config): ...@@ -270,17 +272,17 @@ def update_machine(config):
update_slapprepare_scripts() update_slapprepare_scripts()
update_system() update_system()
os.system('reboot') os.system('reboot')
else : else:
logger.info("We will now upgrade your packages") logger.info("We will now upgrade your packages")
update_software() update_software()
autoupdate.do_update() autoupdate.do_update()
else: else:
if config.last_upgrade < config.upgrade : if config.last_upgrade < config.upgrade:
# Purge repositories list and add new ones # Purge repositories list and add new ones
repositories_process(dict(next_state.items('repositories'))) repositories_process(dict(next_state.items('repositories')))
current_state.set('system','upgrade',config.today.isoformat()) current_state.set('system', 'upgrade', config.today.isoformat())
save_current_state(current_state,config) save_current_state(current_state, config)
if suse_version() < config.opensuse_version: if suse_version() < config.opensuse_version:
logger.info("We will now upgrade your system") logger.info("We will now upgrade your system")
update_system() update_system()
...@@ -288,12 +290,12 @@ def update_machine(config): ...@@ -288,12 +290,12 @@ def update_machine(config):
logger.info("We will now upgrade your packages") logger.info("We will now upgrade your packages")
update_software() update_software()
autoupdate.do_update() autoupdate.do_update()
else : else:
logger.info("Your system is up to date") logger.info("Your system is up to date")
if config.last_reboot < config.reboot : if config.last_reboot < config.reboot:
current_state.set('system','reboot',config.today.isoformat()) current_state.set('system', 'reboot', config.today.isoformat())
save_current_state(current_state,config) save_current_state(current_state, config)
os.system('reboot') os.system('reboot')
...@@ -315,39 +317,39 @@ class Config: ...@@ -315,39 +317,39 @@ class Config:
# add ch to logger # add ch to logger
self.logger.addHandler(ch) self.logger.addHandler(ch)
if self.verbose : if self.verbose:
ch.setLevel(logging.DEBUG) ch.setLevel(logging.DEBUG)
def getSystemInfo(self,current_state,next_state): def getSystemInfo(self, current_state, next_state):
""" """
Extract information from config file and server file Extract information from config file and server file
""" """
self.reboot = datetime.datetime.strptime(next_state.get('system','reboot'), self.reboot = datetime.datetime.strptime(next_state.get('system', 'reboot'),
"%Y-%m-%d").date() "%Y-%m-%d").date()
self.upgrade = datetime.datetime.strptime(next_state.get('system','upgrade'), self.upgrade = datetime.datetime.strptime(next_state.get('system', 'upgrade'),
"%Y-%m-%d").date() "%Y-%m-%d").date()
self.opensuse_version = next_state.getfloat('system','opensuse_version') self.opensuse_version = next_state.getfloat('system', 'opensuse_version')
if not current_state.has_section('system'): if not current_state.has_section('system'):
self.first_time = True self.first_time = True
else: else:
self.first_time = False self.first_time = False
self.last_reboot = datetime.datetime.strptime( self.last_reboot = datetime.datetime.strptime(
current_state.get('system','reboot'), current_state.get('system', 'reboot'),
"%Y-%m-%d").date() "%Y-%m-%d").date()
self.last_upgrade = datetime.datetime.strptime( self.last_upgrade = datetime.datetime.strptime(
current_state.get('system','upgrade'), current_state.get('system', 'upgrade'),
"%Y-%m-%d").date() "%Y-%m-%d").date()
def displayConfig(self): def displayConfig(self):
""" """
Display Config Display Config
""" """
self.logger.debug( "reboot %s" % self.reboot) self.logger.debug("reboot %s" % self.reboot)
self.logger.debug( "upgrade %s" % self.upgrade) self.logger.debug("upgrade %s" % self.upgrade)
self.logger.debug( "suse version %s" % self.opensuse_version) self.logger.debug("suse version %s" % self.opensuse_version)
if not self.first_time : if not self.first_time:
self.logger.debug( "Last reboot : %s" % self.last_reboot) self.logger.debug("Last reboot : %s" % self.last_reboot)
self.logger.debug( "Last upgrade : %s" % self.last_upgrade) self.logger.debug("Last upgrade : %s" % self.last_upgrade)
def main(): def main():
......
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