forked from rthallisey/clapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instackenv-validator.py
executable file
·100 lines (78 loc) · 2.82 KB
/
instackenv-validator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
# curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
# python get-pip.py
import argparse
import logging
import sys
import os
import json
logging.basicConfig()
LOG = logging.getLogger(__name__)
LOG.setLevel(logging.DEBUG) # JPEELER: change to INFO later
def argParser():
parser = argparse.ArgumentParser(description='Clapper')
parser.add_argument('-f', '--file',
help='path to instack json environment file',
type=str,
default='instackenv.json')
return vars(parser.parse_args())
def allUnique(x):
seen = list()
return not any(i in seen or seen.append(i) for i in x)
def main():
args = argParser()
error_count = 0
with open(args['file'], 'r') as net_file:
env_data = json.load(net_file)
maclist = []
baremetal_ips =[]
for node in env_data['nodes']:
LOG.info("Checking node %s" % node['pm_addr'])
try:
if len(node['pm_password']) == 0:
LOG.error('ERROR: Password 0 length.')
except Exception, e:
LOG.error('ERROR: Password does not exist: %s', e)
error_count += 1
try:
if len(node['pm_user']) == 0:
LOG.error('ERROR: User 0 length.')
except Exception, e:
LOG.error('ERROR: User does not exist: %s', e)
error_count += 1
try:
if len(node['mac']) == 0:
LOG.error('ERROR: MAC address 0 length.')
maclist.append(node['mac'])
except Exception, e:
LOG.error('ERROR: MAC address does not exist: %s', e)
error_count += 1
if node['pm_type'] == "pxe_ssh":
LOG.debug("Identified virtual node")
if node['pm_type'] == "pxe_ipmitool":
LOG.debug("Identified baremetal node")
cmd = 'ipmitool -R 1 -I lanplus -H %s -U %s -P %s chassis status' % (node['pm_addr'],
node['pm_user'], node['pm_password'])
LOG.debug("Executing: %s", cmd)
status = os.system(cmd)
if status != 0:
LOG.error('ERROR: ipmitool failed')
error_count += 1
baremetal_ips.append(node['pm_addr'])
if not allUnique(baremetal_ips):
LOG.error('ERROR: Baremetals IPs are not all unique.')
error_count += 1
else:
LOG.debug('Baremetal IPs are all unique.')
if not allUnique(maclist):
LOG.error('ERROR: MAC addresses are not all unique.')
error_count += 1
else:
LOG.debug('MAC addresses are all unique.')
print "\n--------------------"
if error_count == 0:
print('SUCCESS: instackenv validator found 0 errors')
else:
print('FAILURE: instackenv validator found %d errors' % error_count)
if __name__ == "__main__":
sys.exit(main())