rev |
line source |
igor@0
|
1 #!/usr/bin/python
|
igor@0
|
2
|
igor@0
|
3
|
igor@2
|
4 import sys,os,time
|
igor@35
|
5
|
igor@35
|
6 xentaur_path=os.environ['HOME']+"/xentaur"
|
igor@35
|
7
|
igor@0
|
8 sys.path.append('/etc/xen')
|
igor@35
|
9 sys.path.append(xentaur_path)
|
igor@11
|
10
|
igor@40
|
11 network='snrs_ipsec_preshared_1'
|
igor@40
|
12 domain='qua1'
|
igor@35
|
13 from xendomain import *
|
igor@35
|
14
|
igor@29
|
15 bridges_turned_down=[]
|
igor@29
|
16
|
igor@0
|
17 from IPython.Shell import IPShellEmbed
|
igor@0
|
18
|
igor@2
|
19
|
igor@2
|
20 screenrc=os.environ['HOME']+"/.screenrc_xentaur"
|
igor@2
|
21
|
igor@10
|
22 def run(program, *args):
|
igor@10
|
23 pid = os.fork()
|
igor@10
|
24 if not pid:
|
igor@10
|
25 os.execvp(program, (program,) + args)
|
igor@10
|
26 return os.wait()[0]
|
igor@10
|
27
|
igor@10
|
28 def run_command(line):
|
igor@10
|
29 #cmds=line.split()
|
igor@10
|
30 #run(cmds[0],*cmds[1:])
|
igor@10
|
31 run("/bin/sh", "-c", line)
|
igor@10
|
32
|
igor@23
|
33 def run_command_return_stdout(line):
|
igor@23
|
34 p = os.popen(line)
|
igor@23
|
35 output = p.read()
|
igor@23
|
36 p.close()
|
igor@23
|
37 return output
|
igor@23
|
38
|
igor@0
|
39 def create_bridges_script():
|
igor@38
|
40 unbound_bridges=set(bridges)-set(real_bridges)
|
igor@40
|
41 create_unbound_bridges="\n".join(map(lambda x: "sudo /usr/sbin/brctl show | awk '{print $1}' | grep -qx "+x+" || sudo /usr/sbin/brctl addbr "+x, unbound_bridges))
|
igor@4
|
42 create_unbound_bridges+="\n"+"\n".join(map(lambda x: "sudo /bin/ip link set "+x+" up", unbound_bridges))
|
igor@0
|
43
|
igor@0
|
44 print """#!/bin/sh
|
igor@0
|
45 # create unbound bridges
|
igor@0
|
46 %(create_unbound_bridges)s
|
igor@0
|
47 """ % {'create_unbound_bridges' : create_unbound_bridges}
|
igor@0
|
48
|
igor@0
|
49
|
igor@0
|
50 def create_domains_script():
|
igor@35
|
51 for domain in domains:
|
igor@38
|
52 if not domain in real_nodes:
|
igor@38
|
53 print "sudo /usr/sbin/xm create "+xentaur_path+"/xendomain.py "+" domain="+domain+" network="+network+" && sleep 1 && sudo /usr/sbin/xm sched-credit -d $(sudo /usr/sbin/xm list | grep "+domain+" | awk '{print $2}') -c 10 && sleep 1"
|
igor@0
|
54
|
igor@0
|
55 def destroy_domains_script():
|
igor@35
|
56 for domain in domains:
|
igor@38
|
57 if not domain in real_nodes:
|
igor@38
|
58 print "sudo /usr/sbin/xm shutdown "+domain
|
igor@0
|
59
|
igor@0
|
60 def create_screens_script():
|
igor@7
|
61 N=1
|
igor@0
|
62 screens=[]
|
igor@0
|
63 for domain in domains:
|
igor@11
|
64 screens.append("screen -t "+domain+" "+str(N)+" sh -c 'while true; do sudo xm console "+domain+" ; echo Retrying in 5 seconds...; sleep 5; done'")
|
igor@0
|
65 N+=1
|
igor@0
|
66 screenlist="\n".join(screens)
|
igor@0
|
67
|
igor@11
|
68 #
|
igor@11
|
69 # Previous terminal acccess commands:
|
igor@11
|
70 # ip="192.168.80."+str(200+N)
|
igor@11
|
71 # screens.append("screen -t "+domain+" "+str(N)+" sh -c 'while true; do ssh root@"+ip+" ; done'")
|
igor@11
|
72 #
|
igor@11
|
73
|
igor@4
|
74 #hardstatus string "\%{gk}\%c \%{yk}\%M\%d \%{wk}\%?\%-Lw\%?\%{bw}\%n*\%f\%t\%?(\%u)\%?\%{wk}\%?\%+Lw\%?"
|
igor@10
|
75
|
igor@11
|
76 f=open(screenrc, "w");
|
igor@10
|
77 f.write("""
|
igor@2
|
78 hardstatus on
|
igor@2
|
79 hardstatus alwayslastline
|
igor@2
|
80
|
igor@0
|
81 screen -t console 0 bash
|
igor@10
|
82 %s
|
igor@10
|
83 """ % (screenlist))
|
igor@10
|
84 f.close()
|
igor@0
|
85
|
igor@0
|
86 def graph_node(node):
|
igor@0
|
87 i=0
|
igor@0
|
88 domain_type={}
|
igor@0
|
89 for domain in domains:
|
igor@0
|
90 domain_type[domain]=domain_types[i]
|
igor@0
|
91 i+=1
|
nata@31
|
92 return node+" [label=\" "+node+"\",shapefile=\"shapes/all/"+domain_type[node]+".png\",fontcolor=black,fontsize=16]"
|
igor@0
|
93
|
igor@29
|
94 def graph_bridge(bridge):
|
igor@29
|
95 if bridge in hidden_bridges:
|
igor@29
|
96 return ""
|
igor@38
|
97 if bridge in real_bridges:
|
igor@38
|
98 return "%s [shape=none,shapefile=\"shapes/all/real_switch.png\"]" % (bridge)
|
igor@38
|
99 elif bridge in bridges_turned_down:
|
igor@29
|
100 return "%s [shape=none,shapefile=\"shapes/all/switch_turned_down.png\"]" % (bridge)
|
igor@29
|
101 else:
|
igor@29
|
102 return "%s [shape=none,shapefile=\"shapes/all/switch.png\"]" % (bridge)
|
igor@29
|
103
|
igor@29
|
104
|
igor@0
|
105 def graph():
|
igor@0
|
106 nodelist=""
|
igor@0
|
107 bridgelist=""
|
igor@0
|
108 linklist=""
|
igor@0
|
109 physicallist=""
|
igor@0
|
110 networklist=""
|
igor@0
|
111
|
igor@0
|
112 nodelist=";\n ".join(map(graph_node,nodes))
|
igor@0
|
113 if nodelist: nodelist += ";"
|
igor@0
|
114
|
igor@29
|
115 bridgelist=";\n ".join(map(graph_bridge,bridges))
|
igor@0
|
116 if bridgelist: bridgelist += ";"
|
igor@0
|
117
|
igor@0
|
118 links=[]
|
igor@0
|
119 for host, bridges_raw in vbridges_table.iteritems():
|
igor@0
|
120 i=0
|
igor@0
|
121 for this_bridge in bridges_raw:
|
igor@27
|
122 if this_bridge in hidden_bridges or not this_bridge:
|
igor@0
|
123 continue
|
igor@28
|
124 if not [ host, bridges_raw.index(this_bridge), this_bridge ] in temporary_links:
|
igor@28
|
125 links.append(host+" -- "+this_bridge+" [taillabel=\"fa"+str(bridges_raw.index(this_bridge))+"/0\"]")
|
igor@27
|
126 i+=1
|
igor@0
|
127
|
igor@0
|
128 for link in temporary_links:
|
igor@28
|
129 links.append(link[0]+" -- "+link[2]+" [taillabel=\"fa"+str(link[1])+"/0\",color=blue,len=10,w=5,weight=5]")
|
igor@0
|
130
|
igor@27
|
131 for link in broken_links:
|
igor@28
|
132 links.append(link[0]+" -- "+link[2]+" [taillabel=\"fa"+str(link[1])+"/0\",style=dashed]")
|
igor@27
|
133
|
igor@39
|
134
|
igor@39
|
135 # bridge-bridge links
|
igor@39
|
136 for host, bridges_raw in bridge_bridge_table.iteritems():
|
igor@39
|
137 i=0
|
igor@39
|
138 for this_bridge in bridges_raw:
|
igor@39
|
139 if this_bridge in hidden_bridges or not this_bridge:
|
igor@39
|
140 continue
|
igor@39
|
141 if not [ host, bridges_raw.index(this_bridge), this_bridge ] in temporary_links:
|
igor@39
|
142 links.append(host+" -- "+this_bridge)
|
igor@39
|
143 i+=1
|
igor@39
|
144
|
igor@39
|
145
|
igor@39
|
146
|
igor@0
|
147 linklist=";\n ".join(links)
|
igor@0
|
148
|
igor@0
|
149 graph_dot = {
|
igor@0
|
150 'nodelist' : nodelist,
|
igor@0
|
151 'bridgelist' : bridgelist,
|
igor@0
|
152 'linklist' : linklist,
|
igor@0
|
153 'physicallist' : physicallist,
|
igor@0
|
154 'networklist' : networklist,
|
igor@0
|
155 }
|
igor@0
|
156
|
igor@10
|
157 f = open("xenomips.dot", "w");
|
igor@10
|
158 f.write ("""
|
igor@0
|
159 graph G {
|
igor@0
|
160 edge [len=1.25];
|
igor@0
|
161 splines=true;
|
igor@0
|
162 // nodes
|
igor@0
|
163
|
igor@0
|
164 node [shape=plaintext,color=white,shapefile="shapes/cisco.bmp/router.png"];
|
igor@0
|
165 %(nodelist)s
|
igor@0
|
166
|
igor@0
|
167 // bridges
|
igor@0
|
168
|
igor@6
|
169 node [shape=none,shapefile="shapes/all/switch.png"];
|
igor@0
|
170 %(bridgelist)s
|
igor@0
|
171
|
igor@0
|
172 // physical
|
igor@0
|
173
|
igor@0
|
174 node [shape=rectangle,color=blue];
|
igor@0
|
175 %(physicallist)s
|
igor@0
|
176
|
igor@0
|
177 // networks (not bridges, not physical)
|
igor@0
|
178 node [shape=rectangle,color=green];
|
igor@0
|
179 %(networklist)s
|
igor@0
|
180
|
igor@0
|
181 // links (between nodes and bridges)
|
igor@0
|
182 %(linklist)s
|
igor@0
|
183
|
igor@0
|
184 };
|
igor@10
|
185 """ % graph_dot)
|
igor@10
|
186 f.close()
|
igor@10
|
187 run_command("neato -Tpng -o xenomips.png xenomips.dot ")
|
igor@40
|
188 run_command("neato -Tsvg -o xenomips.svg xenomips.dot ")
|
igor@0
|
189
|
igor@27
|
190 def autoredraw():
|
igor@27
|
191 graph()
|
igor@27
|
192
|
igor@0
|
193 def start_all():
|
igor@0
|
194 create_bridges_script()
|
igor@0
|
195 create_screens_script()
|
igor@0
|
196 create_domains_script()
|
igor@0
|
197 graph()
|
igor@0
|
198 print """
|
igor@0
|
199 cat <<NOTE_FOR_USER
|
igor@0
|
200 # To view virtual network map, run:
|
igor@0
|
201 gqview xenomips.png
|
igor@0
|
202 # To attach to VM consoles, run:
|
igor@0
|
203 screen -c screenrc
|
igor@0
|
204 NOTE_FOR_USER
|
igor@0
|
205 """
|
igor@0
|
206
|
igor@0
|
207 def shell():
|
nata@31
|
208 autoredraw()
|
igor@0
|
209 ipshell = IPShellEmbed()
|
igor@0
|
210 ipshell()
|
igor@0
|
211
|
igor@0
|
212 def stop_all():
|
igor@4
|
213 destroy_domains_script()
|
igor@0
|
214
|
igor@0
|
215 def show_usage():
|
igor@0
|
216 print """Usage:
|
igor@0
|
217 xentaur {start|stop|start-bridges|start-domains|stop-domains|screen|graph}
|
igor@0
|
218 """
|
igor@0
|
219
|
igor@33
|
220 def save():
|
igor@33
|
221 print "network =", xen_config_name
|
igor@33
|
222 print "domains =", domains
|
igor@33
|
223 print "domain_types =", domain_types
|
igor@33
|
224 print "bridges =", bridges
|
igor@33
|
225 print "vbridges_table =", vbridges_table
|
igor@33
|
226 print "hidden_bridges =", hidden_bridges
|
igor@33
|
227 print "broken_links =", broken_links
|
igor@33
|
228 print "temporary_links =", temporary_links
|
igor@33
|
229 print "bridges_turned_down =", bridges_turned_down
|
igor@33
|
230
|
igor@33
|
231 #-----------------------------------------------------------------------
|
igor@33
|
232 # CLASSES
|
igor@33
|
233
|
igor@33
|
234 class Bridge:
|
igor@33
|
235 def __init__ (self,name):
|
igor@33
|
236 self.name=name
|
igor@33
|
237 def up(self):
|
igor@33
|
238 bridge_up(self.name)
|
igor@33
|
239 def down(self):
|
igor@33
|
240 bridge_down(self.name)
|
igor@33
|
241 def show(self):
|
igor@33
|
242 show_bridge(self.name)
|
igor@33
|
243 def dump_start(self,filter=""):
|
igor@33
|
244 dump_start(self.name,filter)
|
igor@33
|
245
|
igor@33
|
246
|
igor@38
|
247 class Domain:
|
igor@38
|
248 def __init__ (self,name):
|
igor@38
|
249 self.name=name
|
igor@38
|
250 def start(self):
|
igor@38
|
251 return ""
|
igor@38
|
252 def stop(self):
|
igor@38
|
253 return ""
|
igor@38
|
254 def start_commandline(self):
|
igor@38
|
255 return ""
|
igor@38
|
256 def graphviz(self):
|
igor@38
|
257 return ""
|
igor@38
|
258 def get_domain_id(self):
|
igor@38
|
259 return get_domain_id(self.name)
|
igor@38
|
260
|
igor@23
|
261 #-----------------------------------------------------------------------
|
igor@23
|
262 # DOMAINS
|
igor@23
|
263
|
igor@23
|
264 def get_domain_id(domain):
|
igor@23
|
265 return run_command_return_stdout("sudo xm list | awk '{if ($1 == \"'%s'\") print $2}'" % domain).rstrip("\n")
|
igor@23
|
266
|
igor@22
|
267
|
igor@22
|
268 #-----------------------------------------------------------------------
|
igor@22
|
269 # BRIDGES and IFACES
|
igor@22
|
270
|
igor@22
|
271 def bridge_down(bridge):
|
igor@22
|
272 """
|
igor@22
|
273 Turn the bridge <bridge> down
|
igor@22
|
274 """
|
igor@38
|
275 if bridge in real_bridges:
|
igor@38
|
276 print "Bridge %s is a real bridge" % (bridge)
|
igor@38
|
277 return -1
|
igor@29
|
278 if bridge in bridges_turned_down:
|
igor@29
|
279 print "Bridge %s is turned down already" % (bridge)
|
igor@29
|
280 else:
|
igor@29
|
281 bridges_turned_down.append(bridge)
|
igor@29
|
282 run_command("sudo ip link set %s down" % bridge)
|
igor@29
|
283 autoredraw()
|
igor@22
|
284
|
igor@22
|
285 def bridge_up(bridge):
|
igor@22
|
286 """
|
igor@22
|
287 Turn the bridge <bridge> up
|
igor@22
|
288 """
|
igor@38
|
289 if bridge in real_bridges:
|
igor@38
|
290 print "Bridge %s is a real bridge" % (bridge)
|
igor@38
|
291 return -1
|
igor@29
|
292 if not (bridge in bridges_turned_down):
|
igor@29
|
293 print "Bridge %s is turned up already" % (bridge)
|
igor@29
|
294 else:
|
igor@29
|
295 bridges_turned_down.remove(bridge)
|
igor@29
|
296 run_command("sudo ip link set %s up" % bridge)
|
igor@29
|
297 autoredraw()
|
igor@22
|
298
|
igor@22
|
299 def show_bridge(bridge):
|
igor@22
|
300 """
|
igor@22
|
301 Show the state of the bridge <bridge>
|
igor@22
|
302 """
|
igor@38
|
303 if bridge in real_bridges:
|
igor@38
|
304 print "Bridge %s is a real bridge" % (bridge)
|
igor@38
|
305 return -1
|
igor@22
|
306 run_command("sudo ip link show %s" % bridge)
|
igor@22
|
307
|
igor@23
|
308
|
igor@23
|
309 def int_disconnect(domain, int_number):
|
igor@23
|
310 """
|
igor@23
|
311 Disconnect the interface with the number <int_number>
|
igor@23
|
312 of the domain <domain> from the bridge to which
|
igor@23
|
313 it is connected
|
igor@23
|
314 """
|
igor@23
|
315 dom_id=get_domain_id(domain)
|
igor@23
|
316 bridge=vbridges_table[domain][int_number]
|
igor@23
|
317 if not bridge:
|
igor@23
|
318 print "Interface %s of the %s domain is not connected" % (int_number, domain)
|
igor@23
|
319 return 1
|
igor@23
|
320 run_command("sudo brctl delif %s vif%s.%s" % (bridge, dom_id, int_number))
|
igor@23
|
321 vbridges_table[domain][int_number]=''
|
igor@28
|
322 if [ domain, int_number, bridge ] in temporary_links:
|
igor@28
|
323 temporary_links.remove([ domain, int_number, bridge ])
|
igor@27
|
324 else:
|
igor@28
|
325 broken_links.append([ domain, int_number, bridge ])
|
igor@27
|
326 autoredraw()
|
igor@23
|
327
|
igor@23
|
328 def int_connect(domain, int_number, bridge):
|
igor@23
|
329 """
|
igor@23
|
330 Connect the interface with the number <int_number>
|
igor@24
|
331 of the domain <domain> to the bridge <bridge>
|
igor@23
|
332 """
|
igor@38
|
333 if bridge in real_bridges:
|
igor@38
|
334 print "Bridge %s is a real bridge" % (bridge)
|
igor@38
|
335 return -1
|
igor@38
|
336
|
igor@23
|
337 dom_id=get_domain_id(domain)
|
igor@23
|
338 if vbridges_table[domain][int_number]:
|
igor@23
|
339 print "Interface %s of the %s domain is connected already to the %s bridge" % (int_number, domain, vbridges_table[domain][int_number])
|
igor@23
|
340 return 1
|
igor@23
|
341 run_command("sudo brctl addif %s vif%s.%s" % (bridge, dom_id, int_number))
|
igor@23
|
342 vbridges_table[domain][int_number]=bridge
|
igor@28
|
343 if [ domain, int_number, bridge ] in broken_links:
|
igor@28
|
344 broken_links.remove([ domain, int_number, bridge ])
|
igor@27
|
345 else:
|
igor@28
|
346 temporary_links.append([ domain, int_number, bridge ])
|
igor@27
|
347 autoredraw()
|
igor@23
|
348
|
igor@24
|
349 def int_reconnect(domain, int_number, bridge):
|
igor@24
|
350 """
|
igor@24
|
351 Reconnect the interface with the number <int_number>
|
igor@24
|
352 of the domain <domain> from the bridge to which
|
igor@24
|
353 it is connected to the bridge <bridge>
|
igor@24
|
354 """
|
igor@38
|
355 if bridge in real_bridges:
|
igor@38
|
356 print "Bridge %s is a real bridge" % (bridge)
|
igor@38
|
357 return -1
|
igor@38
|
358
|
igor@24
|
359 int_disconnect(domain, int_number)
|
igor@24
|
360 int_connect(domain, int_number, bridge)
|
igor@24
|
361
|
igor@24
|
362 def show_int(domain, int_number):
|
igor@25
|
363 """
|
igor@25
|
364 Show information about the interface <int_nuber>
|
igor@25
|
365 of the domain <domain>
|
igor@25
|
366 """
|
igor@26
|
367 return vbridges_table[domain][int_number]
|
igor@24
|
368
|
igor@28
|
369
|
igor@28
|
370 def dump_start(bridge, filter=""):
|
igor@38
|
371 if bridge in real_bridges:
|
igor@38
|
372 print "Bridge %s is a real bridge" % (bridge)
|
igor@38
|
373 return -1
|
igor@32
|
374 try:
|
igor@32
|
375 print "Writing dump... (press Ctrl-C to stop)"
|
igor@32
|
376 run_command("sudo tcpdump -w xentaur.dump -i %s %s > /dev/null 2>&1 " % (bridge,filter))
|
igor@32
|
377 except:
|
igor@32
|
378 print "Done.\n Dump is written to xentaur.dump"
|
igor@28
|
379 return 0
|
igor@28
|
380
|
igor@28
|
381 def dump_stop():
|
igor@28
|
382 return 0
|
igor@33
|
383
|
igor@33
|
384
|
igor@33
|
385 #-----------------------------------------------------------------------
|
igor@33
|
386 # CONFIGURATION TEMPLATES
|
igor@33
|
387
|
igor@33
|
388
|
igor@33
|
389 def configure_ip_addresses(doms=domains):
|
igor@40
|
390
|
igor@40
|
391 cisco_set_ip_on_int="""
|
igor@40
|
392 \n\n\n
|
igor@40
|
393 int fa%s/0
|
igor@40
|
394 no ip address
|
igor@40
|
395 ip address %s 255.255.255.0
|
igor@40
|
396 no shutdown
|
igor@40
|
397 exit
|
igor@40
|
398 """
|
igor@40
|
399
|
igor@40
|
400 quagga_set_ip_on_int="""
|
igor@40
|
401 int eth%s
|
igor@40
|
402 no ip address
|
igor@40
|
403 ip address %s/24
|
igor@40
|
404 no shutdown
|
igor@40
|
405 exit
|
igor@40
|
406 """
|
igor@40
|
407
|
igor@40
|
408 for dom in doms:
|
igor@40
|
409 i=domains.index(dom)+1
|
igor@40
|
410 if domain_types[domains.index(dom)] == 'quagga':
|
igor@40
|
411 command = quagga_set_ip_on_int
|
igor@40
|
412 write_to(i,"\nconf t\n")
|
igor@40
|
413 j=0
|
igor@40
|
414 for br in vbridges_table[dom]:
|
igor@40
|
415 write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)))
|
igor@40
|
416 j+=1
|
igor@40
|
417 write_to(i,"\nend\n")
|
igor@40
|
418 else:
|
igor@40
|
419 command = cisco_set_ip_on_int
|
igor@40
|
420 write_to(i,"\nena\nconf t\n")
|
igor@40
|
421 j=0
|
igor@40
|
422 for br in vbridges_table[dom]:
|
igor@40
|
423 write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)))
|
igor@40
|
424 j+=1
|
igor@40
|
425 write_to(i,"\nend\n")
|
igor@40
|
426 return 0
|
igor@40
|
427
|
igor@40
|
428 def configure_no_ip_addresses(doms=domains):
|
igor@40
|
429
|
igor@40
|
430 cisco_set_ip_on_int="""
|
igor@40
|
431 \n\n\n
|
igor@40
|
432 int fa%s/0
|
igor@40
|
433 no ip address %s 255.255.255.0
|
igor@40
|
434 exit
|
igor@40
|
435 """
|
igor@40
|
436
|
igor@40
|
437 quagga_set_ip_on_int="""
|
igor@40
|
438 int eth%s
|
igor@40
|
439 no ip address %s/24
|
igor@40
|
440 exit
|
igor@40
|
441 """
|
igor@40
|
442
|
igor@40
|
443 for dom in doms:
|
igor@40
|
444 i=domains.index(dom)+1
|
igor@40
|
445 if domain_types[domains.index(dom)] == 'quagga':
|
igor@40
|
446 command = quagga_set_ip_on_int
|
igor@40
|
447 write_to(i,"\nconf t\n")
|
igor@40
|
448 j=0
|
igor@40
|
449 for br in vbridges_table[dom]:
|
igor@40
|
450 write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)))
|
igor@40
|
451 j+=1
|
igor@40
|
452 write_to(i,"\nend\n")
|
igor@40
|
453 else:
|
igor@40
|
454 command = cisco_set_ip_on_int
|
igor@40
|
455 write_to(i,"\nena\nconf t\n")
|
igor@40
|
456 j=0
|
igor@40
|
457 for br in vbridges_table[dom]:
|
igor@40
|
458 write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)))
|
igor@40
|
459 j+=1
|
igor@40
|
460 write_to(i,"\nend\n")
|
igor@33
|
461 return 0
|
igor@33
|
462
|
igor@33
|
463 def configure_ospf(doms=domains):
|
igor@40
|
464 for dom in doms:
|
igor@40
|
465 if domain_types[domains.index(dom)] == 'quagga':
|
igor@40
|
466 write_to(dom,"\n\nconf t\nrouter ospf\nnetwork 192.168.0.0/16 area 0\nend\n")
|
igor@40
|
467 else:
|
igor@40
|
468 write_to(dom,"\n\nena\nconf t\nrouter ospf 1\nnetwork 192.168.0.0 0.0.255.255 area 0\nend\n")
|
igor@33
|
469 return 0
|
igor@33
|
470
|
igor@33
|
471 def configure_save(doms=domains):
|
igor@33
|
472 write_to(doms,"\nwr\n")
|
igor@33
|
473
|
igor@0
|
474 #-----------------------------------------------------------------------
|
igor@0
|
475
|
igor@0
|
476
|
igor@0
|
477 def add_domain(name,type):
|
igor@0
|
478 domains.append(name)
|
igor@0
|
479 domain_types.append(type)
|
igor@0
|
480
|
igor@0
|
481 def brake_link(domain,bridge):
|
igor@0
|
482 broken_links.append([domain,bridge])
|
igor@0
|
483
|
igor@4
|
484 wt_timeout=0.5
|
igor@8
|
485 def write_to(screen,string,return_to_screen=""):
|
igor@2
|
486 """
|
igor@2
|
487 write_to(screen,string):
|
igor@2
|
488
|
igor@8
|
489 Type *string* to the specified screen(s).
|
igor@8
|
490 Screen may be specified with the number *screen*,
|
igor@8
|
491 with array of numbers,
|
igor@8
|
492 with array of names.
|
igor@2
|
493
|
igor@2
|
494 """
|
igor@5
|
495 screen_numbers=[] # number of the screens to write to
|
igor@5
|
496 if type(screen) == list:
|
igor@5
|
497 screen_numbers=map(lambda x: domains.index(x)+1, screen)
|
igor@5
|
498 elif type(screen) == int:
|
igor@5
|
499 screen_numbers=[screen]
|
igor@5
|
500 else:
|
igor@5
|
501 screen_numbers=[domains.index(screen)+1]
|
igor@5
|
502
|
igor@5
|
503 for screen_number in screen_numbers:
|
igor@5
|
504 run_command("screen -X select "+str(screen_number))
|
igor@5
|
505 time.sleep(wt_timeout)
|
igor@5
|
506 for line in string.splitlines():
|
igor@5
|
507 f=open('/tmp/xentaurbuf', 'w')
|
igor@5
|
508 f.write(line+"\n")
|
igor@5
|
509 f.close()
|
igor@5
|
510 run_command("screen -X readreg p /tmp/xentaurbuf")
|
igor@5
|
511 time.sleep(wt_timeout)
|
igor@5
|
512 run_command("nohup screen -X paste p >& /dev/null")
|
igor@5
|
513 time.sleep(wt_timeout)
|
igor@5
|
514
|
igor@8
|
515 if return_to_screen != "":
|
igor@8
|
516 run_command("screen -X select %s" % (return_to_screen))
|
igor@8
|
517 time.sleep(wt_timeout)
|
igor@0
|
518
|
igor@0
|
519 #-----------------------------------------------------------------------
|
igor@0
|
520
|
igor@5
|
521 cisco_fa01_up="""
|
igor@5
|
522 ena
|
igor@5
|
523 conf t
|
igor@5
|
524 int fa0/0
|
igor@5
|
525 no shutdown
|
igor@5
|
526 exit
|
igor@5
|
527 int fa1/0
|
igor@5
|
528 no shutdown
|
igor@5
|
529 exit
|
igor@5
|
530 exit
|
igor@5
|
531 exit
|
igor@5
|
532 """
|
igor@5
|
533
|
igor@5
|
534 cisco_set_ip_on_int="""
|
igor@5
|
535 interface fa%s/0
|
igor@5
|
536 no ip address
|
igor@5
|
537 ip address %s 255.255.255.0
|
igor@5
|
538 exit
|
igor@5
|
539 """
|
igor@5
|
540
|
igor@33
|
541
|
igor@0
|
542
|
igor@0
|
543 nodes=domains
|
igor@0
|
544
|
igor@0
|
545 if len(sys.argv) > 1:
|
igor@0
|
546 if sys.argv[1] == 'start':
|
igor@0
|
547 start_all()
|
igor@0
|
548 if sys.argv[1] == 'stop':
|
igor@0
|
549 stop_all()
|
igor@0
|
550 if sys.argv[1] == 'start-bridges':
|
igor@3
|
551 create_bridges_script()
|
igor@0
|
552 if sys.argv[1] == 'start-domains':
|
igor@3
|
553 create_domains_script()
|
igor@0
|
554 if sys.argv[1] == 'stop-domains':
|
igor@3
|
555 destroy_domains_script()
|
igor@0
|
556 elif sys.argv[1] == 'screen':
|
igor@3
|
557 create_screens_script()
|
igor@0
|
558 elif sys.argv[1] == 'graph':
|
igor@0
|
559 graph()
|
igor@0
|
560 elif sys.argv[1] == 'shell':
|
igor@0
|
561 shell()
|
igor@0
|
562
|
igor@0
|
563 else:
|
igor@0
|
564 show_usage()
|
igor@0
|
565 sys.exit(1)
|
igor@0
|
566
|
igor@0
|
567 sys.exit(0)
|
igor@0
|
568
|
igor@0
|
569
|