# HG changeset patch # User Igor Chubin # Date 1263207695 -7200 # Node ID 6c145935ece529d2cfce391f10d55b86aec13e59 # Parent aaf034af3a357e133b6c0f554cc59c8772e9fa49 Fixed path scripts and configuration templates moved to a single file. diff -r aaf034af3a35 -r 6c145935ece5 configuration_templates.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/configuration_templates.py Mon Jan 11 13:01:35 2010 +0200 @@ -0,0 +1,151 @@ +#----------------------------------------------------------------------- +# CONFIGURATION TEMPLATES + +cisco_fa01_up=""" +ena +conf t +int fa0/0 +duplex half +no shutdown +exit +int fa1/0 +duplex half +no shutdown +exit +exit +exit +""" + +cisco_set_ip_on_int=""" +interface fa%s/0 +no ip address +ip address %s 255.255.255.0 +exit +""" + + + +def configure_ip_addresses(doms=domains): + + cisco_set_ip_on_int=""" +int fa%s/0 +duplex full +no ip address +ip address %s 255.255.255.0 +no shutdown +exit +""" + + quagga_set_ip_on_int=""" +int eth%s +no ip address +ip address %s/24 +no shutdown +exit +""" + + linux_set_ip_on_int=""" +ifconfig eth%s %s netmask 255.255.255.0 +""" + + for dom in doms: + i=domains.index(dom)+1 + if domain_types[domains.index(dom)] == 'quagga': + command = quagga_set_ip_on_int + write_to(i,"conf t\n") + j=0 + for br in vbridges_table[dom]: + write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) + j+=1 + write_to(i,"end\n") + elif domain_types[domains.index(dom)] == 'linux': + command = linux_set_ip_on_int + j=0 + for br in vbridges_table[dom]: + #write_to(i, command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)) ) + print i, command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)) + j+=1 + else: + command = cisco_set_ip_on_int + write_to(i,"ena\nconf t\n") + j=0 + for br in vbridges_table[dom]: + write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) + j+=1 + write_to(i,"end\n") + return 0 + +def configure_no_ip_addresses(doms=domains): + cisco_set_ip_on_int=""" +int fa%s/0 +no ip address %s 255.255.255.0 +exit +""" + quagga_set_ip_on_int=""" +int eth%s +no ip address %s/24 +exit +""" + for dom in doms: + i=domains.index(dom)+1 + if domain_types[domains.index(dom)] == 'quagga': + command = quagga_set_ip_on_int + write_to(i,"\nconf t\n") + j=0 + for br in vbridges_table[dom]: + write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) + j+=1 + write_to(i,"\nend\n") + else: + command = cisco_set_ip_on_int + write_to(i,"\n\n\nena\nconf t\n") + j=0 + for br in vbridges_table[dom]: + write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) + j+=1 + write_to(i,"\nend\n") + return 0 + +def configure_ospf(doms=domains): + for dom in doms: + if domain_types[domains.index(dom)] == 'quagga': + write_to(dom,"\n\nconf t\nrouter ospf\nnetwork 192.168.0.0/16 area 0\nend\n") + else: + write_to(dom,"\n\nena\nconf t\nrouter ospf 1\nnetwork 192.168.0.0 0.0.255.255 area 0\nend\n") + return 0 + +def configure_hostname(doms=domains): + for dom in doms: + if domain_types[domains.index(dom)] == 'quagga': + write_to(dom,"\n\nconf t\nhostname %s\nend\n" % dom) + else: + write_to(dom,"\n\nena\nconf t\nhostname %s\nend\n" % dom) + return 0 + +def configure_logging_synchronous(doms=domains): + for dom in domains: + if domain_types[domains.index(dom)] == 'quagga': + 0 + else: + write_to(dom,"\n\nena\nconf t\nline console 0\nlogging synchronous\nend\n") + return 0 + +def configure_exec_timeout_0(doms=domains): + for dom in domains: + if domain_types[domains.index(dom)] == 'quagga': + 0 + else: + write_to(dom,"\n\nena\nconf t\nline console 0\nexec-timeout 0\nend\n") + return 0 + +def configure_no_cdp_log_mismatch_duplex(doms=domains): + for dom in filter_by_type(domains,'dynamips'): + write_to(dom,"\n\nena\nconf t\nno cdp log mismatch duplex\nend\n") + +def configure_save(doms=domains): + write_to(doms,"\nwr\n") + +def configure_root(doms=domains): + write_to(doms,"root\n") + + diff -r aaf034af3a35 -r 6c145935ece5 files/ec2-instances --- a/files/ec2-instances Sat Jan 09 20:20:08 2010 +0200 +++ b/files/ec2-instances Mon Jan 11 13:01:35 2010 +0200 @@ -1,23 +1,10 @@ #!/bin/sh -DOMAIN=ec2.xgu.ru -NETWORK=net1 -INSTANCES_NUMBER=2 -INSTANCE_AMI=ami-b21ff8db -INSTANCE_AMI=ami-7cfd1a15 -SSH_SECRET_KEY=~/.ec2/id_rsa-pstam-keypair -SSH_KEYPAIR=pstam-keypair -VOLUME_NAME=vol-28d13141 -EC2_ZONE=us-east-1a -DOMAIN=ec2.xgu.ru -SCRIPTS_PATH=~/hg/xentaur/files - -XGURULLA_DIR=~/.xgurulla/ -WORK_DIR=${XGURULLA_DIR}/${NETWORK} -mkdir -p ${WORK_DIR} - -set -e -x +# should be run from ~/.xentaur/$NETWORK/ +# and variable NETWORK set +set -e source ./start-instances-$NETWORK +# variables is here # start_emulators is here message() diff -r aaf034af3a35 -r 6c145935ece5 xentaur.py --- a/xentaur.py Sat Jan 09 20:20:08 2010 +0200 +++ b/xentaur.py Mon Jan 11 13:01:35 2010 +0200 @@ -20,14 +20,21 @@ sys.path.append(path_network) sys.path.append('.') + node_object={} link_object={} bridge_object={} ec2_node={} +# ec2 settings +ec2_dns_domain='ec2.xgu.ru' +ec2_zone="us-east-1a" + domain='dyn1' from xendomain import * +execfile(path_xentaur+"/configuration_templates.py") + bridges_turned_down=[] def run(program, *args): @@ -82,14 +89,12 @@ def ec2_assign_nodes_to_instances(): domain_number=0 for dom in domains: - node_name=network+"-node%s"%(domain_number/2) - ec2_node[dom]=node_name + node_name=network+"-node%s"%(domain_number/3) + ec2_node[dom]=node_name+"."+ec2_dns_domain domain_number+=1 def make_start_emulators(): s="" - #s+="cat screenrc_template > screenrc_$NETWORK\n" - #s+="echo \"screen -t console 0 sh -c 'cd ~/xentaur; ./xentaur.py shell'\" >> screenrc_$NETWORK\n" ios="/mnt/ios/C7200-AD.BIN" ec2_assign_nodes_to_instances() for dom in domains: @@ -108,22 +113,38 @@ i+=1 s += "ssh %s \"mkdir -p /mnt/%s; cd /mnt/%s; screen -S %s- -d -m %s\"\n"%(node_name,dom,dom,dom,line) s += "ssh %s \"%s\"\n" % (node_name, line2) - #s += "echo \"screen %s ssh -t %s 'screen -r %s-'\" >> screenrc_%s\n" % (domain_number, node_name, dom, network) - #s += "echo \"screen -t %s %s connect-ec2-session INSTANCE EC2_NODE %s %s %s\" >> screenrc_$NETWORK\n" % (dom, domain_number+1, node_name, network, dom) return s def make_start_instances_config(net=network): f = open(path_network+"/start-instances-"+network, "w"); - f.write("INSTANCES_NUMBER=%s\n"%((len(domains)+1)/2)) + f.write(""" +NETWORK=%(network)s +INSTANCES_NUMBER=%(instances_number)s +INSTANCE_AMI=ami-b21ff8db +INSTANCE_AMI=ami-7cfd1a15 +VOLUME_NAME=vol-28d13141 +SSH_SECRET_KEY=~/.ec2/id_rsa-pstam-keypair +SSH_KEYPAIR=pstam-keypair +EC2_ZONE=%(ec2_zone)s +DOMAIN=%(ec2_dns_domain)s +SCRIPTS_PATH=%(path_scripts)s +""" % { + "network" : network, + "instances_number" : len(set(ec2_node.values())), + "path_scripts" : path_scripts, + + "ec2_dns_domain" : ec2_dns_domain, + "ec2_zone" : ec2_zone, + }) f.write("start_emulators()\n{\n%s\n}\n"%make_start_emulators()) f.close() def start_network(net=network): make_start_instances_config() - #run_command("cd %s; env NETWORK=%s sh %s instances start" % (path_network, network, path_scrips+"/ec2-instances")) + run_command("cd %s; env NETWORK=%s sh %s start" % (path_network, network, path_scripts+"/ec2-instances")) def stop_network(net=network): - run_command("cd %s; env NETWORK=%s sh instances stop" % (path_network, network)) + run_command("cd %s; env NETWORK=%s sh %s stop" % (path_network, network, path_scripts+"/ec2-instances")) ## Stop @@ -223,7 +244,6 @@ screenlist="\n".join(screens) hardstatus='hardstatus string "%{rk}Xentaur%{bk}@%H %{gk}%c %{yk}%d.%m %{wk}%?%-Lw%?%{bw}%n*%f%t%?(%u)%?%{wk}%?%+Lw%?"' - f=open(screenrc, "w"); f.write(""" hardstatus on @@ -578,7 +598,6 @@ """ return vbridges_table[domain][int_number] - def dump_start(bridge, filter=""): if bridge in real_bridges: print "Bridge %s is a real bridge" % (bridge) @@ -595,148 +614,17 @@ #----------------------------------------------------------------------- -# CONFIGURATION TEMPLATES - - -def configure_ip_addresses(doms=domains): - - cisco_set_ip_on_int=""" -\n\n\n -int fa%s/0 -duplex full -no ip address -ip address %s 255.255.255.0 -no shutdown -exit -""" - - quagga_set_ip_on_int=""" -int eth%s -no ip address -ip address %s/24 -no shutdown -exit -""" - - linux_set_ip_on_int=""" -ifconfig eth%s %s netmask 255.255.255.0 -""" - - for dom in doms: - i=domains.index(dom)+1 - if domain_types[domains.index(dom)] == 'quagga': - command = quagga_set_ip_on_int - write_to(i,"\nconf t\n") - j=0 - for br in vbridges_table[dom]: - write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) - j+=1 - write_to(i,"\nend\n") - elif domain_types[domains.index(dom)] == 'linux': - command = linux_set_ip_on_int - j=0 - for br in vbridges_table[dom]: - #write_to(i, command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)) ) - print i, command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)) - j+=1 - else: - command = cisco_set_ip_on_int - write_to(i,"\nena\nconf t\n") - j=0 - for br in vbridges_table[dom]: - write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) - j+=1 - write_to(i,"\nend\n") - return 0 - -def configure_no_ip_addresses(doms=domains): - - cisco_set_ip_on_int=""" -\n\n\n -int fa%s/0 -no ip address %s 255.255.255.0 -exit -""" - - quagga_set_ip_on_int=""" -int eth%s -no ip address %s/24 -exit -""" - - for dom in doms: - i=domains.index(dom)+1 - if domain_types[domains.index(dom)] == 'quagga': - command = quagga_set_ip_on_int - write_to(i,"\nconf t\n") - j=0 - for br in vbridges_table[dom]: - write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) - j+=1 - write_to(i,"\nend\n") - else: - command = cisco_set_ip_on_int - write_to(i,"\nena\nconf t\n") - j=0 - for br in vbridges_table[dom]: - write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) - j+=1 - write_to(i,"\nend\n") - return 0 - -def configure_ospf(doms=domains): - for dom in doms: - if domain_types[domains.index(dom)] == 'quagga': - write_to(dom,"\n\nconf t\nrouter ospf\nnetwork 192.168.0.0/16 area 0\nend\n") - else: - write_to(dom,"\n\nena\nconf t\nrouter ospf 1\nnetwork 192.168.0.0 0.0.255.255 area 0\nend\n") - return 0 - -def configure_hostname(doms=domains): - for dom in doms: - if domain_types[domains.index(dom)] == 'quagga': - write_to(dom,"\n\nconf t\nhostname %s\nend\n" % dom) - else: - write_to(dom,"\n\nena\nconf t\nhostname %s\nend\n" % dom) - return 0 - -def configure_logging_synchronous(doms=domains): - for dom in domains: - if domain_types[domains.index(dom)] == 'quagga': - 0 - else: - write_to(dom,"\n\nena\nconf t\nline console 0\nlogging synchronous\nend\n") - return 0 - -def configure_exec_timeout_0(doms=domains): - for dom in domains: - if domain_types[domains.index(dom)] == 'quagga': - 0 - else: - write_to(dom,"\n\nena\nconf t\nline console 0\nexec-timeout 0\nend\n") - return 0 - -def configure_no_cdp_log_mismatch_duplex(doms=domains): - for dom in filter_by_type(domains,'dynamips'): - write_to(dom,"\n\nena\nconf t\nno cdp log mismatch duplex\nend\n") - -def configure_save(doms=domains): - write_to(doms,"\nwr\n") - -def configure_root(doms=domains): - write_to(doms,"root\n") - -#----------------------------------------------------------------------- - def add_domain(name,type): domains.append(name) domain_types.append(type) -def brake_link(domain,bridge): +def break_link(domain,bridge): broken_links.append([domain,bridge]) -wt_timeout=0.5 +#----------------------------------------------------------------------- + +wt_timeout=1 def write_to(screen,string,return_to_screen=""): """ write_to(screen,string): @@ -754,7 +642,7 @@ screen_numbers=[screen] else: screen_numbers=[domains.index(screen)+1] - + for screen_number in screen_numbers: run_command("screen -X select "+str(screen_number)) time.sleep(wt_timeout) @@ -766,7 +654,7 @@ time.sleep(wt_timeout) run_command("nohup screen -X paste p >& /dev/null") time.sleep(wt_timeout) - + if return_to_screen != "": run_command("screen -X select %s" % (return_to_screen)) time.sleep(wt_timeout) @@ -781,33 +669,9 @@ #----------------------------------------------------------------------- -cisco_fa01_up=""" -ena -conf t -int fa0/0 -duplex half -no shutdown -exit -int fa1/0 -duplex half -no shutdown -exit -exit -exit -""" - -cisco_set_ip_on_int=""" -interface fa%s/0 -no ip address -ip address %s 255.255.255.0 -exit -""" - nodes=domains - create_objects() - if len(sys.argv) == 2: if sys.argv[1] == 'start-all': start_all()