2006-02-28 20:17:00 +08:00
|
|
|
#!/usr/bin/python -u
|
|
|
|
#
|
|
|
|
# Those are the autogenerated Python bindings for libvirt.
|
|
|
|
# Check python/generator.py in the source distribution of libvir
|
|
|
|
# to find out more about the generation process
|
|
|
|
#
|
|
|
|
import libvirtmod
|
|
|
|
import types
|
|
|
|
|
2006-11-08 07:18:56 +08:00
|
|
|
# The root of all libvirt errors.
|
2006-02-28 20:17:00 +08:00
|
|
|
class libvirtError(Exception):
|
2007-04-16 20:37:59 +08:00
|
|
|
def __init__(self, msg, conn=None, dom=None, net=None):
|
2006-11-08 07:18:56 +08:00
|
|
|
Exception.__init__(self, msg)
|
2006-02-28 20:17:00 +08:00
|
|
|
|
2007-04-16 20:37:59 +08:00
|
|
|
if dom is not None:
|
|
|
|
conn = dom._conn
|
|
|
|
elif net is not None:
|
|
|
|
conn = net._conn
|
|
|
|
|
2006-11-08 07:18:56 +08:00
|
|
|
if conn is None:
|
|
|
|
self.err = virGetLastError()
|
|
|
|
else:
|
|
|
|
self.err = conn.virConnGetLastError()
|
|
|
|
|
|
|
|
def get_error_code(self):
|
|
|
|
if self.err is None:
|
|
|
|
return None
|
|
|
|
return self.err[0]
|
|
|
|
|
|
|
|
def get_error_domain(self):
|
|
|
|
if self.err is None:
|
|
|
|
return None
|
|
|
|
return self.err[1]
|
|
|
|
|
|
|
|
def get_error_message(self):
|
|
|
|
if self.err is None:
|
|
|
|
return None
|
|
|
|
return self.err[2]
|
|
|
|
|
|
|
|
def get_error_level(self):
|
|
|
|
if self.err is None:
|
|
|
|
return None
|
|
|
|
return self.err[3]
|
|
|
|
|
|
|
|
def get_str1(self):
|
|
|
|
if self.err is None:
|
|
|
|
return None
|
|
|
|
return self.err[4]
|
|
|
|
|
|
|
|
def get_str2(self):
|
|
|
|
if self.err is None:
|
|
|
|
return None
|
|
|
|
return self.err[5]
|
|
|
|
|
|
|
|
def get_str3(self):
|
|
|
|
if self.err is None:
|
|
|
|
return None
|
|
|
|
return self.err[6]
|
|
|
|
|
|
|
|
def get_int1(self):
|
|
|
|
if self.err is None:
|
|
|
|
return None
|
|
|
|
return self.err[7]
|
|
|
|
|
|
|
|
def get_int2(self):
|
|
|
|
if self.err is None:
|
|
|
|
return None
|
|
|
|
return self.err[8]
|
|
|
|
|
|
|
|
def __str__(self):
|
2006-11-11 03:55:27 +08:00
|
|
|
if self.get_error_message() is None:
|
|
|
|
return Exception.__str__(self)
|
|
|
|
else:
|
|
|
|
return Exception.__str__(self) + " " + self.get_error_message()
|
2006-02-28 20:17:00 +08:00
|
|
|
|
|
|
|
#
|
|
|
|
# register the libvirt global error handler
|
|
|
|
#
|
|
|
|
def registerErrorHandler(f, ctx):
|
|
|
|
"""Register a Python written function to for error reporting.
|
|
|
|
The function is called back as f(ctx, error), with error
|
|
|
|
being a list of informations about the error being raised.
|
|
|
|
Returns 1 in case of success."""
|
|
|
|
return libvirtmod.virRegisterErrorHandler(f,ctx)
|
|
|
|
|
2007-05-29 22:58:27 +08:00
|
|
|
#
|
|
|
|
# Return library version.
|
|
|
|
#
|
|
|
|
def getVersion (name = None):
|
|
|
|
"""If no name parameter is passed (or name is None) then the
|
|
|
|
version of the libvirt library is returned as an integer.
|
|
|
|
|
|
|
|
If a name is passed and it refers to a driver linked to the
|
|
|
|
libvirt library, then this returns a tuple of (library version,
|
|
|
|
driver version).
|
|
|
|
|
|
|
|
If the name passed refers to a non-existent driver, then you
|
|
|
|
will get the exception 'no support for hypervisor'.
|
|
|
|
|
|
|
|
Versions numbers are integers: 1000000*major + 1000*minor + release."""
|
|
|
|
if name is None:
|
|
|
|
ret = libvirtmod.virGetVersion ();
|
|
|
|
else:
|
|
|
|
ret = libvirtmod.virGetVersion (name);
|
|
|
|
if ret is None: raise libvirtError ("virGetVersion() failed")
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
2006-02-28 20:17:00 +08:00
|
|
|
# WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
|
|
|
|
#
|
|
|
|
# Everything before this line comes from libvir.py
|
|
|
|
# Everything after this line is automatically generated
|
|
|
|
#
|
|
|
|
# WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
|