clearer names for actions, and infer actions better
[monitor.git] / tests / nodenetwork.py
1 #!/usr/bin/python
2
3 import sys
4 import plc
5 api = plc.getAuthAPI()
6 import util.file
7
8 if len(sys.argv[1:]) > 0:
9         for host in sys.argv[1:]:
10                 n = api.GetNodes(host)[0]
11                 nn = api.GetInterfaces(n['interface_ids'])
12                 for nodenet in nn:
13                         nnet2 = api.GetInterfaces({'ip': nodenet['ip']})
14                         print "len of nn entries with ip: %s == %s " % ( nodenet['ip'], len(nnet2) )
15                         for nn2 in nnet2:
16                                 n2 = api.GetNodes(nn2['node_id'])
17                                 print "\t%d node is attached to nodenetwork %s" % ( len(n2), nn2['interface_id'] )
18                                 if len(n2) != 0 :
19                                         n2 = n2[0]
20                                         print
21                                         #print "host %s : %s" % (n2['hostname'], n2['node_id'])
22                                 else:
23                                         pass
24                                         #print nn2['interface_id']
25                                         #api.DeleteNodeNetwork(nn2['interface_id'])
26 else:
27         nnids = util.file.getListFromFile('nnids.txt')
28         nnids = [ int(i) for i in nnids]
29         for id in nnids:
30                 nnet2 = api.GetInterfaces(id)
31                 for nn2 in nnet2:
32                         n2 = api.GetNodes(nn2['node_id'])
33                         if len(n2) == 0 :
34                                 print "\t%d node is attached to nodenetwork %s %s" % ( len(n2), nn2['interface_id'] , nn2['ip']),
35
36                                 netlist = api.GetInterfaces({'ip' : nn2['ip']})
37                                 if len(netlist) != 1:
38                                         node_len = len([ n['node_id'] for n in netlist])
39                                         print "\t but, ip %s is used by %s nodenetwork entries" % (nn2['ip'], node_len)
40                                 else:
41                                         print
42                                 #print nn2
43                         else:
44                                 print
45                                 pass