xentaur

changeset 2:e34dd9ee49e5

Функция write_to для записи на консоль виртуальных систем
author igor
date Fri Jul 13 20:52:01 2007 +0300 (2007-07-13)
parents ab37f0ad70e5
children 2c6cfa822bd8
files xentaur.py
line diff
     1.1 --- a/xentaur.py	Fri Jul 13 16:57:33 2007 +0300
     1.2 +++ b/xentaur.py	Fri Jul 13 20:52:01 2007 +0300
     1.3 @@ -1,13 +1,16 @@
     1.4  #!/usr/bin/python
     1.5  
     1.6  
     1.7 -import sys
     1.8 +import sys,os,time
     1.9  import xenomips_vars
    1.10  xenomips_vars.N='1'
    1.11  sys.path.append('/etc/xen')
    1.12  from xenomipsN import vbridges_table, hidden_bridges, domains, broken_links, temporary_links, domain_types
    1.13  from IPython.Shell import IPShellEmbed
    1.14  
    1.15 +
    1.16 +screenrc=os.environ['HOME']+"/.screenrc_xentaur"
    1.17 +
    1.18  def create_bridges_script():
    1.19      unbound_bridges=bridges
    1.20      create_unbound_bridges="\n".join(map(lambda x: "brctl show | awk '{print $1}' | grep -q "+x+" || brctl addbr "+x, unbound_bridges))
    1.21 @@ -39,6 +42,10 @@
    1.22  
    1.23      print """
    1.24  cat <<SCREENRC > screenrc
    1.25 +hardstatus on
    1.26 +hardstatus alwayslastline
    1.27 +hardstatus string "%{gk}%c %{yk}%M%d %{wk}%?%-Lw%?%{bw}%n*%f%t%?(%u)%?%{wk}%?%+Lw%?"
    1.28 +
    1.29  screen -t console 0 bash
    1.30  %(screenlist)s
    1.31  SCREENRC
    1.32 @@ -53,7 +60,6 @@
    1.33      return node+" [label=\"  "+node+"\",shapefile=\"shapes/all/"+domain_type[node]+".png\",fontcolor=navy,fontsize=14]"
    1.34  
    1.35  def graph():
    1.36 -    
    1.37      nodelist=""
    1.38      bridgelist=""
    1.39      linklist=""
    1.40 @@ -157,9 +163,10 @@
    1.41          os.execvp(program, (program,) +  args)
    1.42      return os.wait()[0]
    1.43  
    1.44 -def run_command(line)
    1.45 -    cmds=line.split()
    1.46 -    run(cmds[0],cmds[1:])
    1.47 +def run_command(line):
    1.48 +    #cmds=line.split()
    1.49 +    #run(cmds[0],*cmds[1:])
    1.50 +    run("/bin/sh", "-c", line)
    1.51  
    1.52  def add_domain(name,type):
    1.53      domains.append(name)
    1.54 @@ -168,11 +175,21 @@
    1.55  def brake_link(domain,bridge):
    1.56      broken_links.append([domain,bridge])
    1.57  
    1.58 -def type_to(screen,string)
    1.59 +def write_to(screen,string):
    1.60 +    """
    1.61 +    write_to(screen,string):
    1.62 +
    1.63 +        Type *string* to the screen with the number *screen*
    1.64 +
    1.65 +    """
    1.66 +    screen_number=screen
    1.67 +    f=open('/tmp/xentaurbuf', 'w')
    1.68 +    f.write(string)
    1.69 +    f.close()
    1.70      run_command("screen -X readreg p /tmp/xentaurbuf")
    1.71 -    run_command("screen -X select 1 ")
    1.72 -    run_command("screen -X paste p ")
    1.73 -    run_command("sleep 1")
    1.74 +    run_command("screen -X select "+str(screen_number))
    1.75 +    run_command("nohup screen -X paste p >& /dev/null")
    1.76 +    time.sleep(0.05)
    1.77      run_command("screen -X select 0")
    1.78  
    1.79  #-----------------------------------------------------------------------