ia64/xen-unstable

view tools/python/xen/xend/server/SrvServer.py @ 6552:a9873d384da4

Merge.
author adsharma@los-vmm.sc.intel.com
date Thu Aug 25 12:24:48 2005 -0700 (2005-08-25)
parents 112d44270733 fa0754a9f64f
children dfaf788ab18c
line source
1 #!/usr/bin/python
2 #============================================================================
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of version 2.1 of the GNU Lesser General Public
5 # License as published by the Free Software Foundation.
6 #
7 # This library is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 # Lesser General Public License for more details.
11 #
12 # You should have received a copy of the GNU Lesser General Public
13 # License along with this library; if not, write to the Free Software
14 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 #============================================================================
16 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
17 #============================================================================
19 """Example xend HTTP
21 Can be accessed from a browser or from a program.
22 Do 'python SrvServer.py' to run the server.
23 Then point a web browser at http://localhost:8000/xend and follow the links.
24 Most are stubs, except /domain which has a list of domains and a 'create domain'
25 button.
27 You can also access the server from a program.
28 Do 'python XendClient.py' to run a few test operations.
30 The data served differs depending on the client (as defined by User-Agent
31 and Accept in the HTTP headers). If the client is a browser, data
32 is returned in HTML, with interactive forms. If the client is a program,
33 data is returned in SXP format, with no forms.
35 The server serves to the world by default. To restrict it to the local host
36 change 'interface' in main().
38 Mike Wray <mike.wray@hp.com>
39 """
40 # todo Support security settings etc. in the config file.
41 # todo Support command-line args.
43 from threading import Thread
45 from xen.web.httpserver import HttpServer, UnixHttpServer
47 from xen.xend import XendRoot; xroot = XendRoot.instance()
48 from xen.xend import Vifctl
49 from xen.xend.XendLogging import log
50 from xen.web.SrvDir import SrvDir
52 from SrvRoot import SrvRoot
54 class XendServers:
56 def __init__(self):
57 self.servers = []
59 def add(self, server):
60 self.servers.append(server)
62 def start(self):
63 Vifctl.network('start')
64 for server in self.servers:
65 thread = Thread(target=server.run)
66 thread.start()
68 def create():
69 root = SrvDir()
70 root.putChild('xend', SrvRoot())
71 servers = XendServers()
72 if xroot.get_xend_http_server():
73 port = xroot.get_xend_port()
74 interface = xroot.get_xend_address()
75 servers.add(HttpServer(root=root, interface=interface, port=port))
76 if xroot.get_xend_unix_server():
77 path = xroot.get_xend_unix_path()
78 log.info('unix path=' + path)
79 servers.add(UnixHttpServer(path=path, root=root))
80 return servers