Improve error handling, in particular fixing the ProtocolError that is thrown

when a domain is specified by the user that does not exist.  Added a few
error codes -- many more to come, I expect.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
emellor@leeni.uk.xensource.com committed 2006-03-23 12:59:43 +01:00
1 parent 91c4832c49
commit 88aea7e5a8
4 files changed
+38 -9

No files matched your search

+4
View File
@@ -21,4 +21,8 @@ from xen.util.xmlrpclib2 import ServerProxy
XML_RPC_SOCKET = "/var/run/xend-xmlrpc.sock"
ERROR_INTERNAL = 1
ERROR_GENERIC = 2
ERROR_INVALID_DOMAIN = 3
server = ServerProxy('httpu:///var/run/xend-xmlrpc.sock')
+3 -1
View File
@@ -17,10 +17,12 @@
from xmlrpclib import Fault
import XendClient
class XendError(Fault):
def __init__(self, value):
Fault.__init__(self, 2, value)
Fault.__init__(self, XendClient.ERROR_GENERIC, value)
self.value = value
def __str__(self):
+25 -5
View File
@@ -13,25 +13,45 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2006 Anthony Liguori <aliguori@us.ibm.com>
# Copyright (C) 2006 XenSource Ltd
# Copyright (C) 2006 XenSource Ltd.
#============================================================================
import xmlrpclib
from xen.xend import XendDomain, XendDomainInfo, XendNode, \
XendLogging, XendDmesg
from xen.util.xmlrpclib2 import UnixXMLRPCServer, TCPXMLRPCServer
from xen.xend.XendClient import XML_RPC_SOCKET
from xen.xend.XendClient import XML_RPC_SOCKET, ERROR_INVALID_DOMAIN
def lookup(domid):
return XendDomain.instance().domain_lookup_by_name_or_id(domid)
try:
return XendDomain.instance().domain_lookup_by_name_or_id(domid)
except exn:
log.exception(exn)
raise exn
def dispatch(domid, fn, args):
info = lookup(domid)
return getattr(info, fn)(*args)
if info:
try:
return getattr(info, fn)(*args)
except exn:
log.exception(exn)
raise exn
else:
raise xmlrpclib.Fault(ERROR_INVALID_DOMAIN, domid)
def domain(domid):
info = lookup(domid)
return info.sxpr()
if info:
try:
return info.sxpr()
except exn:
log.exception(exn)
raise exn
else:
raise xmlrpclib.Fault(ERROR_INVALID_DOMAIN, domid)
def domains(detail=1):
if detail < 1:
+6 -3
View File
@@ -1,6 +1,6 @@
# (C) Copyright IBM Corp. 2005
# Copyright (C) 2004 Mike Wray
# Copyright (c) 2005 XenSource Ltd
# Copyright (c) 2005-2006 XenSource Ltd.
#
# Authors:
# Sean Dague <sean at dague dot net>
@@ -38,7 +38,7 @@ from xen.xend import sxp
from xen.xm.opts import *
import console
import xen.xend.XendClient
from xen.xend.XendClient import server
# getopt.gnu_getopt is better, but only exists in Python 2.3+. Use
@@ -1111,7 +1111,10 @@ def main(argv=sys.argv):
except SystemExit:
sys.exit(1)
except xmlrpclib.Fault, ex:
print "Error: %s" % ex.faultString
if ex.faultCode == xen.xend.XendClient.ERROR_INVALID_DOMAIN:
print "Error: the domain '%s' does not exist." % ex.faultString
else:
print "Error: %s" % ex.faultString
sys.exit(1)
except:
print "Unexpected error:", sys.exc_info()[0]
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.