debuggers.hg

view tools/python/xen/xend/osdep.py @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children 5c0bf00e371d
line source
1 #!/usr/bin/env 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 #
17 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
18 # Use is subject to license terms.
20 import os
22 _scripts_dir = {
23 "Linux": "/etc/xen/scripts",
24 "SunOS": "/usr/lib/xen/scripts",
25 }
27 _xend_autorestart = {
28 "NetBSD": True,
29 "Linux": True,
30 "SunOS": False,
31 }
33 _pygrub_path = {
34 "SunOS": "/usr/lib/xen/bin/pygrub"
35 }
37 _vif_script = {
38 "SunOS": "vif-vnic"
39 }
41 def _linux_balloon_stat(label):
42 """Returns the value for the named label, or None if an error occurs."""
44 PROC_XEN_BALLOON = '/proc/xen/balloon'
45 f = file(PROC_XEN_BALLOON, 'r')
46 try:
47 for line in f:
48 keyvalue = line.split(':')
49 if keyvalue[0] == label:
50 values = keyvalue[1].split()
51 if values[0].isdigit():
52 return int(values[0])
53 else:
54 return None
55 return None
56 finally:
57 f.close()
59 def _solaris_balloon_stat(label):
60 """Returns the value for the named label, or None if an error occurs."""
62 import fcntl
63 import array
64 DEV_XEN_BALLOON = '/dev/xen/balloon'
65 BLN_IOCTL_CURRENT = 0x42410001
66 BLN_IOCTL_TARGET = 0x42410002
67 BLN_IOCTL_LOW = 0x42410003
68 BLN_IOCTL_HIGH = 0x42410004
69 BLN_IOCTL_LIMIT = 0x42410005
70 label_to_ioctl = { 'Current allocation' : BLN_IOCTL_CURRENT,
71 'Requested target' : BLN_IOCTL_TARGET,
72 'Low-mem balloon' : BLN_IOCTL_LOW,
73 'High-mem balloon' : BLN_IOCTL_HIGH,
74 'Xen hard limit' : BLN_IOCTL_LIMIT }
76 f = file(DEV_XEN_BALLOON, 'r')
77 try:
78 values = array.array('L', [0])
79 if fcntl.ioctl(f.fileno(), label_to_ioctl[label], values, 1) == 0:
80 return values[0]
81 else:
82 return None
83 finally:
84 f.close()
86 _balloon_stat = {
87 "SunOS": _solaris_balloon_stat
88 }
90 def _get(var, default=None):
91 return var.get(os.uname()[0], default)
93 scripts_dir = _get(_scripts_dir, "/etc/xen/scripts")
94 xend_autorestart = _get(_xend_autorestart)
95 pygrub_path = _get(_pygrub_path, "/usr/bin/pygrub")
96 vif_script = _get(_vif_script, "vif-bridge")
97 lookup_balloon_stat = _get(_balloon_stat, _linux_balloon_stat)