ia64/xen-unstable

view tools/python/xen/xend/XendOptions.py @ 17712:91a9e28aed46

Make ssl relocation server listen on different port

This patch makes ssl relocation server listen on 8003 if enabled.

Whether to start ssl relocation server now controlled by
xend-relocation-ssl-server. So ssl and non-ssl relocation server can
run simultaneously. You can also only start ssl server or only start
non-ssl relocation server.

When mix deploy xen 3.2 server (has no ssl support) and 3.3 servers,
start ssl and non-ssl relocation server simultaneously can keep
backward compatibility.

It's also more reasonable to have separate ports for ssl and non-ssl.

In this patch, also renames xend-relocation-tls to xend-relocation-ssl.

Signed-off-by: Zhigang Wang <zhigang.x.wang@oracle.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri May 23 10:41:44 2008 +0100 (2008-05-23)
parents 1e169f4e8e72
children 51274688c000
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) 2005 XenSource Ltd
17 #============================================================================
19 """Xend root class.
20 Creates the servers and handles configuration.
22 Other classes get config variables by importing this module,
23 using instance() to get a XendOptions instance, and then
24 the config functions (e.g. get_xend_port()) to get
25 configured values.
26 """
28 import os
29 import os.path
30 import string
31 import sys
33 from xen.xend import sxp, osdep, XendLogging
34 from xen.xend.XendError import XendError
36 if os.uname()[0] == 'SunOS':
37 from xen.lowlevel import scf
39 class XendOptions:
40 """Configuration options."""
42 """Where network control scripts live."""
43 network_script_dir = osdep.scripts_dir
45 """Where block control scripts live."""
46 block_script_dir = osdep.scripts_dir
48 """Default path to the log file. """
49 logfile_default = "/var/log/xen/xend.log"
51 """Default level of information to be logged."""
52 loglevel_default = 'DEBUG'
54 """Default Xen-API server configuration. """
55 xen_api_server_default = [['unix']]
57 """Default for the flag indicating whether xend should run an http server
58 (deprecated)."""
59 xend_http_server_default = 'no'
61 xend_tcp_xmlrpc_server_default = 'no'
63 xend_tcp_xmlrpc_server_address_default = 'localhost'
65 xend_tcp_xmlrpc_server_port_default = 8006
67 xend_unix_xmlrpc_server_default = 'yes'
69 """Default interface address xend listens at. """
70 xend_address_default = ''
72 """Default for the flag indicating whether xend should run a relocation server."""
73 xend_relocation_server_default = 'no'
75 """Default for the flag indicating whether xend should run a ssl relocation server."""
76 xend_relocation_ssl_server_default = 'no'
78 """Default interface address the xend relocation server listens at. """
79 xend_relocation_address_default = ''
81 """Default port xend serves HTTP at. """
82 xend_port_default = 8000
84 """Default port xend serves relocation at. """
85 xend_relocation_port_default = 8002
87 """Default port xend serves ssl relocation at. """
88 xend_relocation_ssl_port_default = 8003
90 xend_relocation_hosts_allow_default = ''
92 """Default for the flag indicating whether xend should run a unix-domain
93 server (deprecated)."""
94 xend_unix_server_default = 'no'
96 """Default external migration tool """
97 external_migration_tool_default = ''
99 """Default path the unix-domain server listens at."""
100 xend_unix_path_default = '/var/lib/xend/xend-socket'
102 dom0_min_mem_default = 0
104 dom0_vcpus_default = 0
106 vncpasswd_default = None
108 """Default interface to listen for VNC connections on"""
109 xend_vnc_listen_default = '127.0.0.1'
111 """Use of TLS mode in QEMU VNC server"""
112 xend_vnc_tls = 0
114 """x509 certificate directory for QEMU VNC server"""
115 xend_vnc_x509_cert_dir = "/etc/xen/vnc"
117 """Verify incoming client x509 certs"""
118 xend_vnc_x509_verify = 0
120 """Default session storage path."""
121 xend_domains_path_default = '/var/lib/xend/domains'
123 """Default xend management state storage."""
124 xend_state_path_default = '/var/lib/xend/state'
126 """Default xend QCoW storage repository location."""
127 xend_storage_path_default = '/var/lib/xend/storage'
129 """Default xend security state storage path."""
130 xend_security_path_default = '/var/lib/xend/security'
132 """Default script to configure a backend network interface"""
133 vif_script = osdep.vif_script
135 def __init__(self):
136 self.configure()
138 def _logError(self, fmt, *args):
139 """Logging function to log to stderr. We use this for XendOptions log
140 messages because they may be logged before the logger has been
141 configured. Other components can safely use the logger.
142 """
143 print >>sys.stderr, "xend [ERROR]", fmt % args
146 def configure(self):
147 self.set_config()
148 XendLogging.init(self.get_config_string("logfile",
149 self.logfile_default),
150 self.get_config_string("loglevel",
151 self.loglevel_default))
153 def set_config(self):
154 raise NotImplementedError()
156 def get_config_bool(self, name, val=None):
157 raise NotImplementedError()
159 def get_config_int(self, name, val=None):
160 raise NotImplementedError()
162 def get_config_string(self, name, val=None):
163 raise NotImplementedError()
165 def get_xen_api_server(self):
166 raise NotImplementedError()
168 def get_xend_http_server(self):
169 """Get the flag indicating whether xend should run an http server.
170 """
171 return self.get_config_bool("xend-http-server", self.xend_http_server_default)
173 def get_xend_tcp_xmlrpc_server(self):
174 return self.get_config_bool("xend-tcp-xmlrpc-server",
175 self.xend_tcp_xmlrpc_server_default)
177 def get_xend_tcp_xmlrpc_server_port(self):
178 return self.get_config_int("xend-tcp-xmlrpc-server-port",
179 self.xend_tcp_xmlrpc_server_port_default)
181 def get_xend_tcp_xmlrpc_server_address(self):
182 return self.get_config_string("xend-tcp-xmlrpc-server-address",
183 self.xend_tcp_xmlrpc_server_address_default)
185 def get_xend_tcp_xmlrpc_server_ssl_key_file(self):
186 return self.get_config_string("xend-tcp-xmlrpc-server-ssl-key-file")
188 def get_xend_tcp_xmlrpc_server_ssl_cert_file(self):
189 return self.get_config_string("xend-tcp-xmlrpc-server-ssl-cert-file")
191 def get_xend_unix_xmlrpc_server(self):
192 return self.get_config_bool("xend-unix-xmlrpc-server",
193 self.xend_unix_xmlrpc_server_default)
195 def get_xend_relocation_server(self):
196 """Get the flag indicating whether xend should run a relocation server.
197 """
198 return self.get_config_bool("xend-relocation-server",
199 self.xend_relocation_server_default)
201 def get_xend_relocation_ssl_server(self):
202 """Get the flag indicating whether xend should run a ssl relocation server.
203 """
204 return self.get_config_bool("xend-relocation-ssl-server",
205 self.xend_relocation_ssl_server_default)
207 def get_xend_relocation_server_ssl_key_file(self):
208 return self.get_config_string("xend-relocation-server-ssl-key-file")
210 def get_xend_relocation_server_ssl_cert_file(self):
211 return self.get_config_string("xend-relocation-server-ssl-cert-file")
213 def get_xend_port(self):
214 """Get the port xend listens at for its HTTP interface.
215 """
216 return self.get_config_int('xend-port', self.xend_port_default)
218 def get_xend_relocation_port(self):
219 """Get the port xend listens at for connection to its relocation server.
220 """
221 return self.get_config_int('xend-relocation-port',
222 self.xend_relocation_port_default)
224 def get_xend_relocation_ssl_port(self):
225 """Get the port xend listens at for ssl connection to its relocation
226 server.
227 """
228 return self.get_config_int('xend-relocation-ssl-port',
229 self.xend_relocation_ssl_port_default)
231 def get_xend_relocation_ssl(self):
232 """Whether to use ssl when relocating.
233 """
234 return self.get_config_bool('xend-relocation-ssl', 'no')
236 def get_xend_relocation_hosts_allow(self):
237 return self.get_config_string("xend-relocation-hosts-allow",
238 self.xend_relocation_hosts_allow_default)
240 def get_xend_address(self):
241 """Get the address xend listens at for its HTTP port.
242 This defaults to the empty string which allows all hosts to connect.
243 If this is set to 'localhost' only the localhost will be able to connect
244 to the HTTP port.
245 """
246 return self.get_config_string('xend-address', self.xend_address_default)
248 def get_xend_relocation_address(self):
249 """Get the address xend listens at for its relocation server port.
250 This defaults to the empty string which allows all hosts to connect.
251 If this is set to 'localhost' only the localhost will be able to connect
252 to the relocation port.
253 """
254 return self.get_config_string('xend-relocation-address', self.xend_relocation_address_default)
256 def get_xend_unix_server(self):
257 """Get the flag indicating whether xend should run a unix-domain server.
258 """
259 return self.get_config_bool("xend-unix-server", self.xend_unix_server_default)
261 def get_xend_unix_path(self):
262 """Get the path the xend unix-domain server listens at.
263 """
264 return self.get_config_string("xend-unix-path", self.xend_unix_path_default)
266 def get_xend_domains_path(self):
267 """ Get the path for persistent domain configuration storage
268 """
269 return self.get_config_string("xend-domains-path", self.xend_domains_path_default)
271 def get_xend_state_path(self):
272 """ Get the path for persistent domain configuration storage
273 """
274 return self.get_config_string("xend-state-path", self.xend_state_path_default)
276 def get_xend_storage_path(self):
277 """ Get the path for persistent domain configuration storage
278 """
279 return self.get_config_string("xend-storage-path", self.xend_storage_path_default)
281 def get_xend_security_path(self):
282 """ Get the path for security state
283 """
284 return self.get_config_string("xend-security-path", self.xend_security_path_default)
286 def get_network_script(self):
287 """@return the script used to alter the network configuration when
288 Xend starts and stops, or None if no such script is specified."""
290 s = self.get_config_string('network-script')
292 if s:
293 result = s.split(" ")
294 result[0] = os.path.join(self.network_script_dir, result[0])
295 return result
296 else:
297 return None
299 def get_external_migration_tool(self):
300 """@return the name of the tool to handle virtual TPM migration."""
301 return self.get_config_string('external-migration-tool', self.external_migration_tool_default)
303 def get_enable_dump(self):
304 return self.get_config_bool('enable-dump', 'no')
306 def get_vif_script(self):
307 return self.get_config_string('vif-script', self.vif_script)
309 def get_dom0_min_mem(self):
310 return self.get_config_int('dom0-min-mem', self.dom0_min_mem_default)
312 def get_enable_dom0_ballooning(self):
313 enable_dom0_ballooning_default = 'yes'
314 if self.get_dom0_min_mem() == 0:
315 enable_dom0_ballooning_default = 'no'
316 return self.get_config_bool('enable-dom0-ballooning',
317 enable_dom0_ballooning_default)
319 def get_dom0_vcpus(self):
320 return self.get_config_int('dom0-cpus', self.dom0_vcpus_default)
322 def get_console_limit(self):
323 return self.get_config_int('console-limit', 1024)
325 def get_vnclisten_address(self):
326 return self.get_config_string('vnc-listen', self.xend_vnc_listen_default)
328 def get_vncpasswd_default(self):
329 return self.get_config_string('vncpasswd',
330 self.vncpasswd_default)
332 def get_keymap(self):
333 return self.get_config_value('keymap', None)
335 def get_resource_label_change_script(self):
336 s = self.get_config_value('resource-label-change-script')
337 if s:
338 result = s.split(" ")
339 result[0] = os.path.join(osdep.scripts_dir, result[0])
340 return result
341 else:
342 return None
345 def get_vnc_tls(self):
346 return self.get_config_string('vnc-tls', self.xend_vnc_tls)
348 def get_vnc_x509_cert_dir(self):
349 return self.get_config_string('vnc-x509-cert-dir', self.xend_vnc_x509_cert_dir)
351 def get_vnc_x509_verify(self):
352 return self.get_config_string('vnc-x509-verify', self.xend_vnc_x509_verify)
355 class XendOptionsFile(XendOptions):
357 """Default path to the config file."""
358 config_default = "/etc/xen/xend-config.sxp"
360 """Environment variable used to override config_default."""
361 config_var = "XEND_CONFIG"
363 def set_config(self):
364 """If the config file exists, read it. If not, ignore it.
366 The config file is a sequence of sxp forms.
367 """
368 self.config_path = os.getenv(self.config_var, self.config_default)
369 if os.path.exists(self.config_path):
370 try:
371 fin = file(self.config_path, 'rb')
372 try:
373 config = sxp.parse(fin)
374 finally:
375 fin.close()
376 if config is None:
377 config = ['xend-config']
378 else:
379 config.insert(0, 'xend-config')
380 self.config = config
381 except Exception, ex:
382 self._logError('Reading config file %s: %s',
383 self.config_path, str(ex))
384 raise
385 else:
386 self._logError('Config file does not exist: %s',
387 self.config_path)
388 self.config = ['xend-config']
390 def get_config_value(self, name, val=None):
391 """Get the value of an atomic configuration element.
393 @param name: element name
394 @param val: default value (optional, defaults to None)
395 @return: value
396 """
397 return sxp.child_value(self.config, name, val=val)
399 def get_config_bool(self, name, val=None):
400 v = string.lower(str(self.get_config_value(name, val)))
401 if v in ['yes', 'y', '1', 'on', 'true', 't']:
402 return True
403 if v in ['no', 'n', '0', 'off', 'false', 'f']:
404 return False
405 raise XendError("invalid xend config %s: expected bool: %s" % (name, v))
407 def get_config_int(self, name, val=None):
408 v = self.get_config_value(name, val)
409 try:
410 return int(v)
411 except Exception:
412 raise XendError("invalid xend config %s: expected int: %s" % (name, v))
414 def get_config_string(self, name, val=None):
415 return self.get_config_value(name, val)
417 def get_xen_api_server(self):
418 """Get the Xen-API server configuration.
419 """
420 return self.get_config_value('xen-api-server',
421 self.xen_api_server_default)
423 if os.uname()[0] == 'SunOS':
424 class XendOptionsSMF(XendOptions):
426 def set_config(self):
427 pass
429 def get_config_bool(self, name, val=None):
430 try:
431 return scf.get_bool(name)
432 except scf.error, e:
433 if e[0] == scf.SCF_ERROR_NOT_FOUND:
434 if val in ['yes', 'y', '1', 'on', 'true', 't']:
435 return True
436 if val in ['no', 'n', '0', 'off', 'false', 'f']:
437 return False
438 return val
439 else:
440 raise XendError("option %s: %s:%s" % (name, e[1], e[2]))
442 def get_config_int(self, name, val=None):
443 try:
444 return scf.get_int(name)
445 except scf.error, e:
446 if e[0] == scf.SCF_ERROR_NOT_FOUND:
447 return val
448 else:
449 raise XendError("option %s: %s:%s" % (name, e[1], e[2]))
451 def get_config_string(self, name, val=None):
452 try:
453 return scf.get_string(name)
454 except scf.error, e:
455 if e[0] == scf.SCF_ERROR_NOT_FOUND:
456 return val
457 else:
458 raise XendError("option %s: %s:%s" % (name, e[1], e[2]))
460 def get_xen_api_server(self):
461 # When the new server is a supported configuration, we should
462 # expand this.
463 return [["unix"]]
465 def instance():
466 """Get an instance of XendOptions.
467 Use this instead of the constructor.
468 """
469 global inst
470 try:
471 inst
472 except:
473 if os.uname()[0] == 'SunOS':
474 inst = XendOptionsSMF()
475 else:
476 inst = XendOptionsFile()
477 return inst