7 N = {'id': 0, 'status': 1, 'name': 2, 'cluster': 3, 'ip': 4, 'mac': 5,
8 'roles': 6, 'pending_roles': 7, 'online': 8}
9 E = {'id': 0, 'status': 1, 'name': 2, 'mode': 3, 'release_id': 4,
10 'changes': 5, 'pending_release_id': 6}
11 R = {'id': 0, 'name': 1, 'state': 2, 'operating_system': 3, 'version': 4}
12 RO = {'name': 0, 'conflicts': 1}
14 LOG = logging.getLogger(__name__)
15 LOG.setLevel(logging.DEBUG)
16 formatter = logging.Formatter('%(message)s')
17 out_handler = logging.StreamHandler(sys.stdout)
18 out_handler.setFormatter(formatter)
19 LOG.addHandler(out_handler)
20 out_handler = logging.FileHandler('autodeploy.log', mode='w')
21 out_handler.setFormatter(formatter)
22 LOG.addHandler(out_handler)
24 def exec_cmd(cmd, check=True):
25 process = subprocess.Popen(cmd,
26 stdout=subprocess.PIPE,
27 stderr=subprocess.STDOUT,
29 response = process.communicate()[0].strip()
30 return_code = process.returncode
36 return response, return_code
39 process = subprocess.Popen(cmd,
40 stdout=subprocess.PIPE,
41 stderr=subprocess.STDOUT,
47 lines = printout.splitlines()
49 parsed = [e.strip() for e in l.split('|')]
50 parsed_list.append(parsed)
56 for l in lines.strip().splitlines():
58 cluttered = [e.strip() for e in l.split(' ')]
62 parsed_list.append(parsed)
63 return parsed if len(parsed_list) == 1 else parsed_list
66 LOG.error('%s\n' % message)
69 def check_file_exists(file_path):
70 if not os.path.isfile(file_path):
71 err('ERROR: File %s not found\n' % file_path)
73 def check_dir_exists(dir_path):
74 if not os.path.isdir(dir_path):
75 err('ERROR: Directory %s not found\n' % dir_path)
77 def create_dir_if_not_exists(dir_path):
78 if not os.path.isdir(dir_path):
79 log('Creating directory %s' % dir_path)
82 def commafy(comma_separated_list):
83 l = [c.strip() for c in comma_separated_list.split(',')]
86 def delete_file(file):
87 if os.path.exists(file):
91 r = exec_cmd('whoami')
93 err('You need be root to run this application')
96 LOG.debug('%s\n' % message)
98 class ArgParser(argparse.ArgumentParser):
99 def error(self, message):
100 sys.stderr.write('ERROR: %s\n' % message)