ia64/xen-unstable

view tools/python/xen/util/diagnose.py @ 9656:7af0d54f598c

Fix call to server, using new XendClient syntax.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Mon Apr 10 16:26:23 2006 +0100 (2006-04-10)
parents bf7c16e761fc
children dbf7032f1fc6
line source
1 # This library is free software; you can redistribute it and/or
2 # modify it under the terms of version 2.1 of the GNU Lesser General Public
3 # License as published by the Free Software Foundation.
4 #
5 # This library is distributed in the hope that it will be useful,
6 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8 # Lesser General Public License for more details.
9 #
10 # You should have received a copy of the GNU Lesser General Public
11 # License along with this library; if not, write to the Free Software
12 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13 #
14 # Copyright (c) 2005 XenSource Ltd
17 import re
18 import sys
20 from xen.xend import sxp
22 from xen.xend.XendClient import server
23 from xen.xend.XendError import XendError
24 from xen.xend.xenstore.xstransact import xstransact
25 from xen.xend.server import DevController
27 import xen.xend.XendProtocol
30 domain = None
31 domid = None
32 deviceClass = None
33 device = None
34 frontendPath = None
35 backendPath = None
38 def diagnose(dom):
39 global domain
40 global domid
41 global dompath
43 try:
44 domain = server.xend.domain(dom)
45 state = sxp.child_value(domain, 'state')
46 domid = int(sxp.child_value(domain, 'domid'))
47 name = sxp.child_value(domain, 'name')
48 dompath = '/local/domain/%d' % domid
50 print "Domain ID is %d." % domid
51 print "Domain name is %s." % name
53 if not state:
54 raise XendError("Cannot find state")
56 if state.find('c') != -1:
57 print "Domain has crashed."
59 diagnose_console()
61 diagnose_devices()
62 except xen.xend.XendProtocol.XendError, exn:
63 print exn
66 def diagnose_console():
67 port = xstransact.Read(dompath + '/console/port')
68 ringref = xstransact.Read(dompath + '/console/ring-ref')
69 tty = xstransact.Read(dompath + '/console/tty')
71 if not port:
72 print "Console port is missing; Xend has failed."
73 if not ringref:
74 print "Console ring-ref is missing; Xend has failed."
75 if not tty:
76 print "Console tty is missing; Xenconsoled has failed."
79 def diagnose_devices():
80 global deviceClass
81 global device
82 global frontendPath
83 global backendPath
85 device_path = dompath + '/device'
87 device_classes = xstransact.List(device_path)
89 print "Found %d device classes in use." % len(device_classes)
91 for dc in device_classes:
92 deviceClass = dc
93 device_class_path = device_path + '/' + deviceClass
95 devices = xstransact.List(device_class_path)
97 print "Found %d %s devices." % (len(devices), deviceClass)
99 for d in devices:
100 device = d
102 print "Found device %s, %s." % (deviceClass, device)
104 frontendPath = device_class_path + '/' + device
105 backendPath = xstransact.Read(frontendPath, 'backend')
107 if not backendPath:
108 print ("Cannot find backend path for device %s, %s." %
109 (deviceClass, device))
110 else:
111 frontend_state = xstransact.Read(frontendPath, 'state')
112 backend_state = xstransact.Read(backendPath, 'state')
114 print "Backend is in state %s." % stateString(backend_state)
115 print "Frontend is in state %s." % stateString(frontend_state)
117 check_for_error(True)
118 check_for_error(False)
120 diagnose_hotplugging()
123 def check_for_error(backend):
124 if backend:
125 path = backendPath.replace('backend/', 'error/backend/')
126 else:
127 path = frontendPath.replace('device/', 'error/device/')
129 err = xstransact.Read(path, 'error')
131 if err:
132 print ("%s for device %s, %s shows error %s." %
133 (backend and 'Backend' or 'Frontend', deviceClass, device,
134 err))
137 def diagnose_hotplugging():
138 if deviceClass == 'vbd':
139 phy = xstransact.Read(backendPath, 'physical-device')
141 if phy:
142 print ('Device %s, %s hotplugging has completed successfully, '
143 'and is connected to physical device %s.' %
144 (deviceClass, device, phy))
145 else:
146 print ('Device %s, %s hotplugging failed.' %
147 (deviceClass, device))
148 elif deviceClass == 'vif':
149 handle = xstransact.Read(backendPath, 'handle')
151 if handle:
152 print ('Device %s, %s hotplugging has completed successfully, '
153 'and is using handle %s.' %
154 (deviceClass, device, handle))
155 else:
156 print ('Device %s, %s hotplugging failed.' %
157 (deviceClass, device))
160 def stateString(state):
161 return state and DevController.xenbusState[int(state)] or '<None>'
164 def main(argv = None):
165 if argv is None:
166 argv = sys.argv
168 diagnose(argv[1])
170 return 0
173 if __name__ == "__main__":
174 sys.exit(main())