ia64/xen-unstable

view tools/python/xen/xend/server/SrvServer.py @ 19848:5839491bbf20

[IA64] replace MAX_VCPUS with d->max_vcpus where necessary.

don't use MAX_VCPUS, and use vcpu::max_vcpus.
The changeset of 2f9e1348aa98 introduced max_vcpus to allow more vcpus
per guest. This patch is ia64 counter part.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Mon Jun 29 11:26:05 2009 +0900 (2009-06-29)
parents 634fe9f86d62
children
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
16 # Copyright (C) 2006 XenSource Ltd.
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 import fcntl
44 import re
45 import time
46 import signal
47 from threading import Thread
49 from xen.web.httpserver import HttpServer, UnixHttpServer
51 from xen.xend import XendNode, XendOptions, XendAPI
52 from xen.xend.XendLogging import log
53 from xen.xend.XendClient import XEN_API_SOCKET
54 from xen.xend.XendDomain import instance as xenddomain
55 from xen.web.SrvDir import SrvDir
57 from SrvRoot import SrvRoot
58 from XMLRPCServer import XMLRPCServer
60 xoptions = XendOptions.instance()
63 class XendServers:
65 def __init__(self, root):
66 self.servers = []
67 self.root = root
68 self.running = False
69 self.cleaningUp = False
70 self.reloadingConfig = False
72 def add(self, server):
73 self.servers.append(server)
75 def cleanup(self, signum = 0, frame = None, reloading = False):
76 log.debug("SrvServer.cleanup()")
77 self.cleaningUp = True
78 for server in self.servers:
79 try:
80 server.shutdown()
81 except:
82 pass
84 # clean up domains for those that have on_xend_stop
85 if not reloading:
86 xenddomain().cleanup_domains()
88 self.running = False
91 def reloadConfig(self, signum = 0, frame = None):
92 log.debug("SrvServer.reloadConfig()")
93 self.reloadingConfig = True
94 self.cleanup(signum, frame, reloading = True)
96 def start(self, status):
97 # Running the network script will spawn another process, which takes
98 # the status fd with it unless we set FD_CLOEXEC. Failing to do this
99 # causes the read in SrvDaemon to hang even when we have written here.
100 if status:
101 fcntl.fcntl(status, fcntl.F_SETFD, fcntl.FD_CLOEXEC)
103 # Prepare to catch SIGTERM (received when 'xend stop' is executed)
104 # and call each server's cleanup if possible
105 signal.signal(signal.SIGTERM, self.cleanup)
106 signal.signal(signal.SIGHUP, self.reloadConfig)
108 while True:
109 threads = []
110 for server in self.servers:
111 if server.ready:
112 continue
114 thread = Thread(target=server.run,
115 name=server.__class__.__name__)
116 thread.setDaemon(True)
117 thread.start()
118 threads.append(thread)
120 # check for when all threads have initialized themselves and then
121 # close the status pipe
123 retryCount = 0
124 threads_left = True
125 while threads_left:
126 threads_left = False
128 for server in self.servers:
129 if not server.ready:
130 threads_left = True
131 break
133 if threads_left:
134 time.sleep(.5)
135 retryCount += 1
136 if retryCount > 60:
137 for server in self.servers:
138 if not server.ready:
139 log.error("Server " +
140 server.__class__.__name__ +
141 " did not initialise!")
142 break
144 if status:
145 status.write('0')
146 status.close()
147 status = None
149 # Reaching this point means we can auto start domains
150 try:
151 xenddomain().autostart_domains()
152 except Exception, e:
153 log.exception("Failed while autostarting domains")
155 # loop to keep main thread alive until it receives a SIGTERM
156 self.running = True
157 while self.running:
158 time.sleep(100000000)
160 if self.reloadingConfig:
161 log.info("Restarting all XML-RPC and Xen-API servers...")
162 self.cleaningUp = False
163 self.reloadingConfig = False
164 xoptions.set_config()
165 self.servers = []
166 _loadConfig(self, self.root, True)
167 else:
168 break
170 def _loadConfig(servers, root, reload):
171 if xoptions.get_xend_http_server():
172 servers.add(HttpServer(root,
173 xoptions.get_xend_address(),
174 xoptions.get_xend_port()))
175 if xoptions.get_xend_unix_server():
176 path = xoptions.get_xend_unix_path()
177 log.info('unix path=' + path)
178 servers.add(UnixHttpServer(root, path))
180 api_cfg = xoptions.get_xen_api_server()
181 if api_cfg:
182 try:
183 for server_cfg in api_cfg:
184 # Parse the xen-api-server config
186 ssl_key_file = None
187 ssl_cert_file = None
188 auth_method = XendAPI.AUTH_NONE
189 hosts_allowed = None
191 host_addr = server_cfg[0].split(':', 1)
192 if len(host_addr) == 1:
193 if host_addr[0].lower() == 'unix':
194 use_tcp = False
195 host = 'localhost'
196 port = 0
197 else:
198 use_tcp = True
199 host = ''
200 port = int(host_addr[0])
201 else:
202 use_tcp = True
203 host = str(host_addr[0])
204 port = int(host_addr[1])
206 if len(server_cfg) > 1:
207 if server_cfg[1] in [XendAPI.AUTH_PAM, XendAPI.AUTH_NONE]:
208 auth_method = server_cfg[1]
210 if len(server_cfg) > 2 and len(server_cfg[2]):
211 hosts_allowed = map(re.compile, server_cfg[2].split(' '))
213 if len(server_cfg) > 4:
214 # SSL key and cert file
215 ssl_key_file = server_cfg[3]
216 ssl_cert_file = server_cfg[4]
219 servers.add(XMLRPCServer(auth_method, True, use_tcp = use_tcp,
220 ssl_key_file = ssl_key_file,
221 ssl_cert_file = ssl_cert_file,
222 host = host, port = port,
223 path = XEN_API_SOCKET,
224 hosts_allowed = hosts_allowed))
226 except (ValueError, TypeError), exn:
227 log.exception('Xen API Server init failed')
228 log.error('Xen-API server configuration %s is invalid.', api_cfg)
230 if xoptions.get_xend_tcp_xmlrpc_server():
231 addr = xoptions.get_xend_tcp_xmlrpc_server_address()
232 port = xoptions.get_xend_tcp_xmlrpc_server_port()
233 ssl_key_file = xoptions.get_xend_tcp_xmlrpc_server_ssl_key_file()
234 ssl_cert_file = xoptions.get_xend_tcp_xmlrpc_server_ssl_cert_file()
236 if ssl_key_file and ssl_cert_file:
237 servers.add(XMLRPCServer(XendAPI.AUTH_PAM, False, use_tcp = True,
238 ssl_key_file = ssl_key_file,
239 ssl_cert_file = ssl_cert_file,
240 host = addr, port = port))
241 else:
242 servers.add(XMLRPCServer(XendAPI.AUTH_PAM, False, use_tcp = True,
243 host = addr, port = port))
245 if xoptions.get_xend_unix_xmlrpc_server():
246 servers.add(XMLRPCServer(XendAPI.AUTH_PAM, False))
249 def create():
250 root = SrvDir()
251 root.putChild('xend', SrvRoot())
252 servers = XendServers(root)
253 _loadConfig(servers, root, False)
254 return servers