6 N = {'id': 0, 'status': 1, 'name': 2, 'cluster': 3, 'ip': 4, 'mac': 5,
7 'roles': 6, 'pending_roles': 7, 'online': 8}
8 E = {'id': 0, 'status': 1, 'name': 2, 'mode': 3, 'release_id': 4,
9 'changes': 5, 'pending_release_id': 6}
10 R = {'id': 0, 'name': 1, 'state': 2, 'operating_system': 3, 'version': 4}
11 RO = {'name': 0, 'conflicts': 1}
13 LOG = logging.getLogger(__name__)
14 LOG.setLevel(logging.DEBUG)
15 formatter = logging.Formatter('%(message)s')
16 out_handler = logging.StreamHandler(sys.stdout)
17 out_handler.setFormatter(formatter)
18 LOG.addHandler(out_handler)
19 out_handler = logging.FileHandler('autodeploy.log', mode='w')
20 out_handler.setFormatter(formatter)
21 LOG.addHandler(out_handler)
23 def exec_cmd(cmd, check=True):
24 process = subprocess.Popen(cmd,
25 stdout=subprocess.PIPE,
26 stderr=subprocess.STDOUT,
28 response = process.communicate()[0].strip()
29 return_code = process.returncode
35 return response, return_code
38 process = subprocess.Popen(cmd,
39 stdout=subprocess.PIPE,
40 stderr=subprocess.STDOUT,
46 lines = printout.splitlines()
48 parsed = [e.strip() for e in l.split('|')]
49 parsed_list.append(parsed)
55 for l in lines.strip().splitlines():
57 cluttered = [e.strip() for e in l.split(' ')]
61 parsed_list.append(parsed)
62 return parsed if len(parsed_list) == 1 else parsed_list
65 LOG.error('%s\n' % message)
68 def check_file_exists(file_path):
69 if not os.path.isfile(file_path):
70 err('ERROR: File %s not found\n' % file_path)
72 def check_dir_exists(dir_path):
73 if not os.path.isdir(dir_path):
74 err('ERROR: Directory %s not found\n' % dir_path)
77 r = exec_cmd('whoami')
79 err('You need be root to run this application')
82 LOG.debug('%s\n' % message)