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
12 import cygvirtmod
as libvirtmod
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):
24 elif pool
is not None:
30 err
= virGetLastError()
32 err
= conn
.virConnGetLastError()
38 Exception.__init
__(self
, msg
)
42 def get_error_code(self
):
47 def get_error_domain(self
):
52 def get_error_message(self
):
57 def get_error_level(self
):
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,
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."""
119 ret
= libvirtmod
.virGetVersion ();
121 ret
= libvirtmod
.virGetVersion (name
);
122 if ret
is None: raise libvirtError ("virGetVersion() failed")
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