-
Notifications
You must be signed in to change notification settings - Fork 12
/
example.py
38 lines (37 loc) · 1.12 KB
/
example.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
import sys
import getopt
import racadm
import logging
def main(argv):
user = 'root'
password = 'calvin'
log_level = logging.INFO
opts, args = getopt.getopt(argv,'vu:p:')
results = dict()
for opt, arg in opts:
if opt == '-u':
user = arg
elif opt == '-p':
password = arg
elif opt == '-v':
log_level = logging.DEBUG
logging.basicConfig(level=log_level)
for node in range(1,2):
node_fqdn = 'drac.prg{0:02d}.l.root-servers.org'.format(node)
print node_fqdn
try:
rac = racadm.Racadm(node_fqdn, user, password)
ifconfig = rac.basic_command('ifconfig')
for line in ifconfig.split('\n'):
tokens = line.split()
if tokens and tokens[0] == 'eth0':
logging.debug('{}: {}'.format(node_fqdn, tokens[4]))
results[node_fqdn] = tokens[4]
break
except:
print '{}: error'.format(node_fqdn)
finally:
rac.logout
print results
if __name__ == "__main__":
main(sys.argv[1:])