* python/Makefile.am python/generator.py python/libvir.c
[libvirt-python/ericb.git] / libvir.py
blob86bf422df6d15816033f7aac351171c543add14d
1 #!/usr/bin/python -u
3 # Those are the autogenerated Python bindings for libvirt.
4 # Check python/generator.py in the source distribution of libvir
5 # to find out more about the generation process
8 # On cygwin, the DLL is called cygvirtmod.dll
9 try:
10 import libvirtmod
11 except:
12 import cygvirtmod as libvirtmod
14 import types
16 # The root of all libvirt errors.
17 class libvirtError(Exception):
18 def __init__(self, defmsg, conn=None, dom=None, net=None, pool=None, vol=None):
20 if dom is not None:
21 conn = dom._conn
22 elif net is not None:
23 conn = net._conn
24 elif pool is not None:
25 conn = pool._conn
26 elif vol is not None:
27 conn = vol._conn
29 if conn is None:
30 err = virGetLastError()
31 else:
32 err = conn.virConnGetLastError()
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 (fd, event, callback, opaque):
131 Invoke the Event Impl Handle Callback in C
133 libvirtmod.virEventInvokeHandleCallback(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);
146 # WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
148 # Everything before this line comes from libvir.py
149 # Everything after this line is automatically generated
151 # WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING