Don't ship generated python/libvirt.? files.
[libvirt-python/ericb.git] / libvirt-override.py
blobde1af2d9eff59d90a379ea3d455225904a74c884
2 # Manually written part of python bindings for libvirt
5 # On cygwin, the DLL is called cygvirtmod.dll
6 try:
7 import libvirtmod
8 except ImportError, lib_e:
9 try:
10 import cygvirtmod as libvirtmod
11 except ImportError, cyg_e:
12 if str(cyg_e).count("No module named"):
13 raise lib_e
15 import types
17 # The root of all libvirt errors.
18 class libvirtError(Exception):
19 def __init__(self, defmsg, conn=None, dom=None, net=None, pool=None, vol=None):
21 if dom is not None:
22 conn = dom._conn
23 elif net is not None:
24 conn = net._conn
25 elif pool is not None:
26 conn = pool._conn
27 elif vol is not None:
28 conn = vol._conn
30 # Never call virConnGetLastError().
31 # virGetLastError() is now thread local
32 err = virGetLastError()
33 if err is None:
34 msg = defmsg
35 else:
36 msg = err[2]
38 Exception.__init__(self, msg)
40 self.err = err
42 def get_error_code(self):
43 if self.err is None:
44 return None
45 return self.err[0]
47 def get_error_domain(self):
48 if self.err is None:
49 return None
50 return self.err[1]
52 def get_error_message(self):
53 if self.err is None:
54 return None
55 return self.err[2]
57 def get_error_level(self):
58 if self.err is None:
59 return None
60 return self.err[3]
62 def get_str1(self):
63 if self.err is None:
64 return None
65 return self.err[4]
67 def get_str2(self):
68 if self.err is None:
69 return None
70 return self.err[5]
72 def get_str3(self):
73 if self.err is None:
74 return None
75 return self.err[6]
77 def get_int1(self):
78 if self.err is None:
79 return None
80 return self.err[7]
82 def get_int2(self):
83 if self.err is None:
84 return None
85 return self.err[8]
88 # register the libvirt global error handler
90 def registerErrorHandler(f, ctx):
91 """Register a Python written function to for error reporting.
92 The function is called back as f(ctx, error), with error
93 being a list of information about the error being raised.
94 Returns 1 in case of success."""
95 return libvirtmod.virRegisterErrorHandler(f,ctx)
97 def openAuth(uri, auth, flags):
98 ret = libvirtmod.virConnectOpenAuth(uri, auth, flags)
99 if ret is None:raise libvirtError('virConnectOpenAuth() failed')
100 return virConnect(_obj=ret)
104 # Return library version.
106 def getVersion (name = None):
107 """If no name parameter is passed (or name is None) then the
108 version of the libvirt library is returned as an integer.
110 If a name is passed and it refers to a driver linked to the
111 libvirt library, then this returns a tuple of (library version,
112 driver version).
114 If the name passed refers to a non-existent driver, then you
115 will get the exception 'no support for hypervisor'.
117 Versions numbers are integers: 1000000*major + 1000*minor + release."""
118 if name is None:
119 ret = libvirtmod.virGetVersion ();
120 else:
121 ret = libvirtmod.virGetVersion (name);
122 if ret is None: raise libvirtError ("virGetVersion() failed")
123 return ret
127 # Invoke an EventHandle callback
129 def eventInvokeHandleCallback (watch, fd, event, callback, opaque):
131 Invoke the Event Impl Handle Callback in C
133 libvirtmod.virEventInvokeHandleCallback(watch, fd, event, callback, opaque);
136 # Invoke an EventTimeout callback
138 def eventInvokeTimeoutCallback (timer, callback, opaque):
140 Invoke the Event Impl Timeout Callback in C
142 libvirtmod.virEventInvokeTimeoutCallback(timer, callback, opaque);