mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-07-25 04:58:57 +03:00
Normalize white space
indent by 4 spaces one spaces around assignments Signed-off-by: Philipp Hahn <hahn@univention.de>
This commit is contained in:
28
generator.py
28
generator.py
@ -48,6 +48,7 @@ libvirt_headers = [
|
|||||||
"libvirt-stream",
|
"libvirt-stream",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def getparser():
|
def getparser():
|
||||||
# Attach parser to an unmarshalling object. return both objects.
|
# Attach parser to an unmarshalling object. return both objects.
|
||||||
target = docParser()
|
target = docParser()
|
||||||
@ -55,6 +56,7 @@ def getparser():
|
|||||||
parser.setContentHandler(target)
|
parser.setContentHandler(target)
|
||||||
return parser, target
|
return parser, target
|
||||||
|
|
||||||
|
|
||||||
class docParser(xml.sax.handler.ContentHandler):
|
class docParser(xml.sax.handler.ContentHandler):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._methodname = None
|
self._methodname = None
|
||||||
@ -211,18 +213,21 @@ def function(name, desc, ret, args, file, module, cond):
|
|||||||
name = "virConnectListDomainsID"
|
name = "virConnectListDomainsID"
|
||||||
functions[name] = (desc, ret, args, file, module, cond)
|
functions[name] = (desc, ret, args, file, module, cond)
|
||||||
|
|
||||||
|
|
||||||
def qemu_function(name, desc, ret, args, file, module, cond):
|
def qemu_function(name, desc, ret, args, file, module, cond):
|
||||||
global onlyOverrides
|
global onlyOverrides
|
||||||
if onlyOverrides and name not in qemu_functions:
|
if onlyOverrides and name not in qemu_functions:
|
||||||
return
|
return
|
||||||
qemu_functions[name] = (desc, ret, args, file, module, cond)
|
qemu_functions[name] = (desc, ret, args, file, module, cond)
|
||||||
|
|
||||||
|
|
||||||
def lxc_function(name, desc, ret, args, file, module, cond):
|
def lxc_function(name, desc, ret, args, file, module, cond):
|
||||||
global onlyOverrides
|
global onlyOverrides
|
||||||
if onlyOverrides and name not in lxc_functions:
|
if onlyOverrides and name not in lxc_functions:
|
||||||
return
|
return
|
||||||
lxc_functions[name] = (desc, ret, args, file, module, cond)
|
lxc_functions[name] = (desc, ret, args, file, module, cond)
|
||||||
|
|
||||||
|
|
||||||
def enum(type, name, value):
|
def enum(type, name, value):
|
||||||
if type not in enums:
|
if type not in enums:
|
||||||
enums[type] = {}
|
enums[type] = {}
|
||||||
@ -251,6 +256,7 @@ def enum(type, name, value):
|
|||||||
return
|
return
|
||||||
enums[type][name] = value
|
enums[type][name] = value
|
||||||
|
|
||||||
|
|
||||||
def lxc_enum(type, name, value):
|
def lxc_enum(type, name, value):
|
||||||
if type not in lxc_enums:
|
if type not in lxc_enums:
|
||||||
lxc_enums[type] = {}
|
lxc_enums[type] = {}
|
||||||
@ -258,6 +264,7 @@ def lxc_enum(type, name, value):
|
|||||||
return
|
return
|
||||||
lxc_enums[type][name] = value
|
lxc_enums[type][name] = value
|
||||||
|
|
||||||
|
|
||||||
def qemu_enum(type, name, value):
|
def qemu_enum(type, name, value):
|
||||||
if type not in qemu_enums:
|
if type not in qemu_enums:
|
||||||
qemu_enums[type] = {}
|
qemu_enums[type] = {}
|
||||||
@ -677,6 +684,7 @@ function_skip_index_one = (
|
|||||||
"virDomainRevertToSnapshot",
|
"virDomainRevertToSnapshot",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_function_wrapper(module, name, output, export, include):
|
def print_function_wrapper(module, name, output, export, include):
|
||||||
global py_types
|
global py_types
|
||||||
global unknown_types
|
global unknown_types
|
||||||
@ -739,8 +747,8 @@ def print_function_wrapper(module, name, output, export, include):
|
|||||||
format_args = format_args + ", &pyobj_%s" % (arg[0])
|
format_args = format_args + ", &pyobj_%s" % (arg[0])
|
||||||
c_args = c_args + " PyObject *pyobj_%s;\n" % (arg[0])
|
c_args = c_args + " PyObject *pyobj_%s;\n" % (arg[0])
|
||||||
c_convert = c_convert + \
|
c_convert = c_convert + \
|
||||||
" %s = (%s) Py%s_Get(pyobj_%s);\n" % (arg[0],
|
" %s = (%s) Py%s_Get(pyobj_%s);\n" % (
|
||||||
arg[1], t, arg[0])
|
arg[0], arg[1], t, arg[0])
|
||||||
else:
|
else:
|
||||||
format_args = format_args + ", &%s" % (arg[0])
|
format_args = format_args + ", &%s" % (arg[0])
|
||||||
if f == 't#':
|
if f == 't#':
|
||||||
@ -767,8 +775,8 @@ def print_function_wrapper(module, name, output, export, include):
|
|||||||
if args[1][1] == "char *":
|
if args[1][1] == "char *":
|
||||||
c_call = "\n VIR_FREE(%s->%s);\n" % (
|
c_call = "\n VIR_FREE(%s->%s);\n" % (
|
||||||
args[0][0], args[1][0])
|
args[0][0], args[1][0])
|
||||||
c_call = c_call + " %s->%s = (%s)strdup((const xmlChar *)%s);\n" % (args[0][0],
|
c_call = c_call + " %s->%s = (%s)strdup((const xmlChar *)%s);\n" % (
|
||||||
args[1][0], args[1][1], args[1][0])
|
args[0][0], args[1][0], args[1][1], args[1][0])
|
||||||
else:
|
else:
|
||||||
c_call = "\n %s->%s = %s;\n" % (args[0][0], args[1][0],
|
c_call = "\n %s->%s = %s;\n" % (args[0][0], args[1][0],
|
||||||
args[1][0])
|
args[1][0])
|
||||||
@ -875,6 +883,7 @@ def print_function_wrapper(module, name, output, export, include):
|
|||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def print_c_pointer(classname, output, export, include):
|
def print_c_pointer(classname, output, export, include):
|
||||||
output.write("PyObject *\n")
|
output.write("PyObject *\n")
|
||||||
output.write("libvirt_%s_pointer(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)\n" % classname)
|
output.write("libvirt_%s_pointer(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)\n" % classname)
|
||||||
@ -896,6 +905,7 @@ def print_c_pointer(classname, output, export, include):
|
|||||||
export.write(" { (char *)\"%s_pointer\", libvirt_%s_pointer, METH_VARARGS, NULL },\n" %
|
export.write(" { (char *)\"%s_pointer\", libvirt_%s_pointer, METH_VARARGS, NULL },\n" %
|
||||||
(classname, classname))
|
(classname, classname))
|
||||||
|
|
||||||
|
|
||||||
def buildStubs(module, api_xml):
|
def buildStubs(module, api_xml):
|
||||||
global py_types
|
global py_types
|
||||||
global unknown_types
|
global unknown_types
|
||||||
@ -1019,6 +1029,7 @@ def buildStubs(module, api_xml):
|
|||||||
return -1
|
return -1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
# This part writes part of the Python front-end classes based on
|
# This part writes part of the Python front-end classes based on
|
||||||
@ -1126,16 +1137,19 @@ functions_int_exception_test = {
|
|||||||
}
|
}
|
||||||
functions_int_default_test = "%s == -1"
|
functions_int_default_test = "%s == -1"
|
||||||
|
|
||||||
|
|
||||||
def is_integral_type(name):
|
def is_integral_type(name):
|
||||||
return not re.search("^(unsigned)? ?(int|long)$", name) is None
|
return not re.search("^(unsigned)? ?(int|long)$", name) is None
|
||||||
|
|
||||||
|
|
||||||
def is_optional_arg(info):
|
def is_optional_arg(info):
|
||||||
return re.search("^\(?optional\)?", info) is not None
|
return re.search("^\(?optional\)?", info) is not None
|
||||||
|
|
||||||
def is_python_noninteger_type (name):
|
|
||||||
|
|
||||||
|
def is_python_noninteger_type(name):
|
||||||
return name[-1:] == "*"
|
return name[-1:] == "*"
|
||||||
|
|
||||||
|
|
||||||
def nameFixup(name, classe, type, file):
|
def nameFixup(name, classe, type, file):
|
||||||
# avoid a disastrous clash
|
# avoid a disastrous clash
|
||||||
listname = classe + "List"
|
listname = classe + "List"
|
||||||
@ -1344,6 +1358,7 @@ def functionSortKey(info):
|
|||||||
(index, func, name, ret, args, filename, mod) = info
|
(index, func, name, ret, args, filename, mod) = info
|
||||||
return func, filename
|
return func, filename
|
||||||
|
|
||||||
|
|
||||||
def writeDoc(module, name, args, indent, output):
|
def writeDoc(module, name, args, indent, output):
|
||||||
if module == "libvirt":
|
if module == "libvirt":
|
||||||
funcs = functions
|
funcs = functions
|
||||||
@ -1367,6 +1382,7 @@ def writeDoc(module, name, args, indent, output):
|
|||||||
output.write(val)
|
output.write(val)
|
||||||
output.write(' """\n')
|
output.write(' """\n')
|
||||||
|
|
||||||
|
|
||||||
def buildWrappers(module):
|
def buildWrappers(module):
|
||||||
global ctypes
|
global ctypes
|
||||||
global py_types
|
global py_types
|
||||||
@ -1834,7 +1850,6 @@ def buildWrappers(module):
|
|||||||
classes.write(" #\n")
|
classes.write(" #\n")
|
||||||
cached = None
|
cached = None
|
||||||
|
|
||||||
|
|
||||||
# Since we compile with older libvirt, we don't want to pull
|
# Since we compile with older libvirt, we don't want to pull
|
||||||
# in manually written python methods which call C methods
|
# in manually written python methods which call C methods
|
||||||
# that don't exist. This code attempts to detect which
|
# that don't exist. This code attempts to detect which
|
||||||
@ -1921,6 +1936,7 @@ def buildWrappers(module):
|
|||||||
|
|
||||||
classes.close()
|
classes.close()
|
||||||
|
|
||||||
|
|
||||||
def qemuBuildWrappers(module):
|
def qemuBuildWrappers(module):
|
||||||
global qemu_functions
|
global qemu_functions
|
||||||
|
|
||||||
|
@ -25,7 +25,8 @@
|
|||||||
if len(self.domainEventCallbacks) == 0:
|
if len(self.domainEventCallbacks) == 0:
|
||||||
del self.domainEventCallbacks
|
del self.domainEventCallbacks
|
||||||
ret = libvirtmod.virConnectDomainEventDeregister(self._o, self)
|
ret = libvirtmod.virConnectDomainEventDeregister(self._o, self)
|
||||||
if ret == -1: raise libvirtError ('virConnectDomainEventDeregister() failed', conn=self)
|
if ret == -1:
|
||||||
|
raise libvirtError('virConnectDomainEventDeregister() failed', conn=self)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -37,7 +38,8 @@
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
self.domainEventCallbacks = {cb: opaque}
|
self.domainEventCallbacks = {cb: opaque}
|
||||||
ret = libvirtmod.virConnectDomainEventRegister(self._o, self)
|
ret = libvirtmod.virConnectDomainEventRegister(self._o, self)
|
||||||
if ret == -1: raise libvirtError ('virConnectDomainEventRegister() failed', conn=self)
|
if ret == -1:
|
||||||
|
raise libvirtError('virConnectDomainEventRegister() failed', conn=self)
|
||||||
|
|
||||||
def _dispatchDomainEventCallbacks(self, dom, event, detail):
|
def _dispatchDomainEventCallbacks(self, dom, event, detail):
|
||||||
"""Dispatches events to python user domain event callbacks
|
"""Dispatches events to python user domain event callbacks
|
||||||
@ -272,7 +274,8 @@
|
|||||||
domain callback will disable delivery of this event type """
|
domain callback will disable delivery of this event type """
|
||||||
try:
|
try:
|
||||||
ret = libvirtmod.virConnectDomainEventDeregisterAny(self._o, callbackID)
|
ret = libvirtmod.virConnectDomainEventDeregisterAny(self._o, callbackID)
|
||||||
if ret == -1: raise libvirtError ('virConnectDomainEventDeregisterAny() failed', conn=self)
|
if ret == -1:
|
||||||
|
raise libvirtError('virConnectDomainEventDeregisterAny() failed', conn=self)
|
||||||
del self.domainEventCallbackID[callbackID]
|
del self.domainEventCallbackID[callbackID]
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
@ -291,7 +294,8 @@
|
|||||||
network callback will disable delivery of this event type"""
|
network callback will disable delivery of this event type"""
|
||||||
try:
|
try:
|
||||||
ret = libvirtmod.virConnectNetworkEventDeregisterAny(self._o, callbackID)
|
ret = libvirtmod.virConnectNetworkEventDeregisterAny(self._o, callbackID)
|
||||||
if ret == -1: raise libvirtError ('virConnectNetworkEventDeregisterAny() failed', conn=self)
|
if ret == -1:
|
||||||
|
raise libvirtError('virConnectNetworkEventDeregisterAny() failed', conn=self)
|
||||||
del self.networkEventCallbackID[callbackID]
|
del self.networkEventCallbackID[callbackID]
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
@ -351,7 +355,8 @@
|
|||||||
storage pool callback will disable delivery of this event type"""
|
storage pool callback will disable delivery of this event type"""
|
||||||
try:
|
try:
|
||||||
ret = libvirtmod.virConnectStoragePoolEventDeregisterAny(self._o, callbackID)
|
ret = libvirtmod.virConnectStoragePoolEventDeregisterAny(self._o, callbackID)
|
||||||
if ret == -1: raise libvirtError ('virConnectStoragePoolEventDeregisterAny() failed', conn=self)
|
if ret == -1:
|
||||||
|
raise libvirtError('virConnectStoragePoolEventDeregisterAny() failed', conn=self)
|
||||||
del self.storagePoolEventCallbackID[callbackID]
|
del self.storagePoolEventCallbackID[callbackID]
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
@ -396,7 +401,8 @@
|
|||||||
node device callback will disable delivery of this event type"""
|
node device callback will disable delivery of this event type"""
|
||||||
try:
|
try:
|
||||||
ret = libvirtmod.virConnectNodeDeviceEventDeregisterAny(self._o, callbackID)
|
ret = libvirtmod.virConnectNodeDeviceEventDeregisterAny(self._o, callbackID)
|
||||||
if ret == -1: raise libvirtError ('virConnectNodeDeviceEventDeregisterAny() failed', conn=self)
|
if ret == -1:
|
||||||
|
raise libvirtError('virConnectNodeDeviceEventDeregisterAny() failed', conn=self)
|
||||||
del self.nodeDeviceEventCallbackID[callbackID]
|
del self.nodeDeviceEventCallbackID[callbackID]
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
@ -439,7 +445,8 @@
|
|||||||
secret callback will disable delivery of this event type"""
|
secret callback will disable delivery of this event type"""
|
||||||
try:
|
try:
|
||||||
ret = libvirtmod.virConnectSecretEventDeregisterAny(self._o, callbackID)
|
ret = libvirtmod.virConnectSecretEventDeregisterAny(self._o, callbackID)
|
||||||
if ret == -1: raise libvirtError ('virConnectSecretEventDeregisterAny() failed', conn=self)
|
if ret == -1:
|
||||||
|
raise libvirtError('virConnectSecretEventDeregisterAny() failed', conn=self)
|
||||||
del self.secretEventCallbackID[callbackID]
|
del self.secretEventCallbackID[callbackID]
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
@ -563,11 +570,11 @@
|
|||||||
cb(self, reason, opaque)
|
cb(self, reason, opaque)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def unregisterCloseCallback(self):
|
def unregisterCloseCallback(self):
|
||||||
"""Removes a close event callback"""
|
"""Removes a close event callback"""
|
||||||
ret = libvirtmod.virConnectUnregisterCloseCallback(self._o)
|
ret = libvirtmod.virConnectUnregisterCloseCallback(self._o)
|
||||||
if ret == -1: raise libvirtError ('virConnectUnregisterCloseCallback() failed', conn=self)
|
if ret == -1:
|
||||||
|
raise libvirtError('virConnectUnregisterCloseCallback() failed', conn=self)
|
||||||
|
|
||||||
def registerCloseCallback(self, cb, opaque):
|
def registerCloseCallback(self, cb, opaque):
|
||||||
"""Adds a close event callback, providing a notification
|
"""Adds a close event callback, providing a notification
|
||||||
@ -604,7 +611,8 @@
|
|||||||
libvirtd daemon. Any domains marked for auto destroy will
|
libvirtd daemon. Any domains marked for auto destroy will
|
||||||
block attempts at migration, save-to-file, or snapshots. """
|
block attempts at migration, save-to-file, or snapshots. """
|
||||||
ret = libvirtmod.virDomainCreateXMLWithFiles(self._o, xmlDesc, files, flags)
|
ret = libvirtmod.virDomainCreateXMLWithFiles(self._o, xmlDesc, files, flags)
|
||||||
if ret is None:raise libvirtError('virDomainCreateXMLWithFiles() failed', conn=self)
|
if ret is None:
|
||||||
|
raise libvirtError('virDomainCreateXMLWithFiles() failed', conn=self)
|
||||||
__tmp = virDomain(self, _obj=ret)
|
__tmp = virDomain(self, _obj=ret)
|
||||||
return __tmp
|
return __tmp
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
return retlist
|
return retlist
|
||||||
|
|
||||||
|
|
||||||
def listAllCheckpoints(self, flags=0):
|
def listAllCheckpoints(self, flags=0):
|
||||||
"""List all checkpoints and returns a list of checkpoint objects"""
|
"""List all checkpoints and returns a list of checkpoint objects"""
|
||||||
ret = libvirtmod.virDomainListAllCheckpoints(self._o, flags)
|
ret = libvirtmod.virDomainListAllCheckpoints(self._o, flags)
|
||||||
@ -23,7 +22,6 @@
|
|||||||
|
|
||||||
return retlist
|
return retlist
|
||||||
|
|
||||||
|
|
||||||
def createWithFiles(self, files, flags=0):
|
def createWithFiles(self, files, flags=0):
|
||||||
"""Launch a defined domain. If the call succeeds the domain moves from the
|
"""Launch a defined domain. If the call succeeds the domain moves from the
|
||||||
defined to the running domains pools.
|
defined to the running domains pools.
|
||||||
@ -58,30 +56,35 @@
|
|||||||
If the VIR_DOMAIN_START_FORCE_BOOT flag is set, then any managed save
|
If the VIR_DOMAIN_START_FORCE_BOOT flag is set, then any managed save
|
||||||
file for this domain is discarded, and the domain boots from scratch. """
|
file for this domain is discarded, and the domain boots from scratch. """
|
||||||
ret = libvirtmod.virDomainCreateWithFiles(self._o, files, flags)
|
ret = libvirtmod.virDomainCreateWithFiles(self._o, files, flags)
|
||||||
if ret == -1: raise libvirtError ('virDomainCreateWithFiles() failed', dom=self)
|
if ret == -1:
|
||||||
|
raise libvirtError('virDomainCreateWithFiles() failed', dom=self)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def fsFreeze(self, mountpoints=None, flags=0):
|
def fsFreeze(self, mountpoints=None, flags=0):
|
||||||
"""Freeze specified filesystems within the guest """
|
"""Freeze specified filesystems within the guest """
|
||||||
ret = libvirtmod.virDomainFSFreeze(self._o, mountpoints, flags)
|
ret = libvirtmod.virDomainFSFreeze(self._o, mountpoints, flags)
|
||||||
if ret == -1: raise libvirtError ('virDomainFSFreeze() failed', dom=self)
|
if ret == -1:
|
||||||
|
raise libvirtError('virDomainFSFreeze() failed', dom=self)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def fsThaw(self, mountpoints=None, flags=0):
|
def fsThaw(self, mountpoints=None, flags=0):
|
||||||
"""Thaw specified filesystems within the guest """
|
"""Thaw specified filesystems within the guest """
|
||||||
ret = libvirtmod.virDomainFSThaw(self._o, mountpoints, flags)
|
ret = libvirtmod.virDomainFSThaw(self._o, mountpoints, flags)
|
||||||
if ret == -1: raise libvirtError ('virDomainFSThaw() failed', dom=self)
|
if ret == -1:
|
||||||
|
raise libvirtError('virDomainFSThaw() failed', dom=self)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def getTime(self, flags=0):
|
def getTime(self, flags=0):
|
||||||
"""Extract information about guest time """
|
"""Extract information about guest time """
|
||||||
ret = libvirtmod.virDomainGetTime(self._o, flags)
|
ret = libvirtmod.virDomainGetTime(self._o, flags)
|
||||||
if ret == None: raise libvirtError ('virDomainGetTime() failed', dom=self)
|
if ret == None:
|
||||||
|
raise libvirtError('virDomainGetTime() failed', dom=self)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def setTime(self, time=None, flags=0):
|
def setTime(self, time=None, flags=0):
|
||||||
"""Set guest time to the given value. @time is a dict containing
|
"""Set guest time to the given value. @time is a dict containing
|
||||||
'seconds' field for seconds and 'nseconds' field for nanoseconds """
|
'seconds' field for seconds and 'nseconds' field for nanoseconds """
|
||||||
ret = libvirtmod.virDomainSetTime(self._o, time, flags)
|
ret = libvirtmod.virDomainSetTime(self._o, time, flags)
|
||||||
if ret == -1: raise libvirtError ('virDomainSetTime() failed', dom=self)
|
if ret == -1:
|
||||||
|
raise libvirtError('virDomainSetTime() failed', dom=self)
|
||||||
return ret
|
return ret
|
||||||
|
@ -23,7 +23,8 @@
|
|||||||
self.cb = cb
|
self.cb = cb
|
||||||
cbData = {"stream": self, "cb": cb, "opaque": opaque}
|
cbData = {"stream": self, "cb": cb, "opaque": opaque}
|
||||||
ret = libvirtmod.virStreamEventAddCallback(self._o, events, cbData)
|
ret = libvirtmod.virStreamEventAddCallback(self._o, events, cbData)
|
||||||
if ret == -1: raise libvirtError ('virStreamEventAddCallback() failed')
|
if ret == -1:
|
||||||
|
raise libvirtError('virStreamEventAddCallback() failed')
|
||||||
|
|
||||||
def recvAll(self, handler, opaque):
|
def recvAll(self, handler, opaque):
|
||||||
"""Receive the entire data stream, sending the data to the
|
"""Receive the entire data stream, sending the data to the
|
||||||
@ -105,7 +106,8 @@
|
|||||||
the request would block, integer -2 is returned.
|
the request would block, integer -2 is returned.
|
||||||
"""
|
"""
|
||||||
ret = libvirtmod.virStreamRecv(self._o, nbytes)
|
ret = libvirtmod.virStreamRecv(self._o, nbytes)
|
||||||
if ret is None: raise libvirtError ('virStreamRecv() failed')
|
if ret is None:
|
||||||
|
raise libvirtError('virStreamRecv() failed')
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def send(self, data):
|
def send(self, data):
|
||||||
@ -123,7 +125,8 @@
|
|||||||
subsequent call.
|
subsequent call.
|
||||||
"""
|
"""
|
||||||
ret = libvirtmod.virStreamSend(self._o, data)
|
ret = libvirtmod.virStreamSend(self._o, data)
|
||||||
if ret == -1: raise libvirtError ('virStreamSend() failed')
|
if ret == -1:
|
||||||
|
raise libvirtError('virStreamSend() failed')
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def recvHole(self, flags=0):
|
def recvHole(self, flags=0):
|
||||||
@ -133,7 +136,8 @@
|
|||||||
files. This is the counterpart to sendHole.
|
files. This is the counterpart to sendHole.
|
||||||
"""
|
"""
|
||||||
ret = libvirtmod.virStreamRecvHole(self._o, flags)
|
ret = libvirtmod.virStreamRecvHole(self._o, flags)
|
||||||
if ret is None: raise libvirtError ('virStreamRecvHole() failed')
|
if ret is None:
|
||||||
|
raise libvirtError('virStreamRecvHole() failed')
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def sendHole(self, length, flags=0):
|
def sendHole(self, length, flags=0):
|
||||||
@ -144,7 +148,8 @@
|
|||||||
needless copy of empty file space.
|
needless copy of empty file space.
|
||||||
"""
|
"""
|
||||||
ret = libvirtmod.virStreamSendHole(self._o, length, flags)
|
ret = libvirtmod.virStreamSendHole(self._o, length, flags)
|
||||||
if ret == -1: raise libvirtError('virStreamSendHole() failed')
|
if ret == -1:
|
||||||
|
raise libvirtError('virStreamSendHole() failed')
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def recvFlags(self, nbytes, flags=0):
|
def recvFlags(self, nbytes, flags=0):
|
||||||
@ -162,7 +167,8 @@
|
|||||||
the request would block, integer -2 is returned.
|
the request would block, integer -2 is returned.
|
||||||
"""
|
"""
|
||||||
ret = libvirtmod.virStreamRecvFlags(self._o, nbytes, flags)
|
ret = libvirtmod.virStreamRecvFlags(self._o, nbytes, flags)
|
||||||
if ret is None: raise libvirtError ('virStreamRecvFlags() failed')
|
if ret is None:
|
||||||
|
raise libvirtError('virStreamRecvFlags() failed')
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def sparseRecvAll(self, handler, holeHandler, opaque):
|
def sparseRecvAll(self, handler, holeHandler, opaque):
|
||||||
|
@ -78,6 +78,7 @@ class libvirtError(Exception):
|
|||||||
return None
|
return None
|
||||||
return self.err[8]
|
return self.err[8]
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# register the libvirt global error handler
|
# register the libvirt global error handler
|
||||||
#
|
#
|
||||||
@ -88,9 +89,11 @@ def registerErrorHandler(f, ctx):
|
|||||||
Returns 1 in case of success."""
|
Returns 1 in case of success."""
|
||||||
return libvirtmod.virRegisterErrorHandler(f, ctx)
|
return libvirtmod.virRegisterErrorHandler(f, ctx)
|
||||||
|
|
||||||
|
|
||||||
def openAuth(uri, auth, flags=0):
|
def openAuth(uri, auth, flags=0):
|
||||||
ret = libvirtmod.virConnectOpenAuth(uri, auth, flags)
|
ret = libvirtmod.virConnectOpenAuth(uri, auth, flags)
|
||||||
if ret is None:raise libvirtError('virConnectOpenAuth() failed')
|
if ret is None:
|
||||||
|
raise libvirtError('virConnectOpenAuth() failed')
|
||||||
return virConnect(_obj=ret)
|
return virConnect(_obj=ret)
|
||||||
|
|
||||||
|
|
||||||
@ -113,7 +116,8 @@ def getVersion (name = None):
|
|||||||
ret = libvirtmod.virGetVersion()
|
ret = libvirtmod.virGetVersion()
|
||||||
else:
|
else:
|
||||||
ret = libvirtmod.virGetVersion(name)
|
ret = libvirtmod.virGetVersion(name)
|
||||||
if ret is None: raise libvirtError ("virGetVersion() failed")
|
if ret is None:
|
||||||
|
raise libvirtError("virGetVersion() failed")
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
@ -137,6 +141,7 @@ def _eventInvokeHandleCallback(watch, fd, event, opaque, opaquecompat=None):
|
|||||||
|
|
||||||
libvirtmod.virEventInvokeHandleCallback(watch, fd, event, callback, opaque)
|
libvirtmod.virEventInvokeHandleCallback(watch, fd, event, callback, opaque)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Invoke an EventTimeout callback
|
# Invoke an EventTimeout callback
|
||||||
#
|
#
|
||||||
@ -157,6 +162,7 @@ def _eventInvokeTimeoutCallback(timer, opaque, opaquecompat=None):
|
|||||||
|
|
||||||
libvirtmod.virEventInvokeTimeoutCallback(timer, callback, opaque)
|
libvirtmod.virEventInvokeTimeoutCallback(timer, callback, opaque)
|
||||||
|
|
||||||
|
|
||||||
def _dispatchEventHandleCallback(watch, fd, events, cbData):
|
def _dispatchEventHandleCallback(watch, fd, events, cbData):
|
||||||
cb = cbData["cb"]
|
cb = cbData["cb"]
|
||||||
opaque = cbData["opaque"]
|
opaque = cbData["opaque"]
|
||||||
@ -164,6 +170,7 @@ def _dispatchEventHandleCallback(watch, fd, events, cbData):
|
|||||||
cb(watch, fd, events, opaque)
|
cb(watch, fd, events, opaque)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def _dispatchEventTimeoutCallback(timer, cbData):
|
def _dispatchEventTimeoutCallback(timer, cbData):
|
||||||
cb = cbData["cb"]
|
cb = cbData["cb"]
|
||||||
opaque = cbData["opaque"]
|
opaque = cbData["opaque"]
|
||||||
@ -171,6 +178,7 @@ def _dispatchEventTimeoutCallback(timer, cbData):
|
|||||||
cb(timer, opaque)
|
cb(timer, opaque)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def virEventAddHandle(fd, events, cb, opaque):
|
def virEventAddHandle(fd, events, cb, opaque):
|
||||||
"""
|
"""
|
||||||
register a callback for monitoring file handle events
|
register a callback for monitoring file handle events
|
||||||
@ -188,9 +196,11 @@ def virEventAddHandle(fd, events, cb, opaque):
|
|||||||
"""
|
"""
|
||||||
cbData = {"cb": cb, "opaque": opaque}
|
cbData = {"cb": cb, "opaque": opaque}
|
||||||
ret = libvirtmod.virEventAddHandle(fd, events, cbData)
|
ret = libvirtmod.virEventAddHandle(fd, events, cbData)
|
||||||
if ret == -1: raise libvirtError ('virEventAddHandle() failed')
|
if ret == -1:
|
||||||
|
raise libvirtError('virEventAddHandle() failed')
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def virEventAddTimeout(timeout, cb, opaque):
|
def virEventAddTimeout(timeout, cb, opaque):
|
||||||
"""
|
"""
|
||||||
register a callback for a timer event
|
register a callback for a timer event
|
||||||
@ -208,7 +218,8 @@ def virEventAddTimeout(timeout, cb, opaque):
|
|||||||
"""
|
"""
|
||||||
cbData = {"cb": cb, "opaque": opaque}
|
cbData = {"cb": cb, "opaque": opaque}
|
||||||
ret = libvirtmod.virEventAddTimeout(timeout, cbData)
|
ret = libvirtmod.virEventAddTimeout(timeout, cbData)
|
||||||
if ret == -1: raise libvirtError ('virEventAddTimeout() failed')
|
if ret == -1:
|
||||||
|
raise libvirtError('virEventAddTimeout() failed')
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# Manually written part of python bindings for libvirt-qemu
|
# Manually written part of python bindings for libvirt-qemu
|
||||||
|
|
||||||
|
|
||||||
def _dispatchQemuMonitorEventCallback(conn, dom, event, seconds, micros, details, cbData):
|
def _dispatchQemuMonitorEventCallback(conn, dom, event, seconds, micros, details, cbData):
|
||||||
"""Dispatches events to python user qemu monitor event callbacks
|
"""Dispatches events to python user qemu monitor event callbacks
|
||||||
"""
|
"""
|
||||||
@ -9,16 +10,19 @@ def _dispatchQemuMonitorEventCallback(conn, dom, event, seconds, micros, details
|
|||||||
cb(conn, libvirt.virDomain(conn, _obj=dom), event, seconds, micros, details, opaque)
|
cb(conn, libvirt.virDomain(conn, _obj=dom), event, seconds, micros, details, opaque)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def qemuMonitorEventDeregister(conn, callbackID):
|
def qemuMonitorEventDeregister(conn, callbackID):
|
||||||
"""Removes a qemu monitor event callback. De-registering for a callback
|
"""Removes a qemu monitor event callback. De-registering for a callback
|
||||||
will disable delivery of this event type"""
|
will disable delivery of this event type"""
|
||||||
try:
|
try:
|
||||||
ret = libvirtmod_qemu.virConnectDomainQemuMonitorEventDeregister(conn._o, callbackID)
|
ret = libvirtmod_qemu.virConnectDomainQemuMonitorEventDeregister(conn._o, callbackID)
|
||||||
if ret == -1: raise libvirt.libvirtError ('virConnectDomainQemuMonitorEventDeregister() failed')
|
if ret == -1:
|
||||||
|
raise libvirt.libvirtError('virConnectDomainQemuMonitorEventDeregister() failed')
|
||||||
del conn.qemuMonitorEventCallbackID[callbackID]
|
del conn.qemuMonitorEventCallbackID[callbackID]
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def qemuMonitorEventRegister(conn, dom, event, cb, opaque, flags=0):
|
def qemuMonitorEventRegister(conn, dom, event, cb, opaque, flags=0):
|
||||||
"""Adds a qemu monitor event callback. Registering for a monitor
|
"""Adds a qemu monitor event callback. Registering for a monitor
|
||||||
callback will enable delivery of the events"""
|
callback will enable delivery of the events"""
|
||||||
|
@ -78,6 +78,7 @@ class Callback(object):
|
|||||||
self.impl.log.debug('callback %d close(), scheduling ff', self.iden)
|
self.impl.log.debug('callback %d close(), scheduling ff', self.iden)
|
||||||
self.impl.schedule_ff_callback(self.iden, self.opaque)
|
self.impl.schedule_ff_callback(self.iden, self.opaque)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# file descriptors
|
# file descriptors
|
||||||
#
|
#
|
||||||
@ -161,6 +162,7 @@ class Descriptor(object):
|
|||||||
self.update()
|
self.update()
|
||||||
return callback
|
return callback
|
||||||
|
|
||||||
|
|
||||||
class DescriptorDict(dict):
|
class DescriptorDict(dict):
|
||||||
'''Descriptors collection
|
'''Descriptors collection
|
||||||
|
|
||||||
@ -175,6 +177,7 @@ class DescriptorDict(dict):
|
|||||||
self[fd] = descriptor
|
self[fd] = descriptor
|
||||||
return descriptor
|
return descriptor
|
||||||
|
|
||||||
|
|
||||||
class FDCallback(Callback):
|
class FDCallback(Callback):
|
||||||
'''Callback for file descriptor (watcher)
|
'''Callback for file descriptor (watcher)
|
||||||
|
|
||||||
@ -197,6 +200,7 @@ class FDCallback(Callback):
|
|||||||
self.event = event
|
self.event = event
|
||||||
self.descriptor.update()
|
self.descriptor.update()
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# timeouts
|
# timeouts
|
||||||
#
|
#
|
||||||
@ -254,6 +258,7 @@ class TimeoutCallback(Callback):
|
|||||||
self.update(timeout=-1)
|
self.update(timeout=-1)
|
||||||
super(TimeoutCallback, self).close()
|
super(TimeoutCallback, self).close()
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# main implementation
|
# main implementation
|
||||||
#
|
#
|
||||||
@ -448,10 +453,13 @@ class virEventAsyncIOImpl(object):
|
|||||||
|
|
||||||
|
|
||||||
_current_impl = None
|
_current_impl = None
|
||||||
|
|
||||||
|
|
||||||
def getCurrentImpl():
|
def getCurrentImpl():
|
||||||
'''Return the current implementation, or None if not yet registered'''
|
'''Return the current implementation, or None if not yet registered'''
|
||||||
return _current_impl
|
return _current_impl
|
||||||
|
|
||||||
|
|
||||||
def virEventRegisterAsyncIOImpl(loop=None):
|
def virEventRegisterAsyncIOImpl(loop=None):
|
||||||
'''Arrange for libvirt's callbacks to be dispatched via asyncio event loop
|
'''Arrange for libvirt's callbacks to be dispatched via asyncio event loop
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ def get_libvirt_api_xml_path():
|
|||||||
sys.exit(proc.returncode)
|
sys.exit(proc.returncode)
|
||||||
return stdout.splitlines()[0]
|
return stdout.splitlines()[0]
|
||||||
|
|
||||||
|
|
||||||
# Path to the libvirt API XML file
|
# Path to the libvirt API XML file
|
||||||
if len(sys.argv) >= 3:
|
if len(sys.argv) >= 3:
|
||||||
xml = sys.argv[2]
|
xml = sys.argv[2]
|
||||||
@ -188,7 +189,6 @@ for cname in wantfunctions:
|
|||||||
name.endswith("Callback")):
|
name.endswith("Callback")):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
# virEvent APIs go into main 'libvirt' namespace not any class
|
# virEvent APIs go into main 'libvirt' namespace not any class
|
||||||
if name[0:8] == "virEvent":
|
if name[0:8] == "virEvent":
|
||||||
if name[-4:] == "Func":
|
if name[-4:] == "Func":
|
||||||
@ -231,7 +231,6 @@ for name in sorted(basicklassmap):
|
|||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
# All the error handling methods need special handling
|
# All the error handling methods need special handling
|
||||||
if klass == "libvirt":
|
if klass == "libvirt":
|
||||||
if func in ["CopyLastError", "DefaultErrorFunc",
|
if func in ["CopyLastError", "DefaultErrorFunc",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import libvirt
|
import libvirt
|
||||||
|
|
||||||
|
|
||||||
class TestLibvirtConn(unittest.TestCase):
|
class TestLibvirtConn(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.conn = libvirt.open("test:///default")
|
self.conn = libvirt.open("test:///default")
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import libvirt
|
import libvirt
|
||||||
|
|
||||||
|
|
||||||
class TestLibvirtDomain(unittest.TestCase):
|
class TestLibvirtDomain(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.conn = libvirt.open("test:///default")
|
self.conn = libvirt.open("test:///default")
|
||||||
|
Reference in New Issue
Block a user