xentaur

changeset 66:aaf034af3a35

Merge of Xgurulla into Xentaur code. Not completed yet!!!

Now Xentaur can work with Amazon EC2,
but only with. Local domains management
is switched off temporarily.
author Igor Chubin <igor@chub.in>
date Sat Jan 09 20:20:08 2010 +0200 (2010-01-09)
parents cf823d27b029
children 6c145935ece5
files files/ec2-instances files/node-terminal-session files/prepare-ec2-instance xendomain.py xentaur.py
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/files/ec2-instances	Sat Jan 09 20:20:08 2010 +0200
     1.3 @@ -0,0 +1,183 @@
     1.4 +#!/bin/sh
     1.5 +
     1.6 +DOMAIN=ec2.xgu.ru
     1.7 +NETWORK=net1
     1.8 +INSTANCES_NUMBER=2
     1.9 +INSTANCE_AMI=ami-b21ff8db
    1.10 +INSTANCE_AMI=ami-7cfd1a15
    1.11 +SSH_SECRET_KEY=~/.ec2/id_rsa-pstam-keypair
    1.12 +SSH_KEYPAIR=pstam-keypair
    1.13 +VOLUME_NAME=vol-28d13141
    1.14 +EC2_ZONE=us-east-1a
    1.15 +DOMAIN=ec2.xgu.ru
    1.16 +SCRIPTS_PATH=~/hg/xentaur/files
    1.17 +
    1.18 +XGURULLA_DIR=~/.xgurulla/
    1.19 +WORK_DIR=${XGURULLA_DIR}/${NETWORK}
    1.20 +mkdir -p ${WORK_DIR}
    1.21 +
    1.22 +set -e -x
    1.23 +source ./start-instances-$NETWORK
    1.24 +# start_emulators is here
    1.25 +
    1.26 +message()
    1.27 +{
    1.28 +    printf "\033[1;33m[`date +"%T.%N"|cut -c1-12`] $*\033[0;39m\n"
    1.29 +}
    1.30 +
    1.31 +start_instances()
    1.32 +{
    1.33 +    message "* Starting instances"
    1.34 +    > $NETWORK-instances
    1.35 +    for i in `seq 0 $((INSTANCES_NUMBER-1))`
    1.36 +    do
    1.37 +          > /tmp/$NETWORK-ec2-run-instances
    1.38 +          ec2-run-instances $INSTANCE_AMI -z $EC2_ZONE -k $SSH_KEYPAIR > /tmp/$NETWORK-ec2-run-instances
    1.39 +          cat /tmp/$NETWORK-ec2-run-instances | grep INSTANCE | awk '{print $2}' >> $NETWORK-instances
    1.40 +          message Instance `tail -1 $NETWORK-instances` started
    1.41 +    done
    1.42 +    message "* All $INSTANCES_NUMBER instances started"
    1.43 +    cat $NETWORK-instances
    1.44 +}
    1.45 +
    1.46 +wait_for_loading()
    1.47 +{
    1.48 +    message "* Waiting for the instances finish loading"
    1.49 +    > $NETWORK-instances-ready
    1.50 +    exit=no
    1.51 +    while [ "$exit" != yes ] 
    1.52 +    do
    1.53 +           ec2-describe-instances | grep INSTANCE | egrep "`cat $NETWORK-instances|tr '\n' '|'`"NNNN | grep -q pending || exit=yes
    1.54 +           ec2-describe-instances | grep INSTANCE | egrep "`cat $NETWORK-instances|tr '\n' '|'`"NNNN | grep -v pending \
    1.55 +           | egrep -v "`cat $NETWORK-instances-ready|tr '\n' '|'`"XXXX | awk '{print $2}'> /tmp/$NETWORK-instances-new
    1.56 +	   if [ -s "/tmp/$NETWORK-instances-new" ]
    1.57 +           then 
    1.58 +              cat /tmp/$NETWORK-instances-new >> $NETWORK-instances-ready
    1.59 +              echo -n " "`cat /tmp/$NETWORK-instances-new`
    1.60 +              rm /tmp/$NETWORK-instances-new
    1.61 +           else 
    1.62 +              echo -n .
    1.63 +	   fi
    1.64 +           sleep 5
    1.65 +    done
    1.66 +    echo
    1.67 +    message "* Loading finished"
    1.68 +}
    1.69 +
    1.70 +update_dns()
    1.71 +{
    1.72 +    message "* Updating DNS records"
    1.73 +    i=0
    1.74 +    cat $NETWORK-instances | while read instance
    1.75 +    do
    1.76 +        echo $NETWORK-node$i A $(host $(ec2-describe-instances $instance | grep INS | awk '{print $4}') | awk '{print $3}')
    1.77 +        i=$((i+1))
    1.78 +    done > /tmp/zone-$NETWORK
    1.79 +    message "New records:"
    1.80 +    cat /tmp/zone-$NETWORK
    1.81 +    cat /tmp/zone-$NETWORK | awk '{print $1}' > $NETWORK-hostnames
    1.82 +
    1.83 +#FIXME: The file should be not overwritten, but merged!
    1.84 +    sudo mv /tmp/zone-$NETWORK /etc/bind/ec2-include 
    1.85 +    sudo rndc reload
    1.86 +    message "* Updating DNS records finished"
    1.87 +}
    1.88 +
    1.89 +clear_old_ssh_keys()
    1.90 +{
    1.91 +#FIXME!
    1.92 +#    rm ~/.ssh/known_hosts
    1.93 +    for i in `seq 0 $((INSTANCES_NUMBER-1))`
    1.94 +    do
    1.95 +        ssh-keygen -R $NETWORK-node$i.$DOMAIN
    1.96 +        ssh-keygen -R $NETWORK-node$i
    1.97 +    done
    1.98 +}
    1.99 +
   1.100 +ssh_keys()
   1.101 +{
   1.102 +    message "* Doing SSH keyscan"
   1.103 +    for i in `seq 0 $((INSTANCES_NUMBER-1))`
   1.104 +    do
   1.105 +        ssh-keyscan $NETWORK-node$i.$DOMAIN
   1.106 +        ssh-keyscan $NETWORK-node$i
   1.107 +    done > ssh-keys-$NETWORK
   1.108 +    clear_old_ssh_keys
   1.109 +    cat ssh-keys-$NETWORK >> ~/.ssh/known_hosts
   1.110 +    grep ^# ssh-keys-$NETWORK || true
   1.111 +    message "* SSH keyscan finished"
   1.112 +}
   1.113 +
   1.114 +attach_block_device()
   1.115 +{
   1.116 +    ec2-attach-volume -d /dev/sdb -i `head -1 $NETWORK-instances` $VOLUME_NAME 
   1.117 +}
   1.118 +
   1.119 +configure_instances()
   1.120 +{
   1.121 +#FIXME: Only for managed hosts! Not for all!
   1.122 +    cat <<EOF > ~/.ssh/config
   1.123 +Host *.$DOMAIN
   1.124 +	User root
   1.125 +	IdentityFile $SSH_SECRET_KEY
   1.126 +EOF
   1.127 +    > $NETWORK-preparation.log
   1.128 +    message "* Preparing network. Detailed log messages are in $NETWORK-preparation.log"
   1.129 +    for i in `seq 0 $((INSTANCES_NUMBER-1))`
   1.130 +    do
   1.131 +        host=$NETWORK-node$i.$DOMAIN
   1.132 +	message "* Preparing $host"
   1.133 +	message "** Copying configuration files"
   1.134 +        ssh $host 'mkdir /etc/xgurulla' >> $NETWORK-preparation.log 2>&1
   1.135 +        scp ssh-keys-$NETWORK $host:~/.ssh/known_hosts >> $NETWORK-preparation.log 2>&1
   1.136 +        scp $SSH_SECRET_KEY $host:~/.ssh/id_dsa >> $NETWORK-preparation.log 2>&1
   1.137 +        cat <<EOF | ssh $host 'cat > /etc/xgurulla/config'
   1.138 +NETWORK=$NETWORK
   1.139 +N=$i
   1.140 +SERVER=$NETWORK-node0.$DOMAIN
   1.141 +HOSTNAME=$host
   1.142 +EOF
   1.143 +        scp $SCRIPTS_PATH/prepare-ec2-instance $host:/etc/xgurulla/ >> $NETWORK-preparation.log 2>&1
   1.144 +	message "** Installing software"
   1.145 +        ssh $host sh /etc/xgurulla/prepare-ec2-instance >> $NETWORK-preparation.log 2>&1
   1.146 +    done
   1.147 +}
   1.148 +
   1.149 +start_all() {
   1.150 +start_instances
   1.151 +wait_for_loading
   1.152 +update_dns
   1.153 +ssh_keys
   1.154 +attach_block_device
   1.155 +configure_instances
   1.156 +message "* Starting emulators"
   1.157 +start_emulators
   1.158 +message "* Networking building completed"
   1.159 +}
   1.160 +
   1.161 +stop_instances()
   1.162 +{
   1.163 +[ -s "$NETWORK-instances" ] && ec2-terminate-instances `cat $NETWORK-instances`
   1.164 +ec2-describe-instances
   1.165 +}
   1.166 +
   1.167 +
   1.168 +stop_all()
   1.169 +{
   1.170 +    stop_instances
   1.171 +}
   1.172 +
   1.173 +if [ "$1" = start ]
   1.174 +then
   1.175 +    start_all
   1.176 +elif [ "$1" = stop ]
   1.177 +then
   1.178 +    stop_all
   1.179 +else
   1.180 +    cat <<USAGE
   1.181 +Usage:
   1.182 +
   1.183 +    $0 start | stop
   1.184 +
   1.185 +USAGE
   1.186 +fi
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/files/node-terminal-session	Sat Jan 09 20:20:08 2010 +0200
     2.3 @@ -0,0 +1,58 @@
     2.4 +EC2_INSTANCE=$1
     2.5 +EC2_NODE=$2
     2.6 +SHORT_NAME=$3
     2.7 +NETWORK_NAME=$4
     2.8 +SESSION_NAME=$5
     2.9 +   
    2.10 +NODE_PING_OK=WAIT
    2.11 +NODE_SSH_OK=WAIT
    2.12 +NODE_STATUS=UNKNOWN
    2.13 +
    2.14 +show_logo()
    2.15 +{
    2.16 +cat <<'EOF'
    2.17 +                     ___
    2.18 +                   /     \
    2.19 +                          |
    2.20 +     ---     ----         |    \    /   .----  |     |     | .---. |     |
    2.21 +   /     \ |             /      \  /   |     | |     |     |/      |     |
    2.22 +  |------- |           /         ><    |     | |     |     |       |     |
    2.23 +  |        |         /          /  \   |     | |     |     |       |     |
    2.24 +   \_____   \____  _______  O  /    \   \____|  \____|  O  |        \____|
    2.25 +                                             |
    2.26 +                                             |
    2.27 +                                         ----'
    2.28 +
    2.29 +EOF
    2.30 +}
    2.31 +
    2.32 +show_status()
    2.33 +{
    2.34 +cat <<EOF
    2.35 +
    2.36 +   EC2-instance:  $EC2_INSTANCE
    2.37 +   EC2-node name: $EC2_NODE
    2.38 +   Shortname:     $SHORT_NAME
    2.39 +   Network name:  $NETWORK_NAME
    2.40 +   Network map:   http://ec2.xgu.ru/network/$NETWORK_NAME
    2.41 +   
    2.42 +   Node connection status
    2.43 +   ----------------------
    2.44 +   ping:          $NODE_PING_OK
    2.45 +   ssh:           $NODE_SSH_OK
    2.46 +   Node status:   $NODE_STATUS
    2.47 +EOF
    2.48 +}
    2.49 +
    2.50 +
    2.51 +clear
    2.52 +show_logo
    2.53 +show_status
    2.54 +while true
    2.55 +do
    2.56 +    ssh -t $SHORT_NAME screen -r ${SESSION_NAME}-
    2.57 +    clear
    2.58 +    show_logo
    2.59 +    show_status
    2.60 +    sleep 5
    2.61 +done
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/files/prepare-ec2-instance	Sat Jan 09 20:20:08 2010 +0200
     3.3 @@ -0,0 +1,139 @@
     3.4 +
     3.5 +# usage: 
     3.6 +# loads /etc/xgurulla/config
     3.7 +#
     3.8 +# N the number of the instance
     3.9 +# NETWORK_NAME
    3.10 +# SERVER_NAME
    3.11 +
    3.12 +MAX_INSTANCES=10
    3.13 +FIRST_VLAN=100
    3.14 +LAST_VLAN=200
    3.15 +
    3.16 +. /etc/xgurulla/config
    3.17 +
    3.18 +common_setup()
    3.19 +{
    3.20 +	echo $HOSTNAME > /etc/hostname
    3.21 +	echo 127.0.0.1 $HOSTNAME ${HOSTNAME%%.*} > /etc/hosts
    3.22 +	hostname $HOSTNAME
    3.23 +	touch /root/.hushlogin
    3.24 +	export DEBIAN_FRONTEND=noninteractive
    3.25 +	pkill apt-get ; pkill dpkg ; sleep 5; pkill apt-get; pkill dpkg ; sleep 5
    3.26 +	dpkg --configure -a
    3.27 +     	apt-get -q -y update
    3.28 +        apt-get -q -y install dynamips openvpn bridge-utils rsync vlan unzip screen &
    3.29 +	while ps waux | grep -q apt-get
    3.30 +	do
    3.31 +		sleep 5
    3.32 +		if ps aux | grep -v grep | grep -q dpkg.*defunct
    3.33 +		then
    3.34 +	pkill apt-get ; pkill dpkg ; sleep 5; pkill apt-get; pkill dpkg ; sleep 5
    3.35 +			dpkg --configure -a
    3.36 +    			apt-get -q -y install dynamips openvpn bridge-utils rsync vlan unzip screen &
    3.37 +		fi
    3.38 +	done
    3.39 +}
    3.40 +
    3.41 +server_bridges_setup()
    3.42 +{
    3.43 +    brctl addbr br0
    3.44 +    ip link set br0 up
    3.45 +    ifconfig br0 promisc
    3.46 +    for i in `seq 0 $MAX_INSTANCES`
    3.47 +    do
    3.48 +        brctl addif br0 tap$i
    3.49 +        ip link set tap$i up
    3.50 +    done
    3.51 +}
    3.52 +
    3.53 +vlans_setup()
    3.54 +{
    3.55 +    interface=$1
    3.56 +    ip link set $interface up
    3.57 +    vconfig set_name_type VLAN_PLUS_VID_NO_PAD
    3.58 +    for i in `seq $FIRST_VLAN $LAST_VLAN`
    3.59 +    do
    3.60 +        vconfig add $interface $i
    3.61 +	ip link set vlan$i up
    3.62 +        brctl addbr br$i 
    3.63 +        ip link set br$i up
    3.64 +        ifconfig br$i promisc
    3.65 +	brctl addif br$i vlan$i
    3.66 +    done
    3.67 +}
    3.68 +
    3.69 +server_setup()
    3.70 +{
    3.71 +    cd /etc/openvpn
    3.72 +    openvpn --genkey --secret static.key
    3.73 +    for i in `seq 0 $MAX_INSTANCES`
    3.74 +    do
    3.75 +    cat <<EOF > server$i.conf
    3.76 +port $((22000+i))
    3.77 +secret static.key
    3.78 +dev tap$i
    3.79 +EOF
    3.80 +    done
    3.81 +    /etc/init.d/openvpn restart
    3.82 +}
    3.83 +
    3.84 +client_setup()
    3.85 +{
    3.86 +    cd /etc/openvpn
    3.87 +    scp $SERVER:/etc/openvpn/static.key .
    3.88 +    cat <<EOF > client.conf
    3.89 +port $((22000+N))
    3.90 +secret static.key
    3.91 +remote $SERVER
    3.92 +dev tap0
    3.93 +EOF
    3.94 +    /etc/init.d/openvpn restart
    3.95 +}
    3.96 +
    3.97 +copy_files_to_server()
    3.98 +{
    3.99 +    mkdir /mnt2
   3.100 +    mount /dev/sdb1 /mnt2
   3.101 +    rsync -a /mnt2/ /mnt/
   3.102 +    umount /mnt2
   3.103 +    rmdir /mnt2
   3.104 +    
   3.105 +    #mkdir /mnt/ios
   3.106 +    #cd /mnt/ios
   3.107 +    #wget http://igor.chub.in/tmp/ios
   3.108 +    #unzip ios
   3.109 +}
   3.110 +
   3.111 +copy_files_from_server()
   3.112 +{
   3.113 +    rsync -a $SERVER:/mnt/ /mnt/
   3.114 +}
   3.115 +
   3.116 +if [ "$1" = vlans_setup ]
   3.117 +then
   3.118 +   [ "$N" = 0 ]  && vlans_setup br0 || vlan_setup tap0
   3.119 +   exit 0
   3.120 +fi
   3.121 +
   3.122 +if [ "$1" = server_bridges_setup ]
   3.123 +then
   3.124 +   [ "$N" = 0 ]  && server_bridges_setup
   3.125 +   exit 0
   3.126 +fi
   3.127 +
   3.128 +
   3.129 +if [ "$N" = 0 ] 
   3.130 +then
   3.131 +    common_setup
   3.132 +    server_setup
   3.133 +    server_bridges_setup
   3.134 +    vlans_setup br0
   3.135 +    copy_files_to_server
   3.136 +else
   3.137 +    common_setup
   3.138 +    client_setup
   3.139 +    vlans_setup tap0
   3.140 +    copy_files_from_server
   3.141 +fi
   3.142 +
     4.1 --- a/xendomain.py	Mon Oct 12 00:12:11 2009 +0300
     4.2 +++ b/xendomain.py	Sat Jan 09 20:20:08 2010 +0200
     4.3 @@ -45,7 +45,8 @@
     4.4  real_nodes=[]
     4.5  connection_table={}
     4.6  
     4.7 -exec 'from %s import *' % (network)
     4.8 +#exec 'from %s import *' % (network)
     4.9 +from network import *
    4.10  
    4.11  # overriden by network config
    4.12  ############################
     5.1 --- a/xentaur.py	Mon Oct 12 00:12:11 2009 +0300
     5.2 +++ b/xentaur.py	Sat Jan 09 20:20:08 2010 +0200
     5.3 @@ -2,32 +2,34 @@
     5.4  # vim: set fileencoding=utf-8 :
     5.5  
     5.6  import sys,os,time
     5.7 +from IPython.Shell import IPShellEmbed
     5.8  
     5.9 -xentaur_path="/xentaur/xentaur"
    5.10 +path_xentaur="%s/hg/xentaur" % os.environ['HOME']
    5.11 +path_shapes=path_xentaur+'/shapes'
    5.12 +path_scripts=path_xentaur+'/files'
    5.13 +
    5.14 +network='net1'
    5.15 +
    5.16 +path_network=os.environ['HOME']+"/.xentaur/"+network
    5.17 +if not os.path.exists(path_network):
    5.18 +    os.makedirs(path_network)
    5.19 +screenrc=path_network+"/.screenrc_xentaur"
    5.20  
    5.21  sys.path.append('/etc/xen')
    5.22 -sys.path.append(xentaur_path)
    5.23 +sys.path.append(path_xentaur)
    5.24 +sys.path.append(path_network)
    5.25  sys.path.append('.')
    5.26  
    5.27  node_object={}
    5.28  link_object={}
    5.29  bridge_object={}
    5.30 +ec2_node={}
    5.31  
    5.32 -network='multicast'
    5.33  domain='dyn1'
    5.34 -
    5.35 -#network='snrs'
    5.36 -#domain='dyn1'
    5.37  from xendomain import *
    5.38  
    5.39  bridges_turned_down=[]
    5.40  
    5.41 -from IPython.Shell import IPShellEmbed
    5.42 -
    5.43 -
    5.44 -screenrc=".screenrc_xentaur_"+network
    5.45 -path_shapes='/xentaur/xentaur/shapes'
    5.46 -
    5.47  def run(program, *args):
    5.48      pid = os.fork()
    5.49      if not pid:
    5.50 @@ -63,7 +65,7 @@
    5.51  """ % (script)
    5.52  
    5.53  def start_domain(domain):
    5.54 -    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"
    5.55 +    print "sudo xm create "+path_xentaur+"/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"
    5.56  
    5.57  def start_domains(doms=domains):
    5.58      for domain in doms:
    5.59 @@ -73,9 +75,56 @@
    5.60  def start_all():
    5.61      graph()
    5.62      screen()
    5.63 +    html()
    5.64      start_bridges()
    5.65      start_domains()
    5.66  
    5.67 +def ec2_assign_nodes_to_instances():
    5.68 +    domain_number=0
    5.69 +    for dom in domains:
    5.70 +        node_name=network+"-node%s"%(domain_number/2)
    5.71 +        ec2_node[dom]=node_name
    5.72 +        domain_number+=1
    5.73 +
    5.74 +def make_start_emulators():
    5.75 +    s=""
    5.76 +    #s+="cat screenrc_template > screenrc_$NETWORK\n"
    5.77 +    #s+="echo \"screen -t console 0 sh -c 'cd ~/xentaur; ./xentaur.py shell'\" >> screenrc_$NETWORK\n"
    5.78 +    ios="/mnt/ios/C7200-AD.BIN"
    5.79 +    ec2_assign_nodes_to_instances()
    5.80 +    for dom in domains:
    5.81 +        node_name=ec2_node[dom]
    5.82 +        i=0
    5.83 +        line='dynamips '+ios
    5.84 +        line2=''
    5.85 +        for iface in vbridges_table[dom]:
    5.86 +            bridge=vbridges_table[dom][i]
    5.87 +            if i>0:
    5.88 +                line += " -p %s:PA-FE-TX "%i
    5.89 +            line += " -s %s:0:tap:%s_%s "% (i,dom,iface)
    5.90 +            line2 += "sleep 2; brctl addif %s %s; "%(bridge, dom+"_"+iface)
    5.91 +            line2 +='ifconfig %s up; ifconfig %s promisc ;' %(bridge, bridge)
    5.92 +            line2 += "ifconfig %s_%s up; "%(dom, iface)
    5.93 +            i+=1
    5.94 +        s += "ssh %s \"mkdir -p /mnt/%s; cd /mnt/%s; screen -S %s- -d -m %s\"\n"%(node_name,dom,dom,dom,line)
    5.95 +        s += "ssh %s \"%s\"\n" % (node_name, line2)
    5.96 +        #s += "echo \"screen %s ssh -t %s 'screen -r %s-'\" >> screenrc_%s\n" % (domain_number, node_name, dom, network)
    5.97 +        #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)
    5.98 +    return s
    5.99 +
   5.100 +def make_start_instances_config(net=network):
   5.101 +    f = open(path_network+"/start-instances-"+network, "w");
   5.102 +    f.write("INSTANCES_NUMBER=%s\n"%((len(domains)+1)/2))
   5.103 +    f.write("start_emulators()\n{\n%s\n}\n"%make_start_emulators())
   5.104 +    f.close()
   5.105 +
   5.106 +def start_network(net=network):
   5.107 +    make_start_instances_config()
   5.108 +    #run_command("cd %s; env NETWORK=%s sh %s instances start" % (path_network, network, path_scrips+"/ec2-instances"))
   5.109 +
   5.110 +def stop_network(net=network):
   5.111 +    run_command("cd %s; env NETWORK=%s sh instances stop" % (path_network, network))
   5.112 +
   5.113  ## Stop
   5.114  
   5.115  def stop_domain(domain,wait=0):
   5.116 @@ -165,8 +214,12 @@
   5.117      wait_seconds=1
   5.118      screens=[]
   5.119      for domain in domains:
   5.120 -        screens.append("screen -t %s %s sh -c 'while true; do %s ; echo Retrying in %s secods...; sleep %s ; clear; done'" %
   5.121 -                                 (domain,domains.index(domain)+1,node_object[domain].console_string(),wait_seconds,wait_seconds))
   5.122 +        screens.append("screen -t %(domain)s %(domain_number)s %(console_string)s" % {
   5.123 +            'domain' : domain,
   5.124 +            'domain_number' : domains.index(domain)+1,
   5.125 +            'console_string': node_object[domain].console_string(), 
   5.126 +            'wait_interval' : wait_seconds } )
   5.127 +
   5.128      screenlist="\n".join(screens)
   5.129  
   5.130      hardstatus='hardstatus string "%{rk}Xentaur%{bk}@%H %{gk}%c %{yk}%d.%m %{wk}%?%-Lw%?%{bw}%n*%f%t%?(%u)%?%{wk}%?%+Lw%?"'
   5.131 @@ -179,7 +232,7 @@
   5.132  
   5.133  screen -t console 0 sh -c 'while true; do %s/xentaur.py shell ; echo Retrying in %s secods...; sleep %s ; clear; done'
   5.134  %s
   5.135 -""" % (hardstatus,xentaur_path,wait_seconds,wait_seconds,screenlist))
   5.136 +""" % (hardstatus,path_xentaur,wait_seconds,wait_seconds,screenlist))
   5.137      f.close()
   5.138      print "# GNU Screen config file is written to: %s" % screenrc
   5.139  
   5.140 @@ -197,7 +250,7 @@
   5.141      linklist=";\n    ".join(map(lambda link: link_object[link].graphviz_string(),link_object.keys()))
   5.142      if linklist: linklist += ";"
   5.143  
   5.144 -    f = open(network+".dot", "w");
   5.145 +    f = open(path_network+"/"+network+".dot", "w");
   5.146      f.write ("""
   5.147  graph G {
   5.148      edge [len=1.25];
   5.149 @@ -222,18 +275,40 @@
   5.150  };
   5.151  """ % (nodelist, bridgelist, physicallist, networklist, linklist))
   5.152      f.close()
   5.153 -    run_command("neato -Tpng -o %s.png %s.dot "%(network,network))
   5.154 -    run_command("neato -Tjpg -o %s.jpg %s.dot "%(network,network))
   5.155 -    run_command("neato -Tsvg -o %s.svg %s.dot "%(network,network))
   5.156 -    run_command("neato -Tcmapx -o %s.cmapx -NURL=http://google.com %s.dot "%(network,network))
   5.157 -    print "# Network map is written to files: %s.{png,svg,jpg,dot}" % network
   5.158 +    run_command("neato -Tpng -o %s.png %s.dot "%(path_network+"/"+network,path_network+"/"+network))
   5.159 +    run_command("neato -Tjpg -o %s.jpg %s.dot "%(path_network+"/"+network,path_network+"/"+network))
   5.160 +    run_command("neato -Tsvg -o %s.svg %s.dot "%(path_network+"/"+network,path_network+"/"+network))
   5.161 +    #run_command("neato -Tcmapx -o %s.cmapx -NURL=http://google.com %s.dot "%(path_network+"/"+network,path_network+"/"+network))
   5.162 +    print "# Network map is written to files: %s.{png,svg,jpg,dot}" % (path_network+"/"+network)
   5.163 +
   5.164 +def html():
   5.165 +    f = open(path_network+"/index.html", "w");
   5.166 +    f.write ("""
   5.167 +<html>
   5.168 +<head>
   5.169 +<title>Network %s map</network>
   5.170 +<body>
   5.171 +<img src="%s.png" /><br/>
   5.172 +<pre>
   5.173 +nodes=%s
   5.174 +bridges=%s
   5.175 +vbridges_table=%s
   5.176 +</pre>
   5.177 +</body>
   5.178 +</head>
   5.179 +</html>
   5.180 +""" % (network, network, domains, bridges, vbridges_table))
   5.181 +    f.close()
   5.182 +    #run_command("cp %s.html /var/www/ec2/network/%s/index.html"%(network,network))
   5.183  
   5.184  def autoredraw():
   5.185      graph()
   5.186 +    html()
   5.187 +    screen()
   5.188  
   5.189  def shell():
   5.190      autoredraw()
   5.191 -    ipshell = IPShellEmbed()
   5.192 +    ipshell = IPShellEmbed(['-noconfirm_exit'])
   5.193      ipshell()
   5.194  
   5.195  def version():
   5.196 @@ -247,21 +322,6 @@
   5.197    ' / \     |
   5.198  
   5.199      """
   5.200 -#    print "Xentaur 0.1-PRE"
   5.201 -#    print "(Godzilla-mutant)  _"
   5.202 -#    print "                 / * \\"
   5.203 -#    print "                /   .-"
   5.204 -#    print "               /   |"
   5.205 -#    print "              | \\ \\\\ \\"
   5.206 -#    print "     _ -------|  \\ \\\\ \\"
   5.207 -#    print " / /              \\_\\ -"
   5.208 -#    print "/ |\\           |   |"
   5.209 -#    print "| |  \\ .-----. | \\ |"
   5.210 -#    print "  |  /        \\ \\ \\ \\"
   5.211 -#    print "  \\/|.\\        \\ \\ \\ \\"
   5.212 -#    print "   \\| - .       \\_\\ \\_\\"
   5.213 -#    print "-----------------------------------------------"
   5.214 -
   5.215  
   5.216  def info():
   5.217      version()
   5.218 @@ -364,6 +424,11 @@
   5.219          return self.name+" [color=white,shape=plaintext,label=\"  "+self.name+"\",shapefile=\""+path_shapes+"/all/"+\
   5.220          domain_types[domains.index(self.name)]+".png\",fontcolor=black,fontsize=16,target=\"http://google.com\"]"
   5.221      def console_string(self):
   5.222 +        ec2=True # FIXME
   5.223 +        ec2_assign_nodes_to_instances()
   5.224 +        if ec2:
   5.225 +            return path_scripts+"/node-terminal-session INSTANCE EC2_NODE %s %s %s"%(ec2_node[self.name], network, self.name)
   5.226 +        
   5.227          if self.type in [ 'quagga', 'dynamips', 'freebsd', 'linux' ]:
   5.228              return "sudo xm console "+self.name
   5.229          elif self.name in real_bridges or self.name in real_nodes:
   5.230 @@ -396,7 +461,7 @@
   5.231              return self.node+" -- "+self.bridge+" [taillabel=\"fa"+str(self.interface)+"/0\",style=dashed]"
   5.232  
   5.233          ip="\\n.%s.%s" % (bridges.index(self.bridge)+1, domains.index(self.node)+1) 
   5.234 -        if domain_types[domains.index(self.node)] == 'xenomips':
   5.235 +        if domain_types[domains.index(self.node)] == 'dynamips':
   5.236              int_name="fa"+str(self.interface)+"/0"
   5.237          else:
   5.238              int_name="eth"+str(self.interface)
   5.239 @@ -538,6 +603,7 @@
   5.240      cisco_set_ip_on_int="""
   5.241  \n\n\n
   5.242  int fa%s/0
   5.243 +duplex full
   5.244  no ip address
   5.245  ip address %s 255.255.255.0
   5.246  no shutdown
   5.247 @@ -651,7 +717,7 @@
   5.248      return 0
   5.249  
   5.250  def configure_no_cdp_log_mismatch_duplex(doms=domains):
   5.251 -    for dom in filter_by_type(domains,'xenomips'):
   5.252 +    for dom in filter_by_type(domains,'dynamips'):
   5.253          write_to(dom,"\n\nena\nconf t\nno cdp log mismatch duplex\nend\n")
   5.254  
   5.255  def configure_save(doms=domains):