ia64/xen-unstable

changeset 10487:95ac3f0f79bc

Add an xm serve command.

This command proxies the Xend XML-RPC over stdio. This is similiar to
mercurial's hg serve --stdio command.

The most obvious use of this command is remote XML-RPC invocation over SSH.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
author anthony@rhesis.austin.ibm.com
date Tue Jun 20 10:25:20 2006 +0100 (2006-06-20)
parents 0fe87421cc80
children c2cbcccc44f4
files tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Tue Jun 20 10:25:18 2006 +0100
     1.2 +++ b/tools/python/xen/xm/main.py	Tue Jun 20 10:25:20 2006 +0100
     1.3 @@ -41,6 +41,7 @@ import console
     1.4  import xen.xend.XendClient
     1.5  from xen.xend.XendClient import server
     1.6  from xen.util import security
     1.7 +from select import select
     1.8  
     1.9  # getopt.gnu_getopt is better, but only exists in Python 2.3+.  Use
    1.10  # getopt.getopt if gnu_getopt is not available.  This will mean that options
    1.11 @@ -124,6 +125,7 @@ dumppolicy_help = "dumppolicy           
    1.12  loadpolicy_help = "loadpolicy <policy>              Load binary policy into hypervisor"
    1.13  makepolicy_help = "makepolicy <policy>              Build policy and create .bin/.map files"
    1.14  labels_help     = "labels [policy] [type=DOM|..]    List <type> labels for (active) policy."
    1.15 +serve_help      = "serve                            Proxy Xend XML-RPC over stdio"
    1.16  
    1.17  short_command_list = [
    1.18      "console",
    1.19 @@ -171,7 +173,8 @@ domain_commands = [
    1.20  host_commands = [
    1.21      "dmesg",
    1.22      "info",
    1.23 -    "log"
    1.24 +    "log",
    1.25 +    "serve",
    1.26      ]
    1.27  
    1.28  scheduler_commands = [
    1.29 @@ -834,6 +837,32 @@ def xm_log(args):
    1.30      
    1.31      print server.xend.node.log()
    1.32  
    1.33 +def xm_serve(args):
    1.34 +    arg_check(args, "serve", 0)
    1.35 +
    1.36 +    from fcntl import fcntl, F_SETFL
    1.37 +    
    1.38 +    s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    1.39 +    s.connect(xen.xend.XendClient.XML_RPC_SOCKET)
    1.40 +    fcntl(sys.stdin, F_SETFL, os.O_NONBLOCK)
    1.41 +
    1.42 +    while True:
    1.43 +        iwtd, owtd, ewtd = select([sys.stdin, s], [], [])
    1.44 +        if s in iwtd:
    1.45 +            data = s.recv(4096)
    1.46 +            if len(data) > 0:
    1.47 +                sys.stdout.write(data)
    1.48 +                sys.stdout.flush()
    1.49 +            else:
    1.50 +                break
    1.51 +        if sys.stdin in iwtd:
    1.52 +            data = sys.stdin.read(4096)
    1.53 +            if len(data) > 0:
    1.54 +                s.sendall(data)
    1.55 +            else:
    1.56 +                break
    1.57 +    s.close()
    1.58 +
    1.59  def parse_dev_info(info):
    1.60      def get_info(n, t, d):
    1.61          i = 0
    1.62 @@ -1072,6 +1101,7 @@ commands = {
    1.63      "dmesg": xm_dmesg,
    1.64      "info": xm_info,
    1.65      "log": xm_log,
    1.66 +    "serve": xm_serve,
    1.67      # scheduler
    1.68      "sched-bvt": xm_sched_bvt,
    1.69      "sched-bvt-ctxallow": xm_sched_bvt_ctxallow,