xentaur
changeset 67:6c145935ece5
Fixed path scripts and configuration templates moved to a single file.
author | Igor Chubin <igor@chub.in> |
---|---|
date | Mon Jan 11 13:01:35 2010 +0200 (2010-01-11) |
parents | aaf034af3a35 |
children | f652fab38c7a |
files | configuration_templates.py files/ec2-instances xentaur.py |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/configuration_templates.py Mon Jan 11 13:01:35 2010 +0200 1.3 @@ -0,0 +1,151 @@ 1.4 +#----------------------------------------------------------------------- 1.5 +# CONFIGURATION TEMPLATES 1.6 + 1.7 +cisco_fa01_up=""" 1.8 +ena 1.9 +conf t 1.10 +int fa0/0 1.11 +duplex half 1.12 +no shutdown 1.13 +exit 1.14 +int fa1/0 1.15 +duplex half 1.16 +no shutdown 1.17 +exit 1.18 +exit 1.19 +exit 1.20 +""" 1.21 + 1.22 +cisco_set_ip_on_int=""" 1.23 +interface fa%s/0 1.24 +no ip address 1.25 +ip address %s 255.255.255.0 1.26 +exit 1.27 +""" 1.28 + 1.29 + 1.30 + 1.31 +def configure_ip_addresses(doms=domains): 1.32 + 1.33 + cisco_set_ip_on_int=""" 1.34 +int fa%s/0 1.35 +duplex full 1.36 +no ip address 1.37 +ip address %s 255.255.255.0 1.38 +no shutdown 1.39 +exit 1.40 +""" 1.41 + 1.42 + quagga_set_ip_on_int=""" 1.43 +int eth%s 1.44 +no ip address 1.45 +ip address %s/24 1.46 +no shutdown 1.47 +exit 1.48 +""" 1.49 + 1.50 + linux_set_ip_on_int=""" 1.51 +ifconfig eth%s %s netmask 255.255.255.0 1.52 +""" 1.53 + 1.54 + for dom in doms: 1.55 + i=domains.index(dom)+1 1.56 + if domain_types[domains.index(dom)] == 'quagga': 1.57 + command = quagga_set_ip_on_int 1.58 + write_to(i,"conf t\n") 1.59 + j=0 1.60 + for br in vbridges_table[dom]: 1.61 + write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) 1.62 + j+=1 1.63 + write_to(i,"end\n") 1.64 + elif domain_types[domains.index(dom)] == 'linux': 1.65 + command = linux_set_ip_on_int 1.66 + j=0 1.67 + for br in vbridges_table[dom]: 1.68 + #write_to(i, command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)) ) 1.69 + print i, command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)) 1.70 + j+=1 1.71 + else: 1.72 + command = cisco_set_ip_on_int 1.73 + write_to(i,"ena\nconf t\n") 1.74 + j=0 1.75 + for br in vbridges_table[dom]: 1.76 + write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) 1.77 + j+=1 1.78 + write_to(i,"end\n") 1.79 + return 0 1.80 + 1.81 +def configure_no_ip_addresses(doms=domains): 1.82 + cisco_set_ip_on_int=""" 1.83 +int fa%s/0 1.84 +no ip address %s 255.255.255.0 1.85 +exit 1.86 +""" 1.87 + quagga_set_ip_on_int=""" 1.88 +int eth%s 1.89 +no ip address %s/24 1.90 +exit 1.91 +""" 1.92 + for dom in doms: 1.93 + i=domains.index(dom)+1 1.94 + if domain_types[domains.index(dom)] == 'quagga': 1.95 + command = quagga_set_ip_on_int 1.96 + write_to(i,"\nconf t\n") 1.97 + j=0 1.98 + for br in vbridges_table[dom]: 1.99 + write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) 1.100 + j+=1 1.101 + write_to(i,"\nend\n") 1.102 + else: 1.103 + command = cisco_set_ip_on_int 1.104 + write_to(i,"\n\n\nena\nconf t\n") 1.105 + j=0 1.106 + for br in vbridges_table[dom]: 1.107 + write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) 1.108 + j+=1 1.109 + write_to(i,"\nend\n") 1.110 + return 0 1.111 + 1.112 +def configure_ospf(doms=domains): 1.113 + for dom in doms: 1.114 + if domain_types[domains.index(dom)] == 'quagga': 1.115 + write_to(dom,"\n\nconf t\nrouter ospf\nnetwork 192.168.0.0/16 area 0\nend\n") 1.116 + else: 1.117 + write_to(dom,"\n\nena\nconf t\nrouter ospf 1\nnetwork 192.168.0.0 0.0.255.255 area 0\nend\n") 1.118 + return 0 1.119 + 1.120 +def configure_hostname(doms=domains): 1.121 + for dom in doms: 1.122 + if domain_types[domains.index(dom)] == 'quagga': 1.123 + write_to(dom,"\n\nconf t\nhostname %s\nend\n" % dom) 1.124 + else: 1.125 + write_to(dom,"\n\nena\nconf t\nhostname %s\nend\n" % dom) 1.126 + return 0 1.127 + 1.128 +def configure_logging_synchronous(doms=domains): 1.129 + for dom in domains: 1.130 + if domain_types[domains.index(dom)] == 'quagga': 1.131 + 0 1.132 + else: 1.133 + write_to(dom,"\n\nena\nconf t\nline console 0\nlogging synchronous\nend\n") 1.134 + return 0 1.135 + 1.136 +def configure_exec_timeout_0(doms=domains): 1.137 + for dom in domains: 1.138 + if domain_types[domains.index(dom)] == 'quagga': 1.139 + 0 1.140 + else: 1.141 + write_to(dom,"\n\nena\nconf t\nline console 0\nexec-timeout 0\nend\n") 1.142 + return 0 1.143 + 1.144 +def configure_no_cdp_log_mismatch_duplex(doms=domains): 1.145 + for dom in filter_by_type(domains,'dynamips'): 1.146 + write_to(dom,"\n\nena\nconf t\nno cdp log mismatch duplex\nend\n") 1.147 + 1.148 +def configure_save(doms=domains): 1.149 + write_to(doms,"\nwr\n") 1.150 + 1.151 +def configure_root(doms=domains): 1.152 + write_to(doms,"root\n") 1.153 + 1.154 +
2.1 --- a/files/ec2-instances Sat Jan 09 20:20:08 2010 +0200 2.2 +++ b/files/ec2-instances Mon Jan 11 13:01:35 2010 +0200 2.3 @@ -1,23 +1,10 @@ 2.4 #!/bin/sh 2.5 2.6 -DOMAIN=ec2.xgu.ru 2.7 -NETWORK=net1 2.8 -INSTANCES_NUMBER=2 2.9 -INSTANCE_AMI=ami-b21ff8db 2.10 -INSTANCE_AMI=ami-7cfd1a15 2.11 -SSH_SECRET_KEY=~/.ec2/id_rsa-pstam-keypair 2.12 -SSH_KEYPAIR=pstam-keypair 2.13 -VOLUME_NAME=vol-28d13141 2.14 -EC2_ZONE=us-east-1a 2.15 -DOMAIN=ec2.xgu.ru 2.16 -SCRIPTS_PATH=~/hg/xentaur/files 2.17 - 2.18 -XGURULLA_DIR=~/.xgurulla/ 2.19 -WORK_DIR=${XGURULLA_DIR}/${NETWORK} 2.20 -mkdir -p ${WORK_DIR} 2.21 - 2.22 -set -e -x 2.23 +# should be run from ~/.xentaur/$NETWORK/ 2.24 +# and variable NETWORK set 2.25 +set -e 2.26 source ./start-instances-$NETWORK 2.27 +# variables is here 2.28 # start_emulators is here 2.29 2.30 message()
3.1 --- a/xentaur.py Sat Jan 09 20:20:08 2010 +0200 3.2 +++ b/xentaur.py Mon Jan 11 13:01:35 2010 +0200 3.3 @@ -20,14 +20,21 @@ 3.4 sys.path.append(path_network) 3.5 sys.path.append('.') 3.6 3.7 + 3.8 node_object={} 3.9 link_object={} 3.10 bridge_object={} 3.11 ec2_node={} 3.12 3.13 +# ec2 settings 3.14 +ec2_dns_domain='ec2.xgu.ru' 3.15 +ec2_zone="us-east-1a" 3.16 + 3.17 domain='dyn1' 3.18 from xendomain import * 3.19 3.20 +execfile(path_xentaur+"/configuration_templates.py") 3.21 + 3.22 bridges_turned_down=[] 3.23 3.24 def run(program, *args): 3.25 @@ -82,14 +89,12 @@ 3.26 def ec2_assign_nodes_to_instances(): 3.27 domain_number=0 3.28 for dom in domains: 3.29 - node_name=network+"-node%s"%(domain_number/2) 3.30 - ec2_node[dom]=node_name 3.31 + node_name=network+"-node%s"%(domain_number/3) 3.32 + ec2_node[dom]=node_name+"."+ec2_dns_domain 3.33 domain_number+=1 3.34 3.35 def make_start_emulators(): 3.36 s="" 3.37 - #s+="cat screenrc_template > screenrc_$NETWORK\n" 3.38 - #s+="echo \"screen -t console 0 sh -c 'cd ~/xentaur; ./xentaur.py shell'\" >> screenrc_$NETWORK\n" 3.39 ios="/mnt/ios/C7200-AD.BIN" 3.40 ec2_assign_nodes_to_instances() 3.41 for dom in domains: 3.42 @@ -108,22 +113,38 @@ 3.43 i+=1 3.44 s += "ssh %s \"mkdir -p /mnt/%s; cd /mnt/%s; screen -S %s- -d -m %s\"\n"%(node_name,dom,dom,dom,line) 3.45 s += "ssh %s \"%s\"\n" % (node_name, line2) 3.46 - #s += "echo \"screen %s ssh -t %s 'screen -r %s-'\" >> screenrc_%s\n" % (domain_number, node_name, dom, network) 3.47 - #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) 3.48 return s 3.49 3.50 def make_start_instances_config(net=network): 3.51 f = open(path_network+"/start-instances-"+network, "w"); 3.52 - f.write("INSTANCES_NUMBER=%s\n"%((len(domains)+1)/2)) 3.53 + f.write(""" 3.54 +NETWORK=%(network)s 3.55 +INSTANCES_NUMBER=%(instances_number)s 3.56 +INSTANCE_AMI=ami-b21ff8db 3.57 +INSTANCE_AMI=ami-7cfd1a15 3.58 +VOLUME_NAME=vol-28d13141 3.59 +SSH_SECRET_KEY=~/.ec2/id_rsa-pstam-keypair 3.60 +SSH_KEYPAIR=pstam-keypair 3.61 +EC2_ZONE=%(ec2_zone)s 3.62 +DOMAIN=%(ec2_dns_domain)s 3.63 +SCRIPTS_PATH=%(path_scripts)s 3.64 +""" % { 3.65 + "network" : network, 3.66 + "instances_number" : len(set(ec2_node.values())), 3.67 + "path_scripts" : path_scripts, 3.68 + 3.69 + "ec2_dns_domain" : ec2_dns_domain, 3.70 + "ec2_zone" : ec2_zone, 3.71 + }) 3.72 f.write("start_emulators()\n{\n%s\n}\n"%make_start_emulators()) 3.73 f.close() 3.74 3.75 def start_network(net=network): 3.76 make_start_instances_config() 3.77 - #run_command("cd %s; env NETWORK=%s sh %s instances start" % (path_network, network, path_scrips+"/ec2-instances")) 3.78 + run_command("cd %s; env NETWORK=%s sh %s start" % (path_network, network, path_scripts+"/ec2-instances")) 3.79 3.80 def stop_network(net=network): 3.81 - run_command("cd %s; env NETWORK=%s sh instances stop" % (path_network, network)) 3.82 + run_command("cd %s; env NETWORK=%s sh %s stop" % (path_network, network, path_scripts+"/ec2-instances")) 3.83 3.84 ## Stop 3.85 3.86 @@ -223,7 +244,6 @@ 3.87 screenlist="\n".join(screens) 3.88 3.89 hardstatus='hardstatus string "%{rk}Xentaur%{bk}@%H %{gk}%c %{yk}%d.%m %{wk}%?%-Lw%?%{bw}%n*%f%t%?(%u)%?%{wk}%?%+Lw%?"' 3.90 - 3.91 f=open(screenrc, "w"); 3.92 f.write(""" 3.93 hardstatus on 3.94 @@ -578,7 +598,6 @@ 3.95 """ 3.96 return vbridges_table[domain][int_number] 3.97 3.98 - 3.99 def dump_start(bridge, filter=""): 3.100 if bridge in real_bridges: 3.101 print "Bridge %s is a real bridge" % (bridge) 3.102 @@ -595,148 +614,17 @@ 3.103 3.104 3.105 #----------------------------------------------------------------------- 3.106 -# CONFIGURATION TEMPLATES 3.107 - 3.108 - 3.109 -def configure_ip_addresses(doms=domains): 3.110 - 3.111 - cisco_set_ip_on_int=""" 3.112 -\n\n\n 3.113 -int fa%s/0 3.114 -duplex full 3.115 -no ip address 3.116 -ip address %s 255.255.255.0 3.117 -no shutdown 3.118 -exit 3.119 -""" 3.120 - 3.121 - quagga_set_ip_on_int=""" 3.122 -int eth%s 3.123 -no ip address 3.124 -ip address %s/24 3.125 -no shutdown 3.126 -exit 3.127 -""" 3.128 - 3.129 - linux_set_ip_on_int=""" 3.130 -ifconfig eth%s %s netmask 255.255.255.0 3.131 -""" 3.132 - 3.133 - for dom in doms: 3.134 - i=domains.index(dom)+1 3.135 - if domain_types[domains.index(dom)] == 'quagga': 3.136 - command = quagga_set_ip_on_int 3.137 - write_to(i,"\nconf t\n") 3.138 - j=0 3.139 - for br in vbridges_table[dom]: 3.140 - write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) 3.141 - j+=1 3.142 - write_to(i,"\nend\n") 3.143 - elif domain_types[domains.index(dom)] == 'linux': 3.144 - command = linux_set_ip_on_int 3.145 - j=0 3.146 - for br in vbridges_table[dom]: 3.147 - #write_to(i, command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)) ) 3.148 - print i, command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i)) 3.149 - j+=1 3.150 - else: 3.151 - command = cisco_set_ip_on_int 3.152 - write_to(i,"\nena\nconf t\n") 3.153 - j=0 3.154 - for br in vbridges_table[dom]: 3.155 - write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) 3.156 - j+=1 3.157 - write_to(i,"\nend\n") 3.158 - return 0 3.159 - 3.160 -def configure_no_ip_addresses(doms=domains): 3.161 - 3.162 - cisco_set_ip_on_int=""" 3.163 -\n\n\n 3.164 -int fa%s/0 3.165 -no ip address %s 255.255.255.0 3.166 -exit 3.167 -""" 3.168 - 3.169 - quagga_set_ip_on_int=""" 3.170 -int eth%s 3.171 -no ip address %s/24 3.172 -exit 3.173 -""" 3.174 - 3.175 - for dom in doms: 3.176 - i=domains.index(dom)+1 3.177 - if domain_types[domains.index(dom)] == 'quagga': 3.178 - command = quagga_set_ip_on_int 3.179 - write_to(i,"\nconf t\n") 3.180 - j=0 3.181 - for br in vbridges_table[dom]: 3.182 - write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) 3.183 - j+=1 3.184 - write_to(i,"\nend\n") 3.185 - else: 3.186 - command = cisco_set_ip_on_int 3.187 - write_to(i,"\nena\nconf t\n") 3.188 - j=0 3.189 - for br in vbridges_table[dom]: 3.190 - write_to(i,command % (j, "192.168.%s.%s"%(bridges.index(br)+1,i))) 3.191 - j+=1 3.192 - write_to(i,"\nend\n") 3.193 - return 0 3.194 - 3.195 -def configure_ospf(doms=domains): 3.196 - for dom in doms: 3.197 - if domain_types[domains.index(dom)] == 'quagga': 3.198 - write_to(dom,"\n\nconf t\nrouter ospf\nnetwork 192.168.0.0/16 area 0\nend\n") 3.199 - else: 3.200 - write_to(dom,"\n\nena\nconf t\nrouter ospf 1\nnetwork 192.168.0.0 0.0.255.255 area 0\nend\n") 3.201 - return 0 3.202 - 3.203 -def configure_hostname(doms=domains): 3.204 - for dom in doms: 3.205 - if domain_types[domains.index(dom)] == 'quagga': 3.206 - write_to(dom,"\n\nconf t\nhostname %s\nend\n" % dom) 3.207 - else: 3.208 - write_to(dom,"\n\nena\nconf t\nhostname %s\nend\n" % dom) 3.209 - return 0 3.210 - 3.211 -def configure_logging_synchronous(doms=domains): 3.212 - for dom in domains: 3.213 - if domain_types[domains.index(dom)] == 'quagga': 3.214 - 0 3.215 - else: 3.216 - write_to(dom,"\n\nena\nconf t\nline console 0\nlogging synchronous\nend\n") 3.217 - return 0 3.218 - 3.219 -def configure_exec_timeout_0(doms=domains): 3.220 - for dom in domains: 3.221 - if domain_types[domains.index(dom)] == 'quagga': 3.222 - 0 3.223 - else: 3.224 - write_to(dom,"\n\nena\nconf t\nline console 0\nexec-timeout 0\nend\n") 3.225 - return 0 3.226 - 3.227 -def configure_no_cdp_log_mismatch_duplex(doms=domains): 3.228 - for dom in filter_by_type(domains,'dynamips'): 3.229 - write_to(dom,"\n\nena\nconf t\nno cdp log mismatch duplex\nend\n") 3.230 - 3.231 -def configure_save(doms=domains): 3.232 - write_to(doms,"\nwr\n") 3.233 - 3.234 -def configure_root(doms=domains): 3.235 - write_to(doms,"root\n") 3.236 - 3.237 -#----------------------------------------------------------------------- 3.238 - 3.239 3.240 def add_domain(name,type): 3.241 domains.append(name) 3.242 domain_types.append(type) 3.243 3.244 -def brake_link(domain,bridge): 3.245 +def break_link(domain,bridge): 3.246 broken_links.append([domain,bridge]) 3.247 3.248 -wt_timeout=0.5 3.249 +#----------------------------------------------------------------------- 3.250 + 3.251 +wt_timeout=1 3.252 def write_to(screen,string,return_to_screen=""): 3.253 """ 3.254 write_to(screen,string): 3.255 @@ -754,7 +642,7 @@ 3.256 screen_numbers=[screen] 3.257 else: 3.258 screen_numbers=[domains.index(screen)+1] 3.259 - 3.260 + 3.261 for screen_number in screen_numbers: 3.262 run_command("screen -X select "+str(screen_number)) 3.263 time.sleep(wt_timeout) 3.264 @@ -766,7 +654,7 @@ 3.265 time.sleep(wt_timeout) 3.266 run_command("nohup screen -X paste p >& /dev/null") 3.267 time.sleep(wt_timeout) 3.268 - 3.269 + 3.270 if return_to_screen != "": 3.271 run_command("screen -X select %s" % (return_to_screen)) 3.272 time.sleep(wt_timeout) 3.273 @@ -781,33 +669,9 @@ 3.274 3.275 #----------------------------------------------------------------------- 3.276 3.277 -cisco_fa01_up=""" 3.278 -ena 3.279 -conf t 3.280 -int fa0/0 3.281 -duplex half 3.282 -no shutdown 3.283 -exit 3.284 -int fa1/0 3.285 -duplex half 3.286 -no shutdown 3.287 -exit 3.288 -exit 3.289 -exit 3.290 -""" 3.291 - 3.292 -cisco_set_ip_on_int=""" 3.293 -interface fa%s/0 3.294 -no ip address 3.295 -ip address %s 255.255.255.0 3.296 -exit 3.297 -""" 3.298 - 3.299 nodes=domains 3.300 - 3.301 create_objects() 3.302 3.303 - 3.304 if len(sys.argv) == 2: 3.305 if sys.argv[1] == 'start-all': 3.306 start_all()