Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# Copyright (C) Citrix Systems Inc. 

2# 

3# This program is free software; you can redistribute it and/or modify 

4# it under the terms of the GNU Lesser General Public License as published 

5# by the Free Software Foundation; version 2.1 only. 

6# 

7# This program 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 

10# GNU Lesser General Public License for more details. 

11# 

12# You should have received a copy of the GNU Lesser General Public License 

13# along with this program; if not, write to the Free Software Foundation, Inc., 

14# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 

15# 

16# Xensource error codes 

17# 

18 

19import os 

20import xml.dom.minidom 

21import SR 

22import util 

23 

24XML_DEFS = '/opt/xensource/sm/XE_SR_ERRORCODES.xml' 

25 

26 

27class XenError(Exception): 

28 def __new__(self, key, opterr=None): 

29 # Check the XML definition file exists 

30 if not os.path.exists(XML_DEFS): 

31 raise Exception("No XML def file found") 

32 

33 # Read the definition list 

34 errorlist = self._fromxml('SM-errorcodes') 

35 

36 ########DEBUG####### 

37 #for val in self.errorlist.keys(): 

38 # subdict = self.errorlist[val] 

39 # print "KEY [%s]" % val 

40 # for subval in subdict.keys(): 

41 # print "\tSUBKEY: %s, VALUE: %s" % (subval,subdict[subval]) 

42 ########END####### 

43 

44 # Now find the specific error 

45 if key in errorlist: 45 ↛ 55line 45 didn't jump to line 55, because the condition on line 45 was never false

46 subdict = errorlist[key] 

47 errorcode = int(subdict['value']) 

48 errormessage = subdict['description'] 

49 if opterr is not None: 

50 errormessage += " [opterr=%s]" % opterr 

51 util.SMlog("Raising exception [%d, %s]" % (errorcode, errormessage)) 

52 return SR.SROSError(errorcode, errormessage) 

53 

54 # development error 

55 return SR.SROSError(1, "Error reporting error, unknown key %s" % key) 

56 

57 @staticmethod 

58 def _fromxml(tag): 

59 dom = xml.dom.minidom.parse(XML_DEFS) 

60 objectlist = dom.getElementsByTagName(tag)[0] 

61 

62 errorlist = {} 

63 for node in objectlist.childNodes: 

64 taglist = {} 

65 newval = False 

66 for n in node.childNodes: 

67 if n.nodeType == n.ELEMENT_NODE and node.nodeName == 'code': 

68 taglist[n.nodeName] = "" 

69 for e in n.childNodes: 

70 if e.nodeType == e.TEXT_NODE: 70 ↛ 69line 70 didn't jump to line 69, because the condition on line 70 was never false

71 newval = True 

72 taglist[n.nodeName] += e.data 

73 if newval: 

74 name = taglist['name'] 

75 errorlist[name] = taglist 

76 return errorlist