xentaur

view xentaur.py @ 65:cf823d27b029

Nattaur changes
author nata@nattaur
date Mon Oct 12 00:12:11 2009 +0300 (2009-10-12)
parents 07c6777758dc
children aaf034af3a35
line source
1 #!/usr/bin/python
2 # vim: set fileencoding=utf-8 :
4 import sys,os,time
6 xentaur_path="/xentaur/xentaur"
8 sys.path.append('/etc/xen')
9 sys.path.append(xentaur_path)
10 sys.path.append('.')
12 node_object={}
13 link_object={}
14 bridge_object={}
16 network='multicast'
17 domain='dyn1'
19 #network='snrs'
20 #domain='dyn1'
21 from xendomain import *
23 bridges_turned_down=[]
25 from IPython.Shell import IPShellEmbed
28 screenrc=".screenrc_xentaur_"+network
29 path_shapes='/xentaur/xentaur/shapes'
31 def run(program, *args):
32 pid = os.fork()
33 if not pid:
34 os.execvp(program, (program,) + args)
35 return os.wait()[0]
37 def run_command(line):
38 #cmds=line.split()
39 #run(cmds[0],*cmds[1:])
40 run("/bin/sh", "-c", line)
42 def run_command_return_stdout(line):
43 p = os.popen(line)
44 output = p.read()
45 p.close()
46 return output
48 ################################################################################
49 #Xentaur command-line commands
51 ## Start
53 def start_bridges():
54 unbound_bridges=set(bridges)-set(real_bridges)
55 script=""
56 script="\n".join(map(lambda x: "sudo brctl show | awk '{print $1}' | grep -qx "+x+" || sudo brctl addbr "+x, unbound_bridges))
57 script+="\n"+"\n".join(map(lambda x: "sudo brctl stp "+x+" off", unbound_bridges))
58 script+="\n"+"\n".join(map(lambda x: "sudo ip link set "+x+" up", unbound_bridges))
60 print """#!/bin/sh
61 # create unbound bridges
62 %s
63 """ % (script)
65 def start_domain(domain):
66 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"
68 def start_domains(doms=domains):
69 for domain in doms:
70 if not domain in real_nodes:
71 start_domain(domain)
73 def start_all():
74 graph()
75 screen()
76 start_bridges()
77 start_domains()
79 ## Stop
81 def stop_domain(domain,wait=0):
82 if wait:
83 print "sudo xm shutdown -w "+domain
84 else:
85 print "sudo xm shutdown "+domain
87 def stop_domains(doms=domains, wait=0):
88 for domain in doms:
89 if not domain in real_nodes:
90 stop_domain(domain,wait)
92 def stop_bridges():
93 ###FIXME###
94 return 0
96 def stop_all(wait=0):
97 stop_domains(domains, wait)
98 stop_bridges()
100 def restart_all():
101 stop_all(1)
102 start_all()
104 ####################################################
106 def create_objects():
107 create_node_objects()
108 create_bridge_objects()
109 create_link_objects()
111 def create_node_objects():
112 for dom in domains:
113 node_object[dom]=Node(dom)
115 def create_bridge_objects():
116 for bridge in bridges:
117 bridge_object[bridge]=Bridge(bridge)
119 def create_link_objects():
121 for node, bridges_raw in vbridges_table.iteritems():
122 interface=0
123 j=0
124 for this_bridge in bridges_raw:
125 int_label=""
126 if this_bridge.find(':') != -1:
127 res = this_bridge.split(':')
128 this_bridge= res[0]
129 bridges_raw[j] = this_bridge
130 int_label = res[1]
131 if not [ node, bridges_raw.index(this_bridge), this_bridge ] in temporary_links:
132 name="%s %s %s" % (node,interface,this_bridge)
133 link_object[name]=Link(name,node,interface,this_bridge,int_label)
134 interface+=1
135 vbridges_table[node]=bridges_raw
137 for node, bridges_raw in bridge_bridge_table.iteritems():
138 interface=0
139 j=0
140 for this_bridge in bridges_raw:
141 int_label=""
142 if this_bridge.find(':') != -1:
143 res = this_bridge.split(':')
144 this_bridge= res[2]
145 bridges_raw[j] = this_bridge
146 int_label = res[1]
147 if not [ node, bridges_raw.index(this_bridge), this_bridge ] in temporary_links:
148 name="%s %s %s" % (node,interface,this_bridge)
149 link_object[name]=Link(name,node,interface,this_bridge,int_label)
150 interface+=1
151 bridge_bridge_table[node]=bridges_raw
153 for node,interface,bridge in temporary_links:
154 name="%s %s %s" % (node,interface,bridge)
155 link_object[name]=Link(name,node,interface,this_bridge)
157 for node,interface,bridge in broken_links:
158 name="%s %s %s" % (node,interface,bridge)
159 link_object[name]=Link(name,node,interface,this_bridge)
162 ####################################################
164 def screen():
165 wait_seconds=1
166 screens=[]
167 for domain in domains:
168 screens.append("screen -t %s %s sh -c 'while true; do %s ; echo Retrying in %s secods...; sleep %s ; clear; done'" %
169 (domain,domains.index(domain)+1,node_object[domain].console_string(),wait_seconds,wait_seconds))
170 screenlist="\n".join(screens)
172 hardstatus='hardstatus string "%{rk}Xentaur%{bk}@%H %{gk}%c %{yk}%d.%m %{wk}%?%-Lw%?%{bw}%n*%f%t%?(%u)%?%{wk}%?%+Lw%?"'
174 f=open(screenrc, "w");
175 f.write("""
176 hardstatus on
177 hardstatus alwayslastline
178 %s
180 screen -t console 0 sh -c 'while true; do %s/xentaur.py shell ; echo Retrying in %s secods...; sleep %s ; clear; done'
181 %s
182 """ % (hardstatus,xentaur_path,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 %s
208 // bridges
209 %s
211 // physical
212 node [shape=rectangle,color=blue];
213 %s
215 // networks (not bridges, not physical)
216 node [shape=rectangle,color=green];
217 %s
219 // links (between nodes and bridges)
220 %s
222 };
223 """ % (nodelist, bridgelist, physicallist, networklist, linklist))
224 f.close()
225 run_command("neato -Tpng -o %s.png %s.dot "%(network,network))
226 run_command("neato -Tjpg -o %s.jpg %s.dot "%(network,network))
227 run_command("neato -Tsvg -o %s.svg %s.dot "%(network,network))
228 run_command("neato -Tcmapx -o %s.cmapx -NURL=http://google.com %s.dot "%(network,network))
229 print "# Network map is written to files: %s.{png,svg,jpg,dot}" % network
231 def autoredraw():
232 graph()
234 def shell():
235 autoredraw()
236 ipshell = IPShellEmbed()
237 ipshell()
239 def version():
240 print """
241 Xentaur 0.1-PRE
243 ,--,
244 _ ___/ /\\|
245 ,;`( )__, ) ~
246 // .// '--;
247 ' / \ |
249 """
250 # print "Xentaur 0.1-PRE"
251 # print "(Godzilla-mutant) _"
252 # print " / * \\"
253 # print " / .-"
254 # print " / |"
255 # print " | \\ \\\\ \\"
256 # print " _ -------| \\ \\\\ \\"
257 # print " / / \\_\\ -"
258 # print "/ |\\ | |"
259 # print "| | \\ .-----. | \\ |"
260 # print " | / \\ \\ \\ \\"
261 # print " \\/|.\\ \\ \\ \\ \\"
262 # print " \\| - . \\_\\ \\_\\"
263 # print "-----------------------------------------------"
266 def info():
267 version()
269 print "Network name: ", network
270 print "-----------------------------------------------"
271 print
272 print "Nodes: ", len(domains)
273 print " * virtual nodes: ", len(domains)-len(real_nodes)
274 print " * real nodes:", len(real_nodes)
275 print
276 print "Bridges:", len(bridges)
277 print " * virtual bridges:", len(bridges)-len(real_bridges)-len(cross_bridges)
278 print " * real switches:", len(real_bridges)
279 print " * direct links:", len(cross_bridges)
281 def show_usage():
282 print """Usage:
283 xentaur <command> [<argument>]
285 Commands:
286 start-all -- start bridges and domains
287 start-domains -- start domains only
288 start-bridges -- start bridges only
289 stop-all -- stop bridges and domains
290 stop-domains -- stop domains only
291 stop-bridges -- stop bridges only (domains have to be stopped already)
292 restart-all -- restart bridges and domains
294 start <domain> -- start the <domain>
295 stop <domain> -- stop the <domain>
297 graph -- generate network scheme (result is in <network>.{png,jpg,svg})
298 screen -- generate GNU Screen config file (~/.screenrc_xentaur)
299 shell -- run Xentaur shell
301 """
303 def save():
304 print "network =", xen_config_name
305 print "domains =", domains
306 print "domain_types =", domain_types
307 print "bridges =", bridges
308 print "vbridges_table =", vbridges_table
309 print "hidden_bridges =", hidden_bridges
310 print "broken_links =", broken_links
311 print "temporary_links =", temporary_links
312 print "bridges_turned_down =", bridges_turned_down
314 #-----------------------------------------------------------------------
315 # CLASSES
317 class Bridge:
318 def __init__ (self,name):
319 self.name=name
320 def up(self):
321 bridge_up(self.name)
322 def down(self):
323 bridge_down(self.name)
324 def show(self):
325 show_bridge(self.name)
326 def dump_start(self,filter=""):
327 dump_start(self.name,filter)
329 def is_hidden(self):
330 return self.name in hidden_bridges
331 def is_real(self):
332 return self.name in real_bridges
333 def is_turned_down(self):
334 return self.name in bridges_turned_down
335 def is_cross(self):
336 return self.name in cross_bridges
338 def graphviz_string(self):
339 if self.is_hidden():
340 return "//"
341 elif self.is_cross():
342 return "%s [shape=circle,height=0.03,color=black,fillcolor=black,style=filled,label=\"\"]" % (self.name)
343 elif self.is_real():
344 return "%s [color=white,shape=none,shapefile=\"%s/all/real_switch.png\"]" % (self.name, path_shapes)
345 elif self.is_turned_down():
346 return "%s [color=white,shape=none,shapefile=\"%s/all/switch_turned_down.png\"]" % (self.name, path_shapes)
347 else:
348 return "%s [color=white,shape=none,shapefile=\"%s/all/switch.png\"]" % (self.name, path_shapes)
351 class Node:
352 def __init__ (self,name):
353 self.name=name
354 self.type=domain_types[domains.index(name)]
355 def start(self):
356 return ""
357 def stop(self):
358 return ""
359 def start_commandline(self):
360 return ""
361 def get_domain_id(self):
362 return get_domain_id(self.name)
363 def graphviz_string(self):
364 return self.name+" [color=white,shape=plaintext,label=\" "+self.name+"\",shapefile=\""+path_shapes+"/all/"+\
365 domain_types[domains.index(self.name)]+".png\",fontcolor=black,fontsize=16,target=\"http://google.com\"]"
366 def console_string(self):
367 if self.type in [ 'quagga', 'dynamips', 'freebsd', 'linux' ]:
368 return "sudo xm console "+self.name
369 elif self.name in real_bridges or self.name in real_nodes:
370 return "echo Press enter to connect; read line; "+connection_table[self.name]
373 class Link:
374 def __init__ (self,name,node,interface,bridge,label=""):
375 self.name=name
376 self.node=node
377 self.interface=interface
378 self.bridge=bridge
379 self.label=label
381 def is_temporary(self):
382 return [self.node,self.interface,self.bridge] in temporary_links
384 def is_broken(self):
385 return ([self.node,self.interface,self.bridge] in broken_links)
387 def is_hidden(self):
388 return self.bridge in hidden_bridges
390 def graphviz_string(self):
391 if self.is_hidden():
392 return "//"
393 if self.is_temporary():
394 return self.node+" -- "+self.bridge+" [taillabel=\"fa"+str(self.interface)+"/0\",color=blue,len=10,w=5,weight=5]"
395 if self.is_broken():
396 return self.node+" -- "+self.bridge+" [taillabel=\"fa"+str(self.interface)+"/0\",style=dashed]"
398 ip="\\n.%s.%s" % (bridges.index(self.bridge)+1, domains.index(self.node)+1)
399 if domain_types[domains.index(self.node)] == 'xenomips':
400 int_name="fa"+str(self.interface)+"/0"
401 else:
402 int_name="eth"+str(self.interface)
403 if self.label != "":
404 int_name = self.label
405 return self.node+" -- "+self.bridge+" [taillabel=\""+int_name+ip+"\",fontsize=14,fontname=fixed]"
408 #-----------------------------------------------------------------------
409 # DOMAINS
411 def get_domain_id(domain):
412 return run_command_return_stdout("sudo xm list | awk '{if ($1 == \"'%s'\") print $2}'" % domain).rstrip("\n")
415 #-----------------------------------------------------------------------
416 # BRIDGES and IFACES
418 def bridge_down(bridge):
419 """
420 Turn the bridge <bridge> down
421 """
422 if bridge in real_bridges:
423 print "Bridge %s is a real bridge" % (bridge)
424 return -1
425 if bridge in bridges_turned_down:
426 print "Bridge %s is turned down already" % (bridge)
427 else:
428 bridges_turned_down.append(bridge)
429 run_command("sudo ip link set %s down" % bridge)
430 autoredraw()
432 def bridge_up(bridge):
433 """
434 Turn the bridge <bridge> up
435 """
436 if bridge in real_bridges:
437 print "Bridge %s is a real bridge" % (bridge)
438 return -1
439 if not (bridge in bridges_turned_down):
440 print "Bridge %s is turned up already" % (bridge)
441 else:
442 bridges_turned_down.remove(bridge)
443 run_command("sudo ip link set %s up" % bridge)
444 autoredraw()
446 def show_bridge(bridge):
447 """
448 Show the state of the bridge <bridge>
449 """
450 if bridge in real_bridges:
451 print "Bridge %s is a real bridge" % (bridge)
452 return -1
453 run_command("sudo ip link show %s" % bridge)
456 def int_disconnect(domain, int_number):
457 """
458 Disconnect the interface with the number <int_number>
459 of the domain <domain> from the bridge to which
460 it is connected
461 """
462 dom_id=get_domain_id(domain)
463 bridge=vbridges_table[domain][int_number]
464 if not bridge:
465 print "Interface %s of the %s domain is not connected" % (int_number, domain)
466 return 1
467 run_command("sudo brctl delif %s vif%s.%s" % (bridge, dom_id, int_number))
468 vbridges_table[domain][int_number]=''
469 if [ domain, int_number, bridge ] in temporary_links:
470 temporary_links.remove([ domain, int_number, bridge ])
471 else:
472 broken_links.append([ domain, int_number, bridge ])
473 autoredraw()
475 def int_connect(domain, int_number, bridge):
476 """
477 Connect the interface with the number <int_number>
478 of the domain <domain> to the bridge <bridge>
479 """
480 if bridge in real_bridges:
481 print "Bridge %s is a real bridge" % (bridge)
482 return -1
484 dom_id=get_domain_id(domain)
485 if vbridges_table[domain][int_number]:
486 print "Interface %s of the %s domain is connected already to the %s bridge" % (int_number, domain, vbridges_table[domain][int_number])
487 return 1
488 run_command("sudo brctl addif %s vif%s.%s" % (bridge, dom_id, int_number))
489 vbridges_table[domain][int_number]=bridge
490 if [ domain, int_number, bridge ] in broken_links:
491 broken_links.remove([ domain, int_number, bridge ])
492 else:
493 temporary_links.append([ domain, int_number, bridge ])
494 autoredraw()
496 def int_reconnect(domain, int_number, bridge):
497 """
498 Reconnect the interface with the number <int_number>
499 of the domain <domain> from the bridge to which
500 it is connected to the bridge <bridge>
501 """
502 if bridge in real_bridges:
503 print "Bridge %s is a real bridge" % (bridge)
504 return -1
506 int_disconnect(domain, int_number)
507 int_connect(domain, int_number, bridge)
509 def show_int(domain, int_number):
510 """
511 Show information about the interface <int_nuber>
512 of the domain <domain>
513 """
514 return vbridges_table[domain][int_number]
517 def dump_start(bridge, filter=""):
518 if bridge in real_bridges:
519 print "Bridge %s is a real bridge" % (bridge)
520 return -1
521 try:
522 print "Writing dump... (press Ctrl-C to stop)"
523 run_command("sudo tcpdump -w xentaur.dump -i %s %s > /dev/null 2>&1 " % (bridge,filter))
524 except:
525 print "Done.\n Dump is written to xentaur.dump"
526 return 0
528 def dump_stop():
529 return 0
532 #-----------------------------------------------------------------------
533 # CONFIGURATION TEMPLATES
536 def configure_ip_addresses(doms=domains):
538 cisco_set_ip_on_int="""
539 \n\n\n
540 int fa%s/0
541 no ip address
542 ip address %s 255.255.255.0
543 no shutdown
544 exit
545 """
547 quagga_set_ip_on_int="""
548 int eth%s
549 no ip address
550 ip address %s/24
551 no shutdown
552 exit
553 """
555 linux_set_ip_on_int="""
556 ifconfig eth%s %s netmask 255.255.255.0
557 """
559 for dom in doms:
560 i=domains.index(dom)+1
561 if domain_types[domains.index(dom)] == 'quagga':
562 command = quagga_set_ip_on_int
563 write_to(i,"\nconf t\n")
564 j=0
565 for br in vbridges_table[dom]:
566 write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)))
567 j+=1
568 write_to(i,"\nend\n")
569 elif domain_types[domains.index(dom)] == 'linux':
570 command = linux_set_ip_on_int
571 j=0
572 for br in vbridges_table[dom]:
573 #write_to(i, command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)) )
574 print i, command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))
575 j+=1
576 else:
577 command = cisco_set_ip_on_int
578 write_to(i,"\nena\nconf t\n")
579 j=0
580 for br in vbridges_table[dom]:
581 write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)))
582 j+=1
583 write_to(i,"\nend\n")
584 return 0
586 def configure_no_ip_addresses(doms=domains):
588 cisco_set_ip_on_int="""
589 \n\n\n
590 int fa%s/0
591 no ip address %s 255.255.255.0
592 exit
593 """
595 quagga_set_ip_on_int="""
596 int eth%s
597 no ip address %s/24
598 exit
599 """
601 for dom in doms:
602 i=domains.index(dom)+1
603 if domain_types[domains.index(dom)] == 'quagga':
604 command = quagga_set_ip_on_int
605 write_to(i,"\nconf t\n")
606 j=0
607 for br in vbridges_table[dom]:
608 write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)))
609 j+=1
610 write_to(i,"\nend\n")
611 else:
612 command = cisco_set_ip_on_int
613 write_to(i,"\nena\nconf t\n")
614 j=0
615 for br in vbridges_table[dom]:
616 write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)))
617 j+=1
618 write_to(i,"\nend\n")
619 return 0
621 def configure_ospf(doms=domains):
622 for dom in doms:
623 if domain_types[domains.index(dom)] == 'quagga':
624 write_to(dom,"\n\nconf t\nrouter ospf\nnetwork 192.168.0.0/16 area 0\nend\n")
625 else:
626 write_to(dom,"\n\nena\nconf t\nrouter ospf 1\nnetwork 192.168.0.0 0.0.255.255 area 0\nend\n")
627 return 0
629 def configure_hostname(doms=domains):
630 for dom in doms:
631 if domain_types[domains.index(dom)] == 'quagga':
632 write_to(dom,"\n\nconf t\nhostname %s\nend\n" % dom)
633 else:
634 write_to(dom,"\n\nena\nconf t\nhostname %s\nend\n" % dom)
635 return 0
637 def configure_logging_synchronous(doms=domains):
638 for dom in domains:
639 if domain_types[domains.index(dom)] == 'quagga':
640 0
641 else:
642 write_to(dom,"\n\nena\nconf t\nline console 0\nlogging synchronous\nend\n")
643 return 0
645 def configure_exec_timeout_0(doms=domains):
646 for dom in domains:
647 if domain_types[domains.index(dom)] == 'quagga':
648 0
649 else:
650 write_to(dom,"\n\nena\nconf t\nline console 0\nexec-timeout 0\nend\n")
651 return 0
653 def configure_no_cdp_log_mismatch_duplex(doms=domains):
654 for dom in filter_by_type(domains,'xenomips'):
655 write_to(dom,"\n\nena\nconf t\nno cdp log mismatch duplex\nend\n")
657 def configure_save(doms=domains):
658 write_to(doms,"\nwr\n")
660 def configure_root(doms=domains):
661 write_to(doms,"root\n")
663 #-----------------------------------------------------------------------
666 def add_domain(name,type):
667 domains.append(name)
668 domain_types.append(type)
670 def brake_link(domain,bridge):
671 broken_links.append([domain,bridge])
673 wt_timeout=0.5
674 def write_to(screen,string,return_to_screen=""):
675 """
676 write_to(screen,string):
678 Type *string* to the specified screen(s).
679 Screen may be specified with the number *screen*,
680 with array of numbers,
681 with array of names.
683 """
684 screen_numbers=[] # number of the screens to write to
685 if type(screen) == list:
686 screen_numbers=map(lambda x: domains.index(x)+1, screen)
687 elif type(screen) == int:
688 screen_numbers=[screen]
689 else:
690 screen_numbers=[domains.index(screen)+1]
692 for screen_number in screen_numbers:
693 run_command("screen -X select "+str(screen_number))
694 time.sleep(wt_timeout)
695 for line in string.splitlines():
696 f=open('/tmp/xentaurbuf', 'w')
697 f.write(line+"\n")
698 f.close()
699 run_command("screen -X readreg p /tmp/xentaurbuf")
700 time.sleep(wt_timeout)
701 run_command("nohup screen -X paste p >& /dev/null")
702 time.sleep(wt_timeout)
704 if return_to_screen != "":
705 run_command("screen -X select %s" % (return_to_screen))
706 time.sleep(wt_timeout)
708 def filter_by_type(doms,type):
709 """
710 filter_by_type(doms,type)
712 Return only domains of *doms* that have specified *type*
713 """
714 return filter(lambda x: domain_types[domains.index(x)]==type,domains)
716 #-----------------------------------------------------------------------
718 cisco_fa01_up="""
719 ena
720 conf t
721 int fa0/0
722 duplex half
723 no shutdown
724 exit
725 int fa1/0
726 duplex half
727 no shutdown
728 exit
729 exit
730 exit
731 """
733 cisco_set_ip_on_int="""
734 interface fa%s/0
735 no ip address
736 ip address %s 255.255.255.0
737 exit
738 """
740 nodes=domains
742 create_objects()
745 if len(sys.argv) == 2:
746 if sys.argv[1] == 'start-all':
747 start_all()
748 elif sys.argv[1] == 'start-domains':
749 start_domains()
750 elif sys.argv[1] == 'start-bridges':
751 start_bridges()
752 elif sys.argv[1] == 'stop-all':
753 stop_all()
754 elif sys.argv[1] == 'stop-domains':
755 stop_domains()
756 elif sys.argv[1] == 'stop-bridges':
757 stop_bridges()
758 elif sys.argv[1] == 'restart-all':
759 restart_all()
760 elif sys.argv[1] == 'screen':
761 screen()
762 elif sys.argv[1] == 'graph':
763 graph()
764 elif sys.argv[1] == 'shell':
765 shell()
766 elif sys.argv[1] == 'info':
767 info()
768 else:
769 show_usage()
770 sys.exit(1)
771 elif len(sys.argv) == 3:
772 if sys.argv[1] == 'start':
773 start_domain(sys.argv[2])
774 elif sys.argv[1] == 'stop':
775 stop_domain(sys.argv[2])
776 elif sys.argv[1] == 'restart':
777 stop_domain(sys.argv[2])
778 start_domain(sys.argv[2])
779 else:
780 show_usage()
781 sys.exit(1)
782 else:
783 show_usage()
784 sys.exit(1)
786 sys.exit(0)