Resolve flake8 errors in cobler_system script
Change-Id: Icd1bf34a234410ea0b6365b127b771a3e0ce29ae
This commit is contained in:
parent
8384b8ca4d
commit
32b0e76e21
|
@ -1,26 +1,23 @@
|
|||
#!/usr/bin/env python
|
||||
# flake8: noqa
|
||||
|
||||
import sys
|
||||
import re
|
||||
import shlex
|
||||
import yaml
|
||||
import argparse
|
||||
import logging
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
import StringIO
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
console = logging.StreamHandler()
|
||||
# formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
|
||||
formatter = logging.Formatter('%(message)s')
|
||||
console.setFormatter(formatter)
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(console)
|
||||
|
||||
def system_command(command, expected_resultcodes=(0,)):
|
||||
|
||||
commands = [ i.strip() for i in re.split(ur'\|', command)]
|
||||
def system_command(command, expected_resultcodes=(0,)):
|
||||
commands = [i.strip() for i in re.split(ur'\|', command)]
|
||||
|
||||
process = []
|
||||
process.append(subprocess.Popen(shlex.split(commands[0]),
|
||||
|
@ -39,15 +36,15 @@ def system_command(command, expected_resultcodes=(0,)):
|
|||
|
||||
serr = []
|
||||
for p in process:
|
||||
serr += [ err.strip() for err in p.stderr.readlines() ]
|
||||
serr += [err.strip() for err in p.stderr.readlines()]
|
||||
|
||||
returncode = process[-1].returncode
|
||||
|
||||
if expected_resultcodes and not returncode in expected_resultcodes:
|
||||
logger.error("""Command: '%s'\nreturned not expected \
|
||||
value: %d\nstdout:\n%s\nstderr:\n%s""" % \
|
||||
(command, returncode,
|
||||
process[-1].stdout.read().rstrip('\n'),
|
||||
if expected_resultcodes and returncode not in expected_resultcodes:
|
||||
logger.error(
|
||||
"Command: '%s'\nreturned not expected value: %d\n"
|
||||
"stdout:\n%s\nstderr:\n%s",
|
||||
(command, returncode, process[-1].stdout.read().rstrip('\n'),
|
||||
'\n'.join(serr).rstrip('\n')))
|
||||
sys.exit(1)
|
||||
else:
|
||||
|
@ -64,12 +61,13 @@ def is_system_exist(system_name):
|
|||
code = system_command(command, expected_resultcodes=(0, 1))
|
||||
return code == 0
|
||||
|
||||
|
||||
def update_system(system_name, system_dict):
|
||||
addedit = 'add'
|
||||
if is_system_exist(system_name):
|
||||
addedit = 'edit'
|
||||
|
||||
command = ["""/usr/bin/cobbler system %s --name='%s' --hostname='%s'""" % \
|
||||
command = ["/usr/bin/cobbler system %s --name='%s' --hostname='%s'" %
|
||||
(addedit, system_name, system_dict['hostname'])]
|
||||
|
||||
ksmeta = system_dict.get('ksmeta', '')
|
||||
|
@ -79,7 +77,7 @@ def update_system(system_name, system_dict):
|
|||
|
||||
command.append("""--%s='%s'""" % (opt, system_dict[opt]))
|
||||
|
||||
for int_name in system_dict.get('interfaces_extra',{}):
|
||||
for int_name in system_dict.get('interfaces_extra', {}):
|
||||
int_extra_dict = system_dict['interfaces_extra'][int_name]
|
||||
for int_extra in int_extra_dict:
|
||||
ksmeta = """%s interface_extra_%s_%s=%s""" % \
|
||||
|
@ -116,8 +114,8 @@ def update_system_interfaces(system_name, interfaces_dict):
|
|||
|
||||
return len(code) == 0
|
||||
|
||||
def main():
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-f", "--file", dest="file",
|
||||
metavar="YAML_FILE", type=str,
|
||||
|
|
Loading…
Reference in New Issue