xentaur

view xentaur.py @ 62:e838c1223b89

Делаются какие-то попытки интегрировать в Xentaur
управление разнообразными доменами.
author igor
date Thu Feb 21 21:41:20 2008 +0200 (2008-02-21)
parents 6471afbee150
children 07c6777758dc
line source
1 #!/usr/bin/python
2 # vim: set fileencoding=utf-8 :
4 import sys,os,time
6 xentaur_path=os.environ['HOME']+"/xentaur"
8 sys.path.append('/etc/xen')
9 sys.path.append(xentaur_path)
11 #network='snrs_ipsec_rsa_1'
12 node_object={}
13 link_object={}
14 bridge_object={}
16 network='ids2007dec'
17 domain='fbsd1'
19 #network='snrs'
20 #domain='dyn1'
21 from xendomain import *
23 bridges_turned_down=[]
25 from IPython.Shell import IPShellEmbed
28 screenrc=os.environ['HOME']+"/.screenrc_xentaur"
30 def run(program, *args):
31 pid = os.fork()
32 if not pid:
33 os.execvp(program, (program,) + args)
34 return os.wait()[0]
36 def run_command(line):
37 #cmds=line.split()
38 #run(cmds[0],*cmds[1:])
39 run("/bin/sh", "-c", line)
41 def run_command_return_stdout(line):
42 p = os.popen(line)
43 output = p.read()
44 p.close()
45 return output
47 ################################################################################
48 #Xentaur command-line commands
50 ## Start
52 def start_bridges():
53 unbound_bridges=set(bridges)-set(real_bridges)
54 script=""
55 script="\n".join(map(lambda x: "sudo brctl show | awk '{print $1}' | grep -qx "+x+" || sudo brctl addbr "+x, unbound_bridges))
56 script+="\n"+"\n".join(map(lambda x: "sudo brctl stp "+x+" off", unbound_bridges))
57 script+="\n"+"\n".join(map(lambda x: "sudo ip link set "+x+" up", unbound_bridges))
59 print """#!/bin/sh
60 # create unbound bridges
61 %s
62 """ % (script)
64 def start_domain(domain):
65 print "sudo xm create "+xentaur_path+"/xendomain.py "+" domain="+domain+" network="+network+" && sleep 1 && sudo xm sched-credit -d $(sudo xm list | grep "+domain+" | awk '{print $2}') -c 10 && sleep 1"
67 def start_domains(doms=domains):
68 for domain in doms:
69 if not domain in real_nodes:
70 start_domain(domain)
72 def start_all():
73 graph()
74 screen()
75 start_bridges()
76 start_domains()
78 ## Stop
80 def stop_domain(domain,wait=0):
81 if wait:
82 print "sudo xm shutdown -w "+domain
83 else:
84 print "sudo xm shutdown "+domain
86 def stop_domains(doms=domains, wait=0):
87 for domain in doms:
88 if not domain in real_nodes:
89 stop_domain(domain,wait)
91 def stop_bridges():
92 ###FIXME###
93 return 0
95 def stop_all(wait=0):
96 stop_domains(domains, wait)
97 stop_bridges()
99 def restart_all():
100 stop_all(1)
101 start_all()
103 ####################################################
105 def create_objects():
106 create_node_objects()
107 create_bridge_objects()
108 create_link_objects()
110 def create_node_objects():
111 for dom in domains:
112 node_object[dom]=Node(dom)
114 def create_bridge_objects():
115 for bridge in bridges:
116 bridge_object[bridge]=Bridge(bridge)
118 def create_link_objects():
120 for node, bridges_raw in vbridges_table.iteritems():
121 interface=0
122 j=0
123 for this_bridge in bridges_raw:
124 int_label=""
125 if this_bridge.find(':') != -1:
126 res = this_bridge.split(':')
127 this_bridge= res[0]
128 bridges_raw[j] = this_bridge
129 int_label = res[1]
130 if not [ node, bridges_raw.index(this_bridge), this_bridge ] in temporary_links:
131 name="%s %s %s" % (node,interface,this_bridge)
132 link_object[name]=Link(name,node,interface,this_bridge,int_label)
133 interface+=1
134 vbridges_table[node]=bridges_raw
136 for node, bridges_raw in bridge_bridge_table.iteritems():
137 interface=0
138 j=0
139 for this_bridge in bridges_raw:
140 int_label=""
141 if this_bridge.find(':') != -1:
142 res = this_bridge.split(':')
143 this_bridge= res[0]
144 bridges_raw[j] = this_bridge
145 int_label = res[1]
146 if not [ node, bridges_raw.index(this_bridge), this_bridge ] in temporary_links:
147 name="%s %s %s" % (node,interface,this_bridge)
148 link_object[name]=Link(name,node,interface,this_bridge,int_label)
149 interface+=1
150 bridge_bridge_table[node]=bridges_raw
152 for node,interface,bridge in temporary_links:
153 name="%s %s %s" % (node,interface,bridge)
154 link_object[name]=Link(name,node,interface,this_bridge)
156 for node,interface,bridge in broken_links:
157 name="%s %s %s" % (node,interface,bridge)
158 link_object[name]=Link(name,node,interface,this_bridge)
161 ####################################################
163 def screen():
164 wait_seconds=1
165 screens=[]
166 for domain in domains:
167 screens.append("screen -t %s %s sh -c 'while true; do %s ; echo Retrying in %s secods...; sleep %s ; clear; done'" %
168 (domain,domains.index(domain)+1,node_object[domain].console_string(),wait_seconds,wait_seconds))
169 screenlist="\n".join(screens)
171 hardstatus='hardstatus string "%{rk}Xentaur%{bk}@%H %{gk}%c %{yk}%d.%m %{wk}%?%-Lw%?%{bw}%n*%f%t%?(%u)%?%{wk}%?%+Lw%?"'
173 f=open(screenrc, "w");
174 f.write("""
175 hardstatus on
176 hardstatus alwayslastline
177 %s
179 screen -t console 0 sh -c 'while true; do cd %s; ./xentaur.py shell ; echo Retrying in %s secods...; sleep %s ; clear; done'
180 #screen -t xentaur - sh -c 'while true; do bash ; echo Retrying in %s secods...; sleep %s ; clear; done'
181 %s
182 """ % (hardstatus,xentaur_path,wait_seconds,wait_seconds,wait_seconds,wait_seconds,screenlist))
183 f.close()
184 print "# GNU Screen config file is written to: %s" % screenrc
186 def graph():
187 nodelist=""
188 bridgelist=""
189 linklist=""
190 physicallist=""
191 networklist=""
193 nodelist=";\n ".join(map(lambda node: node_object[node].graphviz_string(),nodes))
194 if nodelist: nodelist += ";"
195 bridgelist=";\n ".join(map(lambda bridge: bridge_object[bridge].graphviz_string(),bridges))
196 if bridgelist: bridgelist += ";"
197 linklist=";\n ".join(map(lambda link: link_object[link].graphviz_string(),link_object.keys()))
198 if linklist: linklist += ";"
200 f = open(network+".dot", "w");
201 f.write ("""
202 graph G {
203 edge [len=1.25];
204 splines=true;
205 // nodes
206 // node [shape=plaintext,color=white,shapefile="shapes/cisco.bmp/router.png"];
207 %s
209 // bridges
210 // node [shape=none,shapefile="shapes/all/switch.png"];
211 %s
213 // physical
214 node [shape=rectangle,color=blue];
215 %s
217 // networks (not bridges, not physical)
218 node [shape=rectangle,color=green];
219 %s
221 // links (between nodes and bridges)
222 %s
224 };
225 """ % (nodelist, bridgelist, physicallist, networklist, linklist))
226 f.close()
227 run_command("neato -Tpng -o %s.png %s.dot "%(network,network))
228 run_command("neato -Tjpg -o %s.jpg %s.dot "%(network,network))
229 run_command("neato -Tsvg -o %s.svg %s.dot "%(network,network))
230 run_command("neato -Tcmapx -o %s.cmapx -NURL=http://google.com %s.dot "%(network,network))
231 print "# Network map is written to files: %s.{png,svg,jpg,dot}" % network
233 def autoredraw():
234 graph()
236 def shell():
237 autoredraw()
238 ipshell = IPShellEmbed()
239 ipshell()
241 def version():
242 print """
243 Xentaur 0.1-PRE
245 ,--,
246 _ ___/ /\\|
247 ,;`( )__, ) ~
248 // .// '--;
249 ' / \ |
251 """
252 # print "Xentaur 0.1-PRE"
253 # print "(Godzilla-mutant) _"
254 # print " / * \\"
255 # print " / .-"
256 # print " / |"
257 # print " | \\ \\\\ \\"
258 # print " _ -------| \\ \\\\ \\"
259 # print " / / \\_\\ -"
260 # print "/ |\\ | |"
261 # print "| | \\ .-----. | \\ |"
262 # print " | / \\ \\ \\ \\"
263 # print " \\/|.\\ \\ \\ \\ \\"
264 # print " \\| - . \\_\\ \\_\\"
265 # print "-----------------------------------------------"
268 def info():
269 version()
271 print "Network name: ", network
272 print "-----------------------------------------------"
273 print
274 print "Nodes: ", len(domains)
275 print " * virtual nodes: ", len(domains)-len(real_nodes)
276 print " * real nodes:", len(real_nodes)
277 print
278 print "Bridges:", len(bridges)
279 print " * virtual bridges:", len(bridges)-len(real_bridges)-len(cross_bridges)
280 print " * real switches:", len(real_bridges)
281 print " * direct links:", len(cross_bridges)
283 def show_usage():
284 print """Usage:
285 xentaur <command> [<argument>]
287 Commands:
288 start-all -- start bridges and domains
289 start-domains -- start domains only
290 start-bridges -- start bridges only
291 stop-all -- stop bridges and domains
292 stop-domains -- stop domains only
293 stop-bridges -- stop bridges only (domains have to be stopped already)
294 restart-all -- restart bridges and domains
296 start <domain> -- start the <domain>
297 stop <domain> -- stop the <domain>
299 graph -- generate network scheme (result is in <network>.{png,jpg,svg})
300 screen -- generate GNU Screen config file (~/.screenrc_xentaur)
301 shell -- run Xentaur shell
303 """
305 def save():
306 print "network =", xen_config_name
307 print "domains =", domains
308 print "domain_types =", domain_types
309 print "bridges =", bridges
310 print "vbridges_table =", vbridges_table
311 print "hidden_bridges =", hidden_bridges
312 print "broken_links =", broken_links
313 print "temporary_links =", temporary_links
314 print "bridges_turned_down =", bridges_turned_down
316 #-----------------------------------------------------------------------
317 # CLASSES
319 class Bridge:
320 def __init__ (self,name):
321 self.name=name
322 def up(self):
323 bridge_up(self.name)
324 def down(self):
325 bridge_down(self.name)
326 def show(self):
327 show_bridge(self.name)
328 def dump_start(self,filter=""):
329 dump_start(self.name,filter)
331 def is_hidden(self):
332 return self.name in hidden_bridges
333 def is_real(self):
334 return self.name in real_bridges
335 def is_turned_down(self):
336 return self.name in bridges_turned_down
337 def is_cross(self):
338 return self.name in cross_bridges
340 def graphviz_string(self):
341 if self.is_hidden():
342 return ""
343 elif self.is_cross():
344 return "%s [shape=circle,height=0.03,color=black,fillcolor=black,style=filled,label=\"\"]" % (self.name)
345 elif self.is_real():
346 return "%s [color=white,shape=none,shapefile=\"shapes/all/real_switch.png\"]" % (self.name)
347 elif self.is_turned_down():
348 return "%s [color=white,shape=none,shapefile=\"shapes/all/switch_turned_down.png\"]" % (self.name)
349 else:
350 return "%s [color=white,shape=none,shapefile=\"shapes/all/switch.png\"]" % (self.name)
353 class Node:
354 def __init__ (self,name):
355 self.name=name
356 self.type=domain_types[domains.index(name)]
357 def start(self):
358 return ""
359 def stop(self):
360 return ""
361 def start_commandline(self):
362 return ""
363 def get_domain_id(self):
364 return get_domain_id(self.name)
365 def graphviz_string(self):
366 return self.name+" [color=white,shape=plaintext,label=\" "+self.name+"\",shapefile=\"shapes/all/"+\
367 domain_types[domains.index(self.name)]+".png\",fontcolor=black,fontsize=16,target=\"http://google.com\"]"
368 def console_string(self):
369 if self.type in [ 'quagga', 'xenomips', 'freebsd', 'linux' ]:
370 return "sudo xm console "+self.name
371 elif self.name in real_bridges or self.name in real_nodes:
372 return "echo Press enter to connect; read line; "+connection_table[self.name]
375 class Link:
376 def __init__ (self,name,node,interface,bridge,label=""):
377 self.name=name
378 self.node=node
379 self.interface=interface
380 self.bridge=bridge
381 self.label=label
383 def is_temporary(self):
384 return [self.node,self.interface,self.bridge] in temporary_links
386 def is_broken(self):
387 return ([self.node,self.interface,self.bridge] in broken_links)
389 def graphviz_string(self):
390 if self.is_temporary():
391 return self.node+" -- "+self.bridge+" [taillabel=\"fa"+str(self.interface)+"/0\",color=blue,len=10,w=5,weight=5]"
392 if self.is_broken():
393 return self.node+" -- "+self.bridge+" [taillabel=\"fa"+str(self.interface)+"/0\",style=dashed]"
395 ip="\\n.%s.%s" % (bridges.index(self.bridge)+1, domains.index(self.node)+1)
396 if domain_types[domains.index(self.node)] == 'xenomips':
397 int_name="fa"+str(self.interface)+"/0"
398 else:
399 int_name="eth"+str(self.interface)
400 if self.label != "":
401 int_name = self.label
402 return self.node+" -- "+self.bridge+" [taillabel=\""+int_name+ip+"\",fontsize=14,fontname=fixed]"
405 #-----------------------------------------------------------------------
406 # DOMAINS
408 def get_domain_id(domain):
409 return run_command_return_stdout("sudo xm list | awk '{if ($1 == \"'%s'\") print $2}'" % domain).rstrip("\n")
412 #-----------------------------------------------------------------------
413 # BRIDGES and IFACES
415 def bridge_down(bridge):
416 """
417 Turn the bridge <bridge> down
418 """
419 if bridge in real_bridges:
420 print "Bridge %s is a real bridge" % (bridge)
421 return -1
422 if bridge in bridges_turned_down:
423 print "Bridge %s is turned down already" % (bridge)
424 else:
425 bridges_turned_down.append(bridge)
426 run_command("sudo ip link set %s down" % bridge)
427 autoredraw()
429 def bridge_up(bridge):
430 """
431 Turn the bridge <bridge> up
432 """
433 if bridge in real_bridges:
434 print "Bridge %s is a real bridge" % (bridge)
435 return -1
436 if not (bridge in bridges_turned_down):
437 print "Bridge %s is turned up already" % (bridge)
438 else:
439 bridges_turned_down.remove(bridge)
440 run_command("sudo ip link set %s up" % bridge)
441 autoredraw()
443 def show_bridge(bridge):
444 """
445 Show the state of the bridge <bridge>
446 """
447 if bridge in real_bridges:
448 print "Bridge %s is a real bridge" % (bridge)
449 return -1
450 run_command("sudo ip link show %s" % bridge)
453 def int_disconnect(domain, int_number):
454 """
455 Disconnect the interface with the number <int_number>
456 of the domain <domain> from the bridge to which
457 it is connected
458 """
459 dom_id=get_domain_id(domain)
460 bridge=vbridges_table[domain][int_number]
461 if not bridge:
462 print "Interface %s of the %s domain is not connected" % (int_number, domain)
463 return 1
464 run_command("sudo brctl delif %s vif%s.%s" % (bridge, dom_id, int_number))
465 vbridges_table[domain][int_number]=''
466 if [ domain, int_number, bridge ] in temporary_links:
467 temporary_links.remove([ domain, int_number, bridge ])
468 else:
469 broken_links.append([ domain, int_number, bridge ])
470 autoredraw()
472 def int_connect(domain, int_number, bridge):
473 """
474 Connect the interface with the number <int_number>
475 of the domain <domain> to the bridge <bridge>
476 """
477 if bridge in real_bridges:
478 print "Bridge %s is a real bridge" % (bridge)
479 return -1
481 dom_id=get_domain_id(domain)
482 if vbridges_table[domain][int_number]:
483 print "Interface %s of the %s domain is connected already to the %s bridge" % (int_number, domain, vbridges_table[domain][int_number])
484 return 1
485 run_command("sudo brctl addif %s vif%s.%s" % (bridge, dom_id, int_number))
486 vbridges_table[domain][int_number]=bridge
487 if [ domain, int_number, bridge ] in broken_links:
488 broken_links.remove([ domain, int_number, bridge ])
489 else:
490 temporary_links.append([ domain, int_number, bridge ])
491 autoredraw()
493 def int_reconnect(domain, int_number, bridge):
494 """
495 Reconnect the interface with the number <int_number>
496 of the domain <domain> from the bridge to which
497 it is connected to the bridge <bridge>
498 """
499 if bridge in real_bridges:
500 print "Bridge %s is a real bridge" % (bridge)
501 return -1
503 int_disconnect(domain, int_number)
504 int_connect(domain, int_number, bridge)
506 def show_int(domain, int_number):
507 """
508 Show information about the interface <int_nuber>
509 of the domain <domain>
510 """
511 return vbridges_table[domain][int_number]
514 def dump_start(bridge, filter=""):
515 if bridge in real_bridges:
516 print "Bridge %s is a real bridge" % (bridge)
517 return -1
518 try:
519 print "Writing dump... (press Ctrl-C to stop)"
520 run_command("sudo tcpdump -w xentaur.dump -i %s %s > /dev/null 2>&1 " % (bridge,filter))
521 except:
522 print "Done.\n Dump is written to xentaur.dump"
523 return 0
525 def dump_stop():
526 return 0
529 #-----------------------------------------------------------------------
530 # CONFIGURATION TEMPLATES
533 def configure_ip_addresses(doms=domains):
535 cisco_set_ip_on_int="""
536 \n\n\n
537 int fa%s/0
538 no ip address
539 ip address %s 255.255.255.0
540 no shutdown
541 exit
542 """
544 quagga_set_ip_on_int="""
545 int eth%s
546 no ip address
547 ip address %s/24
548 no shutdown
549 exit
550 """
552 for dom in doms:
553 i=domains.index(dom)+1
554 if domain_types[domains.index(dom)] == 'quagga':
555 command = quagga_set_ip_on_int
556 write_to(i,"\nconf t\n")
557 j=0
558 for br in vbridges_table[dom]:
559 write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)))
560 j+=1
561 write_to(i,"\nend\n")
562 else:
563 command = cisco_set_ip_on_int
564 write_to(i,"\nena\nconf t\n")
565 j=0
566 for br in vbridges_table[dom]:
567 write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)))
568 j+=1
569 write_to(i,"\nend\n")
570 return 0
572 def configure_no_ip_addresses(doms=domains):
574 cisco_set_ip_on_int="""
575 \n\n\n
576 int fa%s/0
577 no ip address %s 255.255.255.0
578 exit
579 """
581 quagga_set_ip_on_int="""
582 int eth%s
583 no ip address %s/24
584 exit
585 """
587 for dom in doms:
588 i=domains.index(dom)+1
589 if domain_types[domains.index(dom)] == 'quagga':
590 command = quagga_set_ip_on_int
591 write_to(i,"\nconf t\n")
592 j=0
593 for br in vbridges_table[dom]:
594 write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)))
595 j+=1
596 write_to(i,"\nend\n")
597 else:
598 command = cisco_set_ip_on_int
599 write_to(i,"\nena\nconf t\n")
600 j=0
601 for br in vbridges_table[dom]:
602 write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)))
603 j+=1
604 write_to(i,"\nend\n")
605 return 0
607 def configure_ospf(doms=domains):
608 for dom in doms:
609 if domain_types[domains.index(dom)] == 'quagga':
610 write_to(dom,"\n\nconf t\nrouter ospf\nnetwork 192.168.0.0/16 area 0\nend\n")
611 else:
612 write_to(dom,"\n\nena\nconf t\nrouter ospf 1\nnetwork 192.168.0.0 0.0.255.255 area 0\nend\n")
613 return 0
615 def configure_hostname(doms=domains):
616 for dom in doms:
617 if domain_types[domains.index(dom)] == 'quagga':
618 write_to(dom,"\n\nconf t\nhostname %s\nend\n" % dom)
619 else:
620 write_to(dom,"\n\nena\nconf t\nhostname %s\nend\n" % dom)
621 return 0
623 def configure_logging_synchronous(doms=domains):
624 for dom in domains:
625 if domain_types[domains.index(dom)] == 'quagga':
626 0
627 else:
628 write_to(dom,"\n\nena\nconf t\nline console 0\nlogging synchronous\nend\n")
629 return 0
631 def configure_exec_timeout_0(doms=domains):
632 for dom in domains:
633 if domain_types[domains.index(dom)] == 'quagga':
634 0
635 else:
636 write_to(dom,"\n\nena\nconf t\nline console 0\nexec-timeout 0\nend\n")
637 return 0
639 def configure_no_cdp_log_mismatch_duplex(doms=domains):
640 for dom in filter_by_type(domains,'xenomips'):
641 write_to(dom,"\n\nena\nconf t\nno cdp log mismatch duplex\nend\n")
643 def configure_save(doms=domains):
644 write_to(doms,"\nwr\n")
646 def configure_root(doms=domains):
647 write_to(doms,"root\n")
649 #-----------------------------------------------------------------------
652 def add_domain(name,type):
653 domains.append(name)
654 domain_types.append(type)
656 def brake_link(domain,bridge):
657 broken_links.append([domain,bridge])
659 wt_timeout=0.5
660 def write_to(screen,string,return_to_screen=""):
661 """
662 write_to(screen,string):
664 Type *string* to the specified screen(s).
665 Screen may be specified with the number *screen*,
666 with array of numbers,
667 with array of names.
669 """
670 screen_numbers=[] # number of the screens to write to
671 if type(screen) == list:
672 screen_numbers=map(lambda x: domains.index(x)+1, screen)
673 elif type(screen) == int:
674 screen_numbers=[screen]
675 else:
676 screen_numbers=[domains.index(screen)+1]
678 for screen_number in screen_numbers:
679 run_command("screen -X select "+str(screen_number))
680 time.sleep(wt_timeout)
681 for line in string.splitlines():
682 f=open('/tmp/xentaurbuf', 'w')
683 f.write(line+"\n")
684 f.close()
685 run_command("screen -X readreg p /tmp/xentaurbuf")
686 time.sleep(wt_timeout)
687 run_command("nohup screen -X paste p >& /dev/null")
688 time.sleep(wt_timeout)
690 if return_to_screen != "":
691 run_command("screen -X select %s" % (return_to_screen))
692 time.sleep(wt_timeout)
694 def filter_by_type(doms,type):
695 """
696 filter_by_type(doms,type)
698 Return only domains of *doms* that have specified *type*
699 """
700 return filter(lambda x: domain_types[domains.index(x)]==type,domains)
702 #-----------------------------------------------------------------------
704 cisco_fa01_up="""
705 ena
706 conf t
707 int fa0/0
708 duplex half
709 no shutdown
710 exit
711 int fa1/0
712 duplex half
713 no shutdown
714 exit
715 exit
716 exit
717 """
719 cisco_set_ip_on_int="""
720 interface fa%s/0
721 no ip address
722 ip address %s 255.255.255.0
723 exit
724 """
726 nodes=domains
728 create_objects()
731 if len(sys.argv) == 2:
732 if sys.argv[1] == 'start-all':
733 start_all()
734 elif sys.argv[1] == 'start-domains':
735 start_domains()
736 elif sys.argv[1] == 'start-bridges':
737 start_bridges()
738 elif sys.argv[1] == 'stop-all':
739 stop_all()
740 elif sys.argv[1] == 'stop-domains':
741 stop_domains()
742 elif sys.argv[1] == 'stop-bridges':
743 stop_bridges()
744 elif sys.argv[1] == 'restart-all':
745 restart_all()
746 elif sys.argv[1] == 'screen':
747 screen()
748 elif sys.argv[1] == 'graph':
749 graph()
750 elif sys.argv[1] == 'shell':
751 shell()
752 elif sys.argv[1] == 'info':
753 info()
754 else:
755 show_usage()
756 sys.exit(1)
757 elif len(sys.argv) == 3:
758 if sys.argv[1] == 'start':
759 start_domain(sys.argv[2])
760 elif sys.argv[1] == 'stop':
761 stop_domain(sys.argv[2])
762 elif sys.argv[1] == 'restart':
763 stop_domain(sys.argv[2])
764 start_domain(sys.argv[2])
765 else:
766 show_usage()
767 sys.exit(1)
768 else:
769 show_usage()
770 sys.exit(1)
772 sys.exit(0)