debuggers.hg

view tools/python/xen/xend/server/SrvServer.py @ 4655:a838a908e38e

bitkeeper revision 1.1327.2.2 (4267a9b3MhPpljnjQ5IbfLdzcW2K3w)

Remove twisted from the HTTP server and replace with a
threaded server. Add classes to provide tcp and unix servers
using threads instead of twisted. Remove use of twisted from
the consoles, event server and HTTP resources

Signed-off-by: Mike Wray <mike.wray@hp.com>
author mjw@wray-m-3.hpl.hp.com
date Thu Apr 21 13:25:07 2005 +0000 (2005-04-21)
parents 0a4b76b6b5a0
children 369e382b2f81
line source
1 #!/usr/bin/python
2 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
4 """Example xend HTTP and console server.
6 Can be accessed from a browser or from a program.
7 Do 'python SrvServer.py' to run the server.
8 Then point a web browser at http://localhost:8000/xend and follow the links.
9 Most are stubs, except /domain which has a list of domains and a 'create domain'
10 button.
12 You can also access the server from a program.
13 Do 'python XendClient.py' to run a few test operations.
15 The data served differs depending on the client (as defined by User-Agent
16 and Accept in the HTTP headers). If the client is a browser, data
17 is returned in HTML, with interactive forms. If the client is a program,
18 data is returned in SXP format, with no forms.
20 The server serves to the world by default. To restrict it to the local host
21 change 'interface' in main().
23 Mike Wray <mike.wray@hp.com>
24 """
25 # todo Support security settings etc. in the config file.
26 # todo Support command-line args.
28 from threading import Thread
30 from xen.web.httpserver import HttpServer
32 from xen.xend import XendRoot
33 xroot = XendRoot.instance()
34 from xen.xend import Vifctl
35 from SrvRoot import SrvRoot
36 from SrvDir import SrvDir
38 def create(port=None, interface=None, bridge=0):
39 if port is None:
40 port = xroot.get_xend_port()
41 if interface is None:
42 interface = xroot.get_xend_address()
43 if bridge:
44 Vifctl.network('start')
45 root = SrvDir()
46 root.putChild('xend', SrvRoot())
47 server = HttpServer(root=root, interface=interface, port=port)
48 thread = Thread(name="XendHttpServer", target=server.run)
49 return thread