Please note that the CVS and issue trackers have moved to GitHub. These Trac pages are no longer kept up-to-date.

root/seattle/trunk/deploymentscripts/deploy_vessel_info.py@5637

Revision 2632, 7.0 KB (checked in by konp, 10 years ago)

Added v2 pubkey, and hashes.dict for 0.1l. Minor other changes.

Line 
1
2
3import repyhelper
4import os
5import deploy_main
6import deploy_helper
7
8print 'Import .repy files into namespace...',
9# make sure we have access to the rsa lib in the local namespace
10repyhelper.translate_and_import('rsa.repy')
11repyhelper.translate_and_import('advertise.repy')
12print 'Done'
13
14
15
16
17
18print 'Loading keys from files...',
19canonicalpublickey = rsa_file_to_publickey("canonical.publickey")
20
21v2publickey = rsa_file_to_publickey("v2.publickey")
22
23# The key used for new donations...
24acceptdonationpublickey = rsa_file_to_publickey("acceptdonation.publickey")
25
26# Used for our first attempt at doing something sensible...
27movingtoonepercentpublickey = rsa_file_to_publickey("movingtoonepercent.publickey")
28onepercentpublickey = rsa_file_to_publickey("onepercent.publickey")
29
30# Used as the second onepercentpublickey -- used to correct ivan's
31# mistake of deleting vesselport entries from the geni database
32movingtoonepercent2publickey = rsa_file_to_publickey("movingtoonepercent2.publickey")
33onepercent2publickey = rsa_file_to_publickey("onepercent2.publickey")
34
35
36# Getting us out of the mess we started with
37#genilookuppublickey = rsa_file_to_publickey("genilookup.publickey")
38movingtogenilookuppublickey = rsa_file_to_publickey("movingtogenilookup.publickey")
39
40# Used as the many events onepercent publickey -- This has 50 events per vessel
41movingtoonepercentmanyeventspublickey = rsa_file_to_publickey("movingtoonepercentmanyevents.publickey")
42onepercentmanyeventspublickey = rsa_file_to_publickey("onepercentmanyevents.publickey")
43
44knownstates = [canonicalpublickey, acceptdonationpublickey, 
45           movingtoonepercentpublickey, onepercentpublickey,
46           movingtoonepercent2publickey, onepercent2publickey,
47           movingtoonepercentmanyeventspublickey, onepercentmanyeventspublickey,
48           movingtogenilookuppublickey, v2publickey]
49
50# string representations of the above states
51knownstates_string_representation = ['canonicalpublickey', 'acceptdonationpublickey', 
52           'movingtoonepercentpublickey', 'onepercentpublickey',
53           'movingtoonepercent2publickey', 'onepercent2publickey',
54           'movingtoonepercentmanyeventspublickey', 'onepercentmanyeventspublickey',
55           'movingtogenilookuppublickey', 'v2']
56
57print 'Done'
58
59
60def get_nodes_for_key(key):
61  # returns nodes corresponding to that key
62  keys_repy = advertise_lookup(key, 10000000)
63  return (keys_repy)
64 
65
66
67def main():
68
69  # delete the old advertised_nodes_list.list file
70  try:
71    os.remove('advertised_nodes_list.list') 
72  except OSError, ose:
73    pass
74  except Exception, e:
75    print e
76    return
77 
78  advertised_nodes_list = []
79 
80  for i in range(len(knownstates)):
81    current_key = knownstates[i]
82    print 'Nodes corresponding to '+knownstates_string_representation[i]+'...',
83   
84    nodes_in_state = get_nodes_for_key(current_key)
85   
86    total_counter = 0
87    try:
88      # write all of these nodes to file
89      advertised_nodes_handle = open('advertised_nodes_list.list', 'a')
90     
91      # write the type of nodes these are as a comment
92      advertised_nodes_handle.write('\n\n# '+knownstates_string_representation[i])
93      print 'writing to file...',
94     
95      counter = 0
96      total_counter += counter
97      for each_node in nodes_in_state:
98        # strip the :port from each node, make sure it's not an empty string
99        if each_node:
100          nodeip, sep, port = each_node.rpartition(':')
101          advertised_nodes_list.append(nodeip)
102          advertised_nodes_handle.write('\n'+str(nodeip))
103          counter += 1
104      advertised_nodes_handle.write('\n\tA total of '+str(counter))
105      advertised_nodes_handle.close()
106      print 'Finished'
107     
108    except Exception, e:
109      print 'An error occured while writing to file ('+str(e)+')'
110 
111  # this makes it uniq
112  advertised_nodes_list = list(set(advertised_nodes_list))
113  if not advertised_nodes_list:
114    print "You've hit a timeout with the server, it thinks you're spamming it. Please wait"
115    return
116  print advertised_nodes_list
117 
118 
119 
120  # now we read in the other iplist file, ignore all !user: lines and comments
121  # just use the method from deploy_main to do that, but it'll return an array
122  # of tuples (user, hostname/ip) so we'll just grab the hostname/ip field
123  remote_host_tuples = deploy_main.get_remote_hosts_from_file('iplist2.list', True)
124 
125  # this'll keep track of the actual hostnames/ips
126  pl_nodes = []
127
128  for each_host in remote_host_tuples:
129    # each_host[0]: username
130    # each_host[1]: hostname/ip
131    pl_nodes.append(each_host[1])
132   
133  # keeps track of ip->hostname and hostname->ip mappings
134  dns_dict = {}
135 
136  # this'll keep track of the already checked nodes
137  dns_dict['flagged'] = []
138 
139  # keeps track of the rerversed dns entries
140  advertise_reversedns = []
141 
142  # loopbacks, network, eg: 192.*
143  networkiplist = []
144 
145  for each_host in advertised_nodes_list:
146    try:
147      reversedlookup = deploy_helper.dnslookup(each_host)
148    except Exception, e:
149      print each_host + ":\t"+e
150    else:
151      print str(each_host)+' resolves to '+reversedlookup.strip('\r\n. ')
152     
153      if each_host == reversedlookup:
154        networkiplist.append(each_host)
155      else:
156        dns_dict[each_host] = reversedlookup.strip('\r\n. ')
157        dns_dict[reversedlookup.strip('\r\n. ')] = each_host
158        advertise_reversedns.append(reversedlookup.strip('\r\n. '))
159 
160  try:
161    # write the reverse dns's looked up
162    reversed_filehandle = open('advertised_nodes_rdns.list', 'w+')
163    for each_host in advertise_reversedns:
164      reversed_filehandle.write('\n'+each_host)
165    reversed_filehandle.close()
166  except Exception, e:
167    print e
168   
169  # combine the two lists
170  all_advertised_nodes = advertise_reversedns + advertised_nodes_list
171 
172  uniq_counter = 0
173  uniq_list = []
174 
175  print '\n\n'
176 
177  for each_node in all_advertised_nodes:
178    # make sure this node isn't flagged as already checked
179    try:
180      if each_node not in dns_dict['flagged']:
181        if each_node not in pl_nodes:
182          # make sure the reversedns counterpart isn't in the list either
183          if dns_dict[each_node] not in pl_nodes:
184            uniq_counter += 1
185            print each_node+' is not in pl_list'
186            uniq_list.append(each_node)
187            # flag it as already checked
188        # flag the node's counterpart as checked
189        dns_dict['flagged'].append(dns_dict[each_node])
190    except KeyError, ke:
191      # key error means it's an ip in the networkiplist
192      uniq_counter += 1
193      print each_node+' is not in pl_list (ke)'
194      uniq_list.append(each_node)
195    except Exception, e:
196      print e
197 
198  try:
199    # write the reverse dns's looked up
200    uniq_filehandle = open('advertised_nodes_uniq.list', 'w+')
201    for each_host in uniq_list:
202      uniq_filehandle.write('\n'+each_host)
203    uniq_filehandle.close()
204  except Exception, e:
205    print e
206 
207  print '\n\n'
208  print 'The following files were created: advertised_nodes_uniq.list, advertised_nodes_list.list, and advertised_nodes_rdns.list'
209  print 'The number of non-PL/University nodes is '+str(uniq_counter) 
210 
211 
212   
213if __name__ == '__main__':
214  main()
Note: See TracBrowser for help on using the browser.