[libvirt] [PATCH libvirt-python v3 00/40] Split python binding into separate repo

From: "Daniel P. Berrange" <berrange@redhat.com> This patch series is a followup to https://www.redhat.com/archives/libvir-list/2013-November/msg00712.html This series is what I consider ready to declare final, ready for the real GIT repo split to be done. Starting from libvirt GIT master as of commit bae383f29194b9c61f9ab245f493ce7d654868d1 Author: Daniel P. Berrange <berrange@redhat.com> Date: Fri Nov 22 14:32:23 2013 +0000 I did the following $ git clone libvirt libvirt-python $ cd libvirt-python $ git mv examples/python python/examples $ git mv examples/domain-events/events-python/event-test.py python/examples $ git commit $ git filter-branch --subdirectory-filter python --tag-name-filter cat -- --all $ git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d $ git reflog expire --expire=now --all $ git gc --prune=now Then applied the following 40 patches using git am -3 You should now have a repo that's a couple of MB in size, showing only the files from python/ dir, in the root. The tags have been re-written to show content from the python/ directory. All the GPG signatures from tags are removed, since they are invalid after rewriting history. This was previously agreed to be the right way to handle this. The build system uses python distutils instead of autoconf/automake. It still uses the code generator as before though, pulling the XML files from /usr/share/libvirt/api (or whever you installed libvirt, as indicated by pkg-config). created a simple autobuild.sh to do an end-to-end build, including the RPM generation. Or you can just do python setup.py build ('make' equiv) python setup.py test ('make check' equiv) python setup.py rpm ('make rpm' equiv) python setup.py clean ('make clean' equiv) Historically libvirt python only worked with the exact matching libvirt binary. With this series, it is now possible to compile against any version back to 0.9.11. It is not possible to go back further than this, since the libvirt-api.xml file we need was not installed into /usr/share prior to 0.9.11. As such I removed Doug's patches which dealt with 0.9.6->0.9.10 Fortunately it seems 0.9.11 is in fact sufficient for OpenStack's targetted distros. The full GIT tree is git clone git://fedorapeople.org/~berrange/libvirt-python-v9.git Please take a moment to examine this. Unless bugs are found, this GIT repo will be moved as-is onto libvirt.org GIT. For doing releases, the following process would be needed ...build and install the new libvirt release RPM first... $ cd libvirt-python.git $ git tag -s -m 'Release 1.2.0' v1.2.0 $ ./autobuild.sh $ git push master v1.2.0 Now the 'dist/libvirt-python-X.y.z.tar.gz' file should be copied to http://libvirt.org/sources/python/ and also uploaded to PyPI Distutils can do the upload, but is deprecated since it passes your passwd in cleartext over the net :-( Instead OpenStack guys recommend use of twine https://pypi.python.org/pypi/twine eg $ twine upload dist/libvirt-python-x.y.z.tar.gz Unfortunately 'twine' isn't in Fedora repos, but is easy to install it locally using 'pip install twine' Daniel Daniel P. Berrange (20): Remove obsolete Makefile.am Update generator for new code layout Update header file includes Import STREQ macro from libvirt Add decl of MIN macro Import gnulib's xalloc_oversized macro Import gnulib's ignore_value macro Import code annotation macros from libvirt Import VIR_ALLOC / VIR_ALLOC_N / VIR_REALLOC_N functions Remove use of virStrcpyStatic Import VIR_FORCE_CLOSE macro from libvirt Add build/ to python module path for sanitytest.py Add execute permission for sanitytest.py Setup distutils build system VIR_DOMAIN_EVENT_ID_BALLOON_CHANGED appeared in 0.10.0 virDomainQemuAgentCommand appeared in 0.10.0 VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK appeared in 1.0.0 VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED appeared in 1.1.1 Relax min required libvirt to version 0.9.11 Ensure API overrides only used if API exists Doug Goldstein (20): Import LIBVIR_CHECK_VERSION macro from libvirt Import some virTypedParams* APIs from libvirt Break generator.py to be called per module Create array of modules to be built Don't build LXC module when building less than 1.0.2 virDomainListAllSnapshots API appeared in 0.9.13 virConnectListAllDomains API appeared in 0.9.13 virDomainSnapshotListAllChildren API appeared in 0.9.13 virConnect{Unr,R}egisterCloseCallback API appeared in 0.10.0 virDomainPinEmulator and virDomainGetEmulatorPinInfo APIs appeared in 0.10.0 virConnectListAll* APIs appeared in 0.10.2 virNode{Get,Set}MemoryParameters API appeared in 0.10.2 virStoragePoolListAllVolumes API appeared in 0.10.2 virNodeGetCPUMap API appeared in 1.0.0 virDomainGetJobStats API appeared in 1.0.3 virDomainMigrateGetCompressionCache API appeared in 1.0.3 virTypedParams* API appeared in 1.0.2 and used in 1.1.0 virDomainMigrate3 and virDomainMigrateToURI3 appeared in 1.1.0 virDomainCreateXMLWithFiles and virDomainCreateWithFiles APIs appeared in 1.1.1 virConnectGetCPUModelNames API appeared in 1.1.3 .gitignore | 4 + AUTHORS.in | 12 ++ COPYING | 339 ++++++++++++++++++++++++++++++++ COPYING.LESSER | 502 ++++++++++++++++++++++++++++++++++++++++++++++++ MANIFEST.in | 35 ++++ Makefile.am | 173 ----------------- NEWS | 9 + autobuild.sh | 24 +++ examples/Makefile.am | 21 -- generator.py | 94 +++++---- libvirt-lxc-override.c | 9 +- libvirt-override.c | 222 ++++++++++++++------- libvirt-python.spec.in | 34 ++++ libvirt-qemu-override.c | 13 +- libvirt-utils.c | 186 ++++++++++++++++++ libvirt-utils.h | 209 ++++++++++++++++++++ sanitytest.py | 4 + setup.py | 296 ++++++++++++++++++++++++++++ typewrappers.c | 5 +- 19 files changed, 1866 insertions(+), 325 deletions(-) create mode 100644 .gitignore create mode 100644 AUTHORS.in create mode 100644 COPYING create mode 100644 COPYING.LESSER create mode 100644 MANIFEST.in delete mode 100644 Makefile.am create mode 100644 NEWS create mode 100755 autobuild.sh delete mode 100644 examples/Makefile.am create mode 100644 libvirt-python.spec.in create mode 100644 libvirt-utils.c create mode 100644 libvirt-utils.h mode change 100644 => 100755 sanitytest.py create mode 100644 setup.py -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> We are no longer using automake, so Makefile.am is obsolete Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- Makefile.am | 173 --------------------------------------------------- examples/Makefile.am | 21 ------- 2 files changed, 194 deletions(-) delete mode 100644 Makefile.am delete mode 100644 examples/Makefile.am diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index c9c2a8b..0000000 --- a/Makefile.am +++ /dev/null @@ -1,173 +0,0 @@ -# Makefile for libvirt python library - -## Copyright (C) 2005-2013 Red Hat, Inc. -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library. If not, see -## <http://www.gnu.org/licenses/>. - -INCLUDES = \ - $(PYTHON_INCLUDES) \ - -I$(top_builddir)/gnulib/lib \ - -I$(top_srcdir)/gnulib/lib \ - -I$(top_srcdir) \ - -I$(top_builddir)/src \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/util \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/include \ - $(GETTEXT_CPPFLAGS) - -AM_CFLAGS = $(WARN_CFLAGS) -AM_LDFLAGS = \ - $(RELRO_LDFLAGS) \ - $(NO_INDIRECT_LDFLAGS) \ - $(NULL) - -CLASSES_EXTRA = \ - libvirt-override-virConnect.py \ - libvirt-override-virDomain.py \ - libvirt-override-virDomainSnapshot.py \ - libvirt-override-virStoragePool.py \ - libvirt-override-virStream.py - -EXTRA_DIST = \ - generator.py \ - typewrappers.c \ - typewrappers.h \ - libvirt-override.c \ - libvirt-override.py \ - libvirt-override-api.xml \ - libvirt-lxc-override.c \ - libvirt-lxc-override-api.xml \ - libvirt-qemu-override.c \ - libvirt-qemu-override-api.xml \ - sanitytest.py \ - $(CLASSES_EXTRA) \ - $(DOCS) - -if WITH_PYTHON -mylibs = \ - $(top_builddir)/src/libvirt.la \ - $(top_builddir)/gnulib/lib/libgnu.la -myqemulibs = \ - $(top_builddir)/src/libvirt-qemu.la \ - $(top_builddir)/gnulib/lib/libgnu.la -mylxclibs = \ - $(top_builddir)/src/libvirt-lxc.la \ - $(top_builddir)/gnulib/lib/libgnu.la - -all-local: libvirt.py libvirt_qemu.py libvirt_lxc.py - -pyexec_LTLIBRARIES = libvirtmod.la libvirtmod_qemu.la libvirtmod_lxc.la - -libvirtmod_la_SOURCES = libvirt-override.c typewrappers.c -nodist_libvirtmod_la_SOURCES = libvirt.c libvirt.h -# Python <= 2.4 header files contain a redundant decl, hence we -# need extra flags here -libvirtmod_la_CFLAGS = $(WARN_CFLAGS) $(WARN_PYTHON_CFLAGS) - -libvirtmod_la_LDFLAGS = -module -avoid-version -shared \ - -L$(top_builddir)/src/.libs \ - $(AM_LDFLAGS) \ - $(CYGWIN_EXTRA_LDFLAGS) -libvirtmod_la_LIBADD = $(mylibs) \ - $(CYGWIN_EXTRA_LIBADD) $(CYGWIN_EXTRA_PYTHON_LIBADD) - -libvirtmod_qemu_la_SOURCES = libvirt-qemu-override.c typewrappers.c -nodist_libvirtmod_qemu_la_SOURCES = libvirt-qemu.c libvirt-qemu.h -# Python <= 2.4 header files contain a redundant decl, hence we -# need extra flags here -libvirtmod_qemu_la_CFLAGS = $(WARN_PYTHON_CFLAGS) - -libvirtmod_qemu_la_LDFLAGS = -module -avoid-version -shared \ - -L$(top_builddir)/src/.libs \ - $(AM_LDFLAGS) \ - $(CYGWIN_EXTRA_LDFLAGS) -libvirtmod_qemu_la_LIBADD = $(myqemulibs) \ - $(CYGWIN_EXTRA_LIBADD) $(CYGWIN_EXTRA_PYTHON_LIBADD) - -libvirtmod_lxc_la_SOURCES = libvirt-lxc-override.c typewrappers.c -nodist_libvirtmod_lxc_la_SOURCES = libvirt-lxc.c libvirt-lxc.h -# Python <= 2.4 header files contain a redundant decl, hence we -# need extra flags here -libvirtmod_lxc_la_CFLAGS = $(WARN_PYTHON_CFLAGS) - -libvirtmod_lxc_la_LDFLAGS = -module -avoid-version -shared \ - -L$(top_builddir)/src/.libs \ - $(AM_LDFLAGS) \ - $(CYGWIN_EXTRA_LDFLAGS) -libvirtmod_lxc_la_LIBADD = $(mylxclibs) \ - $(CYGWIN_EXTRA_LIBADD) $(CYGWIN_EXTRA_PYTHON_LIBADD) - -GENERATE = generator.py -API_DESC = $(top_srcdir)/docs/libvirt-api.xml \ - $(srcdir)/libvirt-override-api.xml -GENERATED= libvirt-export.c \ - libvirt.c \ - libvirt.h \ - libvirt.py - -QEMU_API_DESC = $(top_srcdir)/docs/libvirt-qemu-api.xml \ - $(srcdir)/libvirt-qemu-override-api.xml -QEMU_GENERATED= libvirt-qemu-export.c \ - libvirt-qemu.c \ - libvirt-qemu.h \ - libvirt_qemu.py - -LXC_API_DESC = $(top_srcdir)/docs/libvirt-lxc-api.xml \ - $(srcdir)/libvirt-lxc-override-api.xml -LXC_GENERATED= libvirt-lxc-export.c \ - libvirt-lxc.c \ - libvirt-lxc.h \ - libvirt_lxc.py - -$(GENERATE).stamp: $(srcdir)/$(GENERATE) \ - $(API_DESC) \ - $(QEMU_API_DESC) \ - $(LXC_API_DESC) \ - $(CLASSES_EXTRA) - $(AM_V_GEN)$(PYTHON) $(srcdir)/$(GENERATE) $(PYTHON) && \ - touch $@ - -$(GENERATED) $(QEMU_GENERATED) $(LXC_GENERATED): $(GENERATE).stamp - -$(libvirtmod_la_OBJECTS): $(GENERATED) -$(libvirtmod_qemu_la_OBJECTS): $(QEMU_GENERATED) -$(libvirtmod_lxc_la_OBJECTS): $(LXC_GENERATED) - -check-local: - $(AM_V_GEN)../run $(PYTHON) $(srcdir)/sanitytest.py - -install-data-local: - $(mkinstalldirs) $(DESTDIR)$(pyexecdir) - $(INSTALL) -m 0644 libvirt.py $(DESTDIR)$(pyexecdir) - $(INSTALL) -m 0644 libvirt_lxc.py $(DESTDIR)$(pyexecdir) - $(INSTALL) -m 0644 libvirt_qemu.py $(DESTDIR)$(pyexecdir) - -uninstall-local: - rm -f $(DESTDIR)$(pyexecdir)/libvirt.py - rm -f $(DESTDIR)$(pyexecdir)/libvirt_lxc.py - rm -f $(DESTDIR)$(pyexecdir)/libvirt_qemu.py - -CLEANFILES= $(GENERATED) $(QEMU_GENERATED) $(LXC_GENERATED) $(GENERATE).stamp \ - *.pyc - -else ! WITH_PYTHON -all: -endif ! WITH_PYTHON - -dummy: - -tests test: all dummy - -@(cd tests && $(MAKE) MAKEFLAGS+=--silent tests) diff --git a/examples/Makefile.am b/examples/Makefile.am deleted file mode 100644 index 7823c20..0000000 --- a/examples/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ -## Copyright (C) 2005-2013 Red Hat, Inc. -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library. If not, see -## <http://www.gnu.org/licenses/>. - -EXTRA_DIST= \ - README \ - consolecallback.py \ - topology.py \ - dominfo.py domrestore.py domsave.py domstart.py esxlist.py -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Change the generator.py to - Take XML API file names on command line - Generate data in build/ directory instead of cwd --- generator.py | 69 ++++++++++++++++++++++-------------------------------------- 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/generator.py b/generator.py index 20f5dff..9ea29a8 100755 --- a/generator.py +++ b/generator.py @@ -17,17 +17,10 @@ import re quiet=True -if __name__ == "__main__": - # launched as a script - srcPref = os.path.dirname(sys.argv[0]) - if len(sys.argv) > 1: - python = sys.argv[1] - else: - print "Python binary not specified" - sys.exit(1) -else: - # imported - srcPref = os.path.dirname(__file__) +coreapifile = sys.argv[1] +lxcapifile = sys.argv[2] +qemuapifile = sys.argv[3] + ####################################################################### # @@ -777,7 +770,7 @@ def print_function_wrapper(module, name, output, export, include): return 0 return 1 -def buildStubs(module): +def buildStubs(module, api_xml): global py_types global py_return_types global unknown_types @@ -799,26 +792,16 @@ def buildStubs(module): funcs_failed = qemu_functions_failed funcs_skipped = qemu_functions_skipped - api_xml = "%s-api.xml" % module - try: - f = open(os.path.join(srcPref,api_xml)) + f = open(api_xml) data = f.read() f.close() (parser, target) = getparser() parser.feed(data) parser.close() except IOError, msg: - try: - f = open(os.path.join(srcPref,"..","docs",api_xml)) - data = f.read() - f.close() - (parser, target) = getparser() - parser.feed(data) - parser.close() - except IOError, msg: - print file, ":", msg - sys.exit(1) + print file, ":", msg + sys.exit(1) n = len(funcs.keys()) if not quiet: @@ -828,7 +811,7 @@ def buildStubs(module): py_types['pythonObject'] = ('O', "pythonObject", "pythonObject", "pythonObject") try: - f = open(os.path.join(srcPref, override_api_xml)) + f = open(override_api_xml) data = f.read() f.close() (parser, target) = getparser() @@ -845,9 +828,9 @@ def buildStubs(module): failed = 0 skipped = 0 - header_file = "%s.h" % module - export_file = "%s-export.c" % module - wrapper_file = "%s.c" % module + header_file = "build/%s.h" % module + export_file = "build/%s-export.c" % module + wrapper_file = "build/%s.c" % module include = open(header_file, "w") include.write("/* Generated */\n\n") @@ -857,11 +840,10 @@ def buildStubs(module): wrapper = open(wrapper_file, "w") wrapper.write("/* Generated by generator.py */\n\n") - wrapper.write("#include <config.h>\n") wrapper.write("#include <Python.h>\n") wrapper.write("#include <libvirt/" + module + ".h>\n") wrapper.write("#include \"typewrappers.h\"\n") - wrapper.write("#include \"" + module + ".h\"\n\n") + wrapper.write("#include \"build/" + module + ".h\"\n\n") for function in funcs.keys(): # Skip the functions which are not for the module @@ -1283,15 +1265,14 @@ def buildWrappers(module): info = (0, func, name, ret, args, file, mod) function_classes['None'].append(info) - classes_file = "%s.py" % module - extra_file = os.path.join(srcPref, "%s-override.py" % module) + classes_file = "build/%s.py" % module + extra_file = "%s-override.py" % module extra = None classes = open(classes_file, "w") if os.path.exists(extra_file): extra = open(extra_file, "r") - classes.write("#! " + python + " -i\n") classes.write("#\n") classes.write("# WARNING WARNING WARNING WARNING\n") classes.write("#\n") @@ -1716,7 +1697,7 @@ def buildWrappers(module): classes.write("\n") # Append "<classname>.py" to class def, iff it exists try: - extra = open(os.path.join(srcPref,"libvirt-override-" + classname + ".py"), "r") + extra = open("libvirt-override-" + classname + ".py", "r") classes.write (" #\n") classes.write (" # %s methods from %s.py (hand coded)\n" % (classname,classname)) classes.write (" #\n") @@ -1746,14 +1727,13 @@ def qemuBuildWrappers(module): print "ERROR: only libvirt-qemu is supported" return None - extra_file = os.path.join(srcPref, "%s-override.py" % module) + extra_file = "%s-override.py" % module extra = None - fd = open("libvirt_qemu.py", "w") + fd = open("build/libvirt_qemu.py", "w") if os.path.exists(extra_file): extra = open(extra_file, "r") - fd.write("#! " + python + " -i\n") fd.write("#\n") fd.write("# WARNING WARNING WARNING WARNING\n") fd.write("#\n") @@ -1858,14 +1838,13 @@ def lxcBuildWrappers(module): print "ERROR: only libvirt-lxc is supported" return None - extra_file = os.path.join(srcPref, "%s-override.py" % module) + extra_file = "%s-override.py" % module extra = None - fd = open("libvirt_lxc.py", "w") + fd = open("build/libvirt_lxc.py", "w") if os.path.exists(extra_file): extra = open(extra_file, "r") - fd.write("#! " + python + " -i\n") fd.write("#\n") fd.write("# WARNING WARNING WARNING WARNING\n") fd.write("#\n") @@ -1964,11 +1943,13 @@ def lxcBuildWrappers(module): quiet = 0 -if buildStubs("libvirt") < 0: +if not os.path.exists("build"): + os.mkdir("build") +if buildStubs("libvirt", coreapifile) < 0: sys.exit(1) -if buildStubs("libvirt-lxc") < 0: +if buildStubs("libvirt-lxc", lxcapifile) < 0: sys.exit(1) -if buildStubs("libvirt-qemu") < 0: +if buildStubs("libvirt-qemu", qemuapifile) < 0: sys.exit(1) buildWrappers("libvirt") lxcBuildWrappers("libvirt-lxc") -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> We're no longer using automake, so <config.h> files are not required. Also remove of all libvirt internal util header files. Reference generated header files in build/ subdir. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- libvirt-lxc-override.c | 8 ++------ libvirt-override.c | 11 ++--------- libvirt-qemu-override.c | 7 ++----- typewrappers.c | 4 ---- 4 files changed, 6 insertions(+), 24 deletions(-) diff --git a/libvirt-lxc-override.c b/libvirt-lxc-override.c index f76ff4b..9b8cd4c 100644 --- a/libvirt-lxc-override.c +++ b/libvirt-lxc-override.c @@ -9,8 +9,6 @@ * Daniel Veillard <veillard@redhat.com> */ -#include <config.h> - /* Horrible kludge to work around even more horrible name-space pollution via Python.h. That file includes /usr/include/python2.5/pyconfig*.h, which has over 180 autoconf-style HAVE_* definitions. Shame on them. */ @@ -20,9 +18,7 @@ #include <libvirt/libvirt-lxc.h> #include <libvirt/virterror.h> #include "typewrappers.h" -#include "libvirt-lxc.h" -#include "viralloc.h" -#include "virfile.h" +#include "build/libvirt-lxc.h" #ifndef __CYGWIN__ extern void initlibvirtmod_lxc(void); @@ -108,7 +104,7 @@ error: * * ************************************************************************/ static PyMethodDef libvirtLxcMethods[] = { -#include "libvirt-lxc-export.c" +#include "build/libvirt-lxc-export.c" {(char *) "virDomainLxcOpenNamespace", libvirt_lxc_virDomainLxcOpenNamespace, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; diff --git a/libvirt-override.c b/libvirt-override.c index c60747d..a54ea34 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -9,8 +9,6 @@ * Daniel Veillard <veillard@redhat.com> */ -#include <config.h> - /* Horrible kludge to work around even more horrible name-space pollution via Python.h. That file includes /usr/include/python2.5/pyconfig*.h, which has over 180 autoconf-style HAVE_* definitions. Shame on them. */ @@ -23,12 +21,7 @@ #include <libvirt/libvirt.h> #include <libvirt/virterror.h> #include "typewrappers.h" -#include "libvirt.h" -#include "viralloc.h" -#include "virtypedparam.h" -#include "ignore-value.h" -#include "virutil.h" -#include "virstring.h" +#include "build/libvirt.h" #ifndef __CYGWIN__ extern void initlibvirtmod(void); @@ -7225,7 +7218,7 @@ cleanup: * * ************************************************************************/ static PyMethodDef libvirtMethods[] = { -#include "libvirt-export.c" +#include "build/libvirt-export.c" {(char *) "virGetVersion", libvirt_virGetVersion, METH_VARARGS, NULL}, {(char *) "virConnectGetVersion", libvirt_virConnectGetVersion, METH_VARARGS, NULL}, {(char *) "virConnectGetCPUModelNames", libvirt_virConnectGetCPUModelNames, METH_VARARGS, NULL}, diff --git a/libvirt-qemu-override.c b/libvirt-qemu-override.c index 6249031..4008b10 100644 --- a/libvirt-qemu-override.c +++ b/libvirt-qemu-override.c @@ -9,8 +9,6 @@ * Daniel Veillard <veillard@redhat.com> */ -#include <config.h> - /* Horrible kludge to work around even more horrible name-space pollution via Python.h. That file includes /usr/include/python2.5/pyconfig*.h, which has over 180 autoconf-style HAVE_* definitions. Shame on them. */ @@ -20,8 +18,7 @@ #include <libvirt/libvirt-qemu.h> #include <libvirt/virterror.h> #include "typewrappers.h" -#include "libvirt-qemu.h" -#include "viralloc.h" +#include "build/libvirt-qemu.h" #ifndef __CYGWIN__ extern void initlibvirtmod_qemu(void); @@ -119,7 +116,7 @@ libvirt_qemu_virDomainQemuAgentCommand(PyObject *self ATTRIBUTE_UNUSED, PyObject * * ************************************************************************/ static PyMethodDef libvirtQemuMethods[] = { -#include "libvirt-qemu-export.c" +#include "build/libvirt-qemu-export.c" {(char *) "virDomainQemuMonitorCommand", libvirt_qemu_virDomainQemuMonitorCommand, METH_VARARGS, NULL}, {(char *) "virDomainQemuAgentCommand", libvirt_qemu_virDomainQemuAgentCommand, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} diff --git a/typewrappers.c b/typewrappers.c index 9ba8790..ba02d6a 100644 --- a/typewrappers.c +++ b/typewrappers.c @@ -7,8 +7,6 @@ * Daniel Veillard <veillard@redhat.com> */ -#include <config.h> - /* Horrible kludge to work around even more horrible name-space pollution * via Python.h. That file includes /usr/include/python2.5/pyconfig*.h, * which has over 180 autoconf-style HAVE_* definitions. Shame on them. */ @@ -16,8 +14,6 @@ #include "typewrappers.h" -#include "viralloc.h" - #ifndef Py_CAPSULE_H typedef void(*PyCapsule_Destructor)(void *, void *); #endif -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- libvirt-override.c | 1 + libvirt-utils.h | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 libvirt-utils.h diff --git a/libvirt-override.c b/libvirt-override.c index a54ea34..f459602 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -22,6 +22,7 @@ #include <libvirt/virterror.h> #include "typewrappers.h" #include "build/libvirt.h" +#include "libvirt-utils.h" #ifndef __CYGWIN__ extern void initlibvirtmod(void); diff --git a/libvirt-utils.h b/libvirt-utils.h new file mode 100644 index 0000000..bec7346 --- /dev/null +++ b/libvirt-utils.h @@ -0,0 +1,27 @@ +/* + * libvirt-utils.h: misc helper APIs for python binding + * + * Copyright (C) 2013 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#ifndef __LIBVIRT_UTILS_H__ +# define __LIBVIRT_UTILS_H__ + +# define STREQ(a,b) (strcmp(a,b) == 0) + +#endif /* __LIBVIRT_UTILS_H__ */ -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- libvirt-utils.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt-utils.h b/libvirt-utils.h index bec7346..aed64e6 100644 --- a/libvirt-utils.h +++ b/libvirt-utils.h @@ -24,4 +24,8 @@ # define STREQ(a,b) (strcmp(a,b) == 0) +# ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) +# endif + #endif /* __LIBVIRT_UTILS_H__ */ -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- libvirt-override.c | 1 + libvirt-utils.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index f459602..cb78e0d 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -20,6 +20,7 @@ #include <Python.h> #include <libvirt/libvirt.h> #include <libvirt/virterror.h> +#include <stddef.h> #include "typewrappers.h" #include "build/libvirt.h" #include "libvirt-utils.h" diff --git a/libvirt-utils.h b/libvirt-utils.h index aed64e6..c1223fd 100644 --- a/libvirt-utils.h +++ b/libvirt-utils.h @@ -28,4 +28,19 @@ # define MIN(a,b) (((a) < (b)) ? (a) : (b)) # endif +/* Return 1 if an array of N objects, each of size S, cannot exist due + to size arithmetic overflow. S must be positive and N must be + nonnegative. This is a macro, not a function, so that it + works correctly even when SIZE_MAX < N. + + By gnulib convention, SIZE_MAX represents overflow in size + calculations, so the conservative dividend to use here is + SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value. + However, malloc (SIZE_MAX) fails on all known hosts where + sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for + exactly-SIZE_MAX allocations on such hosts; this avoids a test and + branch when S is known to be 1. */ +# define xalloc_oversized(n, s) \ + ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) + #endif /* __LIBVIRT_UTILS_H__ */ -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- libvirt-utils.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libvirt-utils.h b/libvirt-utils.h index c1223fd..961cc20 100644 --- a/libvirt-utils.h +++ b/libvirt-utils.h @@ -43,4 +43,15 @@ # define xalloc_oversized(n, s) \ ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) + +/* The __attribute__((__warn_unused_result__)) feature + is available in gcc versions 3.4 and newer, + while the typeof feature has been available since 2.7 at least. */ +# if 3 < __GNUC__ + (4 <= __GNUC_MINOR__) +# define ignore_value(x) \ + (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) +# else +# define ignore_value(x) ((void) (x)) +# endif + #endif /* __LIBVIRT_UTILS_H__ */ -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Import ATTRIBUTE_RETURN_CHECK, ATTRIBUTE_UNUSED & ATTRIBUTE_NONNULL macros Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- libvirt-utils.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/libvirt-utils.h b/libvirt-utils.h index 961cc20..f608eb4 100644 --- a/libvirt-utils.h +++ b/libvirt-utils.h @@ -54,4 +54,56 @@ # define ignore_value(x) ((void) (x)) # endif +# ifdef __GNUC__ +/** + * ATTRIBUTE_UNUSED: + * + * Macro to flag consciously unused parameters to functions + */ +# ifndef ATTRIBUTE_UNUSED +# define ATTRIBUTE_UNUSED __attribute__((__unused__)) +# endif + +/* gcc's handling of attribute nonnull is less than stellar - it does + * NOT improve diagnostics, and merely allows gcc to optimize away + * null code checks even when the caller manages to pass null in spite + * of the attribute, leading to weird crashes. Coverity, on the other + * hand, knows how to do better static analysis based on knowing + * whether a parameter is nonnull. Make this attribute conditional + * based on whether we are compiling for real or for analysis, while + * still requiring correct gcc syntax when it is turned off. See also + * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17308 */ +# ifndef ATTRIBUTE_NONNULL +# if __GNUC_PREREQ (3, 3) +# if STATIC_ANALYSIS +# define ATTRIBUTE_NONNULL(m) __attribute__((__nonnull__(m))) +# else +# define ATTRIBUTE_NONNULL(m) __attribute__(()) +# endif +# else +# define ATTRIBUTE_NONNULL(m) +# endif +# endif + +# ifndef ATTRIBUTE_RETURN_CHECK +# if __GNUC_PREREQ (3, 4) +# define ATTRIBUTE_RETURN_CHECK __attribute__((__warn_unused_result__)) +# else +# define ATTRIBUTE_RETURN_CHECK +# endif +# endif + +# else +# ifndef ATTRIBUTE_UNUSED +# define ATTRIBUTE_UNUSED +# endif +# ifndef ATTRIBUTE_NONNULL +# define ATTRIBUTE_NONNULL(m) +# endif +# ifndef ATTRIBUTE_RETURN_CHECK +# define ATTRIBUTE_RETURN_CHECK +# endif +# endif /* __GNUC__ */ + + #endif /* __LIBVIRT_UTILS_H__ */ -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Import the libvirt memory allocation functions, stripping the OOM testing and error reporting pieces. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- libvirt-lxc-override.c | 1 + libvirt-override.c | 106 +++++++++++++++++++++--------------------- libvirt-qemu-override.c | 1 + libvirt-utils.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++ libvirt-utils.h | 77 +++++++++++++++++++++++++++++++ typewrappers.c | 1 + 6 files changed, 253 insertions(+), 53 deletions(-) create mode 100644 libvirt-utils.c diff --git a/libvirt-lxc-override.c b/libvirt-lxc-override.c index 9b8cd4c..03b00b0 100644 --- a/libvirt-lxc-override.c +++ b/libvirt-lxc-override.c @@ -18,6 +18,7 @@ #include <libvirt/libvirt-lxc.h> #include <libvirt/virterror.h> #include "typewrappers.h" +#include "libvirt-utils.h" #include "build/libvirt-lxc.h" #ifndef __CYGWIN__ diff --git a/libvirt-override.c b/libvirt-override.c index cb78e0d..e0df994 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -166,7 +166,7 @@ setPyVirTypedParameter(PyObject *info, return NULL; } - if (VIR_ALLOC_N_QUIET(ret, size) < 0) { + if (VIR_ALLOC_N(ret, size) < 0) { PyErr_NoMemory(); return NULL; } @@ -506,7 +506,7 @@ libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -573,7 +573,7 @@ libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) sumparams = nparams * MIN(ncpus, 128); - if (VIR_ALLOC_N_QUIET(params, sumparams) < 0) { + if (VIR_ALLOC_N(params, sumparams) < 0) { error = PyErr_NoMemory(); goto error; } @@ -625,7 +625,7 @@ libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) if (nparams) { sumparams = nparams; - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) { + if (VIR_ALLOC_N(params, nparams) < 0) { error = PyErr_NoMemory(); goto error; } @@ -806,7 +806,7 @@ libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -854,7 +854,7 @@ libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -914,7 +914,7 @@ libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -990,7 +990,7 @@ libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1064,7 +1064,7 @@ libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1124,7 +1124,7 @@ libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1184,7 +1184,7 @@ libvirt_virDomainSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1244,7 +1244,7 @@ libvirt_virDomainGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1304,7 +1304,7 @@ libvirt_virDomainSetNumaParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1364,7 +1364,7 @@ libvirt_virDomainGetNumaParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1425,7 +1425,7 @@ libvirt_virDomainSetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1486,7 +1486,7 @@ libvirt_virDomainGetInterfaceParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1532,12 +1532,12 @@ libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED, if (i_retval < 0) return VIR_PY_INT_FAIL; - if (VIR_ALLOC_N_QUIET(cpuinfo, dominfo.nrVirtCpu) < 0) + if (VIR_ALLOC_N(cpuinfo, dominfo.nrVirtCpu) < 0) return PyErr_NoMemory(); cpumaplen = VIR_CPU_MAPLEN(cpunum); if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) || - VIR_ALLOC_N_QUIET(cpumap, dominfo.nrVirtCpu * cpumaplen) < 0) { + VIR_ALLOC_N(cpumap, dominfo.nrVirtCpu * cpumaplen) < 0) { error = PyErr_NoMemory(); goto cleanup; } @@ -1660,7 +1660,7 @@ libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED, } cpumaplen = VIR_CPU_MAPLEN(cpunum); - if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0) + if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); for (i = 0; i < tuple_size; i++) { @@ -1725,7 +1725,7 @@ libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED, } cpumaplen = VIR_CPU_MAPLEN(cpunum); - if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0) + if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); for (i = 0; i < tuple_size; i++) { @@ -1785,7 +1785,7 @@ libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED, cpumaplen = VIR_CPU_MAPLEN(cpunum); if (xalloc_oversized(dominfo.nrVirtCpu, cpumaplen) || - VIR_ALLOC_N_QUIET(cpumaps, dominfo.nrVirtCpu * cpumaplen) < 0) + VIR_ALLOC_N(cpumaps, dominfo.nrVirtCpu * cpumaplen) < 0) goto cleanup; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -1854,7 +1854,7 @@ libvirt_virDomainPinEmulator(PyObject *self ATTRIBUTE_UNUSED, if ((tuple_size = PyTuple_Size(pycpumap)) == -1) return NULL; - if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0) + if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); for (i = 0; i < tuple_size; i++) { @@ -1913,7 +1913,7 @@ libvirt_virDomainGetEmulatorPinInfo(PyObject *self ATTRIBUTE_UNUSED, cpumaplen = VIR_CPU_MAPLEN(cpunum); - if (VIR_ALLOC_N_QUIET(cpumap, cpumaplen) < 0) + if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -2189,7 +2189,7 @@ libvirt_virConnectOpenAuth(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { auth.ncredtype = PyList_Size(pycredtype); if (auth.ncredtype) { size_t i; - if (VIR_ALLOC_N_QUIET(auth.credtype, auth.ncredtype) < 0) + if (VIR_ALLOC_N(auth.credtype, auth.ncredtype) < 0) return VIR_PY_NONE; for (i = 0; i < auth.ncredtype; i++) { PyObject *val; @@ -2370,7 +2370,7 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(ids, c_retval) < 0) + if (VIR_ALLOC_N(ids, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -2462,7 +2462,7 @@ libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedDomains(conn, names, c_retval); @@ -2510,7 +2510,7 @@ libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) + if (VIR_ALLOC_N(names, c_retval) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virDomainSnapshotListNames(dom, names, c_retval, flags); @@ -2612,7 +2612,7 @@ libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) + if (VIR_ALLOC_N(names, c_retval) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virDomainSnapshotListChildrenNames(snap, names, c_retval, @@ -2946,7 +2946,7 @@ libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListNetworks(conn, names, c_retval); @@ -2992,7 +2992,7 @@ libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedNetworks(conn, names, c_retval); @@ -3201,7 +3201,7 @@ libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *arg return VIR_PY_NONE; conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); - if (VIR_ALLOC_N_QUIET(freeMems, maxCells) < 0) + if (VIR_ALLOC_N(freeMems, maxCells) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -3246,7 +3246,7 @@ libvirt_virNodeGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) return VIR_PY_NONE; if (nparams) { - if (VIR_ALLOC_N_QUIET(stats, nparams) < 0) + if (VIR_ALLOC_N(stats, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -3310,7 +3310,7 @@ libvirt_virNodeGetMemoryStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) return VIR_PY_NONE; if (nparams) { - if (VIR_ALLOC_N_QUIET(stats, nparams) < 0) + if (VIR_ALLOC_N(stats, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -3371,7 +3371,7 @@ libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListStoragePools(conn, names, c_retval); @@ -3425,7 +3425,7 @@ libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedStoragePools(conn, names, c_retval); @@ -3525,7 +3525,7 @@ libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virStoragePoolListVolumes(pool, names, c_retval); @@ -3787,7 +3787,7 @@ libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virNodeListDevices(conn, cap, names, c_retval, flags); @@ -3878,7 +3878,7 @@ libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virNodeDeviceListCaps(dev, names, c_retval); @@ -3998,7 +3998,7 @@ libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(uuids, c_retval) < 0) + if (VIR_ALLOC_N(uuids, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListSecrets(conn, uuids, c_retval); @@ -4218,7 +4218,7 @@ libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(uuids, c_retval) < 0) + if (VIR_ALLOC_N(uuids, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListNWFilters(conn, uuids, c_retval); @@ -4310,7 +4310,7 @@ libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListInterfaces(conn, names, c_retval); @@ -4365,7 +4365,7 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED, return VIR_PY_NONE; if (c_retval) { - if (VIR_ALLOC_N_QUIET(names, c_retval) < 0) + if (VIR_ALLOC_N(names, c_retval) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; c_retval = virConnectListDefinedInterfaces(conn, names, c_retval); @@ -4465,7 +4465,7 @@ libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED, size_t i; ncpus = PyList_Size(list); - if (VIR_ALLOC_N_QUIET(xmlcpus, ncpus) < 0) + if (VIR_ALLOC_N(xmlcpus, ncpus) < 0) return VIR_PY_INT_FAIL; for (i = 0; i < ncpus; i++) { @@ -4675,7 +4675,7 @@ libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -4736,7 +4736,7 @@ libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -4779,7 +4779,7 @@ libvirt_virDomainGetDiskErrors(PyObject *self ATTRIBUTE_UNUSED, ndisks = count; if (ndisks) { - if (VIR_ALLOC_N_QUIET(disks, ndisks) < 0) + if (VIR_ALLOC_N(disks, ndisks) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6651,7 +6651,7 @@ libvirt_virStreamRecv(PyObject *self ATTRIBUTE_UNUSED, } stream = PyvirStream_Get(pyobj_stream); - if (VIR_ALLOC_N_QUIET(buf, nbytes+1 > 0 ? nbytes+1 : 1) < 0) + if (VIR_ALLOC_N(buf, nbytes+1 > 0 ? nbytes+1 : 1) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6877,7 +6877,7 @@ libvirt_virDomainBlockPeek(PyObject *self ATTRIBUTE_UNUSED, domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); - if (VIR_ALLOC_N_QUIET(buf, size) < 0) + if (VIR_ALLOC_N(buf, size) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6914,7 +6914,7 @@ libvirt_virDomainMemoryPeek(PyObject *self ATTRIBUTE_UNUSED, domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); - if (VIR_ALLOC_N_QUIET(buf, size) < 0) + if (VIR_ALLOC_N(buf, size) < 0) return VIR_PY_NONE; LIBVIRT_BEGIN_ALLOW_THREADS; @@ -6974,7 +6974,7 @@ libvirt_virNodeSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -7034,7 +7034,7 @@ libvirt_virNodeGetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); - if (VIR_ALLOC_N_QUIET(params, nparams) < 0) + if (VIR_ALLOC_N(params, nparams) < 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -7142,7 +7142,7 @@ libvirt_virDomainCreateWithFiles(PyObject *self ATTRIBUTE_UNUSED, PyObject *args nfiles = PyList_Size(pyobj_files); - if (VIR_ALLOC_N_QUIET(files, nfiles) < 0) + if (VIR_ALLOC_N(files, nfiles) < 0) return PyErr_NoMemory(); for (i = 0; i < nfiles; i++) { @@ -7188,7 +7188,7 @@ libvirt_virDomainCreateXMLWithFiles(PyObject *self ATTRIBUTE_UNUSED, PyObject *a nfiles = PyList_Size(pyobj_files); - if (VIR_ALLOC_N_QUIET(files, nfiles) < 0) + if (VIR_ALLOC_N(files, nfiles) < 0) return PyErr_NoMemory(); for (i = 0; i < nfiles; i++) { diff --git a/libvirt-qemu-override.c b/libvirt-qemu-override.c index 4008b10..676e8bf 100644 --- a/libvirt-qemu-override.c +++ b/libvirt-qemu-override.c @@ -18,6 +18,7 @@ #include <libvirt/libvirt-qemu.h> #include <libvirt/virterror.h> #include "typewrappers.h" +#include "libvirt-utils.h" #include "build/libvirt-qemu.h" #ifndef __CYGWIN__ diff --git a/libvirt-utils.c b/libvirt-utils.c new file mode 100644 index 0000000..3d9bb9a --- /dev/null +++ b/libvirt-utils.c @@ -0,0 +1,120 @@ +/* + * libvirt-utils.c: misc helper APIs for python binding + * + * Copyright (C) 2013 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include <errno.h> +#include <stddef.h> +#include <stdlib.h> +#include "libvirt-utils.h" + +/** + * virAlloc: + * @ptrptr: pointer to pointer for address of allocated memory + * @size: number of bytes to allocate + * + * Allocate 'size' bytes of memory. Return the address of the + * allocated memory in 'ptrptr'. The newly allocated memory is + * filled with zeros. + * + * Returns -1 on failure to allocate, zero on success + */ +int virAlloc(void *ptrptr, + size_t size) +{ + *(void **)ptrptr = calloc(1, size); + if (*(void **)ptrptr == NULL) { + return -1; + } + return 0; +} + +/** + * virAllocN: + * @ptrptr: pointer to pointer for address of allocated memory + * @size: number of bytes to allocate + * @count: number of elements to allocate + * + * Allocate an array of memory 'count' elements long, + * each with 'size' bytes. Return the address of the + * allocated memory in 'ptrptr'. The newly allocated + * memory is filled with zeros. + * + * Returns -1 on failure to allocate, zero on success + */ +int virAllocN(void *ptrptr, + size_t size, + size_t count) +{ + *(void**)ptrptr = calloc(count, size); + if (*(void**)ptrptr == NULL) { + return -1; + } + return 0; +} + +/** + * virReallocN: + * @ptrptr: pointer to pointer for address of allocated memory + * @size: number of bytes to allocate + * @count: number of elements in array + * + * Resize the block of memory in 'ptrptr' to be an array of + * 'count' elements, each 'size' bytes in length. Update 'ptrptr' + * with the address of the newly allocated memory. On failure, + * 'ptrptr' is not changed and still points to the original memory + * block. Any newly allocated memory in 'ptrptr' is uninitialized. + * + * Returns -1 on failure to allocate, zero on success + */ +int virReallocN(void *ptrptr, + size_t size, + size_t count) +{ + void *tmp; + + if (xalloc_oversized(count, size)) { + errno = ENOMEM; + return -1; + } + tmp = realloc(*(void**)ptrptr, size * count); + if (!tmp && (size * count)) { + return -1; + } + *(void**)ptrptr = tmp; + return 0; +} + + +/** + * virFree: + * @ptrptr: pointer to pointer for address of memory to be freed + * + * Release the chunk of memory in the pointer pointed to by + * the 'ptrptr' variable. After release, 'ptrptr' will be + * updated to point to NULL. + */ +void virFree(void *ptrptr) +{ + int save_errno = errno; + + free(*(void**)ptrptr); + *(void**)ptrptr = NULL; + errno = save_errno; +} diff --git a/libvirt-utils.h b/libvirt-utils.h index f608eb4..30380a3 100644 --- a/libvirt-utils.h +++ b/libvirt-utils.h @@ -106,4 +106,81 @@ # endif /* __GNUC__ */ +/* Don't call these directly - use the macros below */ +int virAlloc(void *ptrptr, size_t size) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); +int virAllocN(void *ptrptr, size_t size, size_t count) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); +int virReallocN(void *ptrptr, size_t size, size_t count) + ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1); +void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); + +/** + * VIR_ALLOC: + * @ptr: pointer to hold address of allocated memory + * + * Allocate sizeof(*ptr) bytes of memory and store + * the address of allocated memory in 'ptr'. Fill the + * newly allocated memory with zeros. + * + * This macro is safe to use on arguments with side effects. + * + * Returns -1 on failure (with OOM error reported), 0 on success + */ +# define VIR_ALLOC(ptr) virAlloc(&(ptr), sizeof(*(ptr))) + +/** + * VIR_ALLOC_N: + * @ptr: pointer to hold address of allocated memory + * @count: number of elements to allocate + * + * Allocate an array of 'count' elements, each sizeof(*ptr) + * bytes long and store the address of allocated memory in + * 'ptr'. Fill the newly allocated memory with zeros. + * + * This macro is safe to use on arguments with side effects. + * + * Returns -1 on failure (with OOM error reported), 0 on success + */ +# define VIR_ALLOC_N(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count)) + +/** + * VIR_REALLOC_N: + * @ptr: pointer to hold address of allocated memory + * @count: number of elements to allocate + * + * Re-allocate an array of 'count' elements, each sizeof(*ptr) + * bytes long and store the address of allocated memory in + * 'ptr'. If 'ptr' grew, the added memory is uninitialized. + * + * This macro is safe to use on arguments with side effects. + * + * Returns -1 on failure (with OOM error reported), 0 on success + */ +# define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count)) + +/** + * VIR_FREE: + * @ptr: pointer holding address to be freed + * + * Free the memory stored in 'ptr' and update to point + * to NULL. + * + * This macro is safe to use on arguments with side effects. + */ +# if !STATIC_ANALYSIS +/* The ternary ensures that ptr is a pointer and not an integer type, + * while evaluating ptr only once. This gives us extra compiler + * safety when compiling under gcc. For now, we intentionally cast + * away const, since a number of callers safely pass const char *. + */ +# define VIR_FREE(ptr) virFree((void *) (1 ? (const void *) &(ptr) : (ptr))) +# else +/* The Coverity static analyzer considers the else path of the "?:" and + * flags the VIR_FREE() of the address of the address of memory as a + * RESOURCE_LEAK resulting in numerous false positives (eg, VIR_FREE(&ptr)) + */ +# define VIR_FREE(ptr) virFree((void *) &(ptr)) +# endif + #endif /* __LIBVIRT_UTILS_H__ */ diff --git a/typewrappers.c b/typewrappers.c index ba02d6a..d6cbbf1 100644 --- a/typewrappers.c +++ b/typewrappers.c @@ -13,6 +13,7 @@ #undef HAVE_PTHREAD_H #include "typewrappers.h" +#include "libvirt-utils.h" #ifndef Py_CAPSULE_H typedef void(*PyCapsule_Destructor)(void *, void *); -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- libvirt-override.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libvirt-override.c b/libvirt-override.c index e0df994..45c5652 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -189,7 +189,8 @@ setPyVirTypedParameter(PyObject *info, goto cleanup; } - ignore_value(virStrcpyStatic(temp->field, keystr)); + strncpy(temp->field, keystr, sizeof(*temp->field) - 1); + temp->field[sizeof(*temp->field) - 1] = '\0'; temp->type = params[i].type; switch (params[i].type) { -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Import the macro for safely closing file descriptors Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- libvirt-utils.c | 20 ++++++++++++++++++++ libvirt-utils.h | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/libvirt-utils.c b/libvirt-utils.c index 3d9bb9a..9c29a1c 100644 --- a/libvirt-utils.c +++ b/libvirt-utils.c @@ -22,6 +22,7 @@ #include <errno.h> #include <stddef.h> #include <stdlib.h> +#include <unistd.h> #include "libvirt-utils.h" /** @@ -118,3 +119,22 @@ void virFree(void *ptrptr) *(void**)ptrptr = NULL; errno = save_errno; } + + +int virFileClose(int *fdptr) +{ + int saved_errno = 0; + int rc = 0; + + saved_errno = errno; + + if (*fdptr < 0) + return 0; + + rc = close(*fdptr); + *fdptr = -1; + + errno = saved_errno; + + return rc; +} diff --git a/libvirt-utils.h b/libvirt-utils.h index 30380a3..795f678 100644 --- a/libvirt-utils.h +++ b/libvirt-utils.h @@ -183,4 +183,11 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); # define VIR_FREE(ptr) virFree((void *) &(ptr)) # endif +/* Don't call this directly - use the macro below */ +int virFileClose(int *fdptr) + ATTRIBUTE_RETURN_CHECK; + +# define VIR_FORCE_CLOSE(FD) \ + ignore_value(virFileClose(&(FD))) + #endif /* __LIBVIRT_UTILS_H__ */ -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> Add LIBVIR_CHECK_VERSION from libvirt upstream so that we can check the version of the library we are compiling against and support a range of libvirt versions. The macro was added to libvirt in 1.2.0 so we must provide it if its not defined. --- libvirt-utils.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libvirt-utils.h b/libvirt-utils.h index 795f678..447e81f 100644 --- a/libvirt-utils.h +++ b/libvirt-utils.h @@ -28,6 +28,16 @@ # define MIN(a,b) (((a) < (b)) ? (a) : (b)) # endif +/** + * libvirt.h provides this as of version 1.1.5, but we want to be able + * to support older versions of libvirt so copy and paste the macro from + * libvirt.h + */ +# ifndef LIBVIR_CHECK_VERSION +# define LIBVIR_CHECK_VERSION(major, minor, micro) \ + ((major) * 1000000 + (minor) * 1000 + (micro) <= LIBVIR_VERSION_NUMBER) +# endif + /* Return 1 if an array of N objects, each of size S, cannot exist due to size arithmetic overflow. S must be positive and N must be nonnegative. This is a macro, not a function, so that it -- 1.8.3.1

On 11/22/2013 09:22 AM, Daniel P. Berrange wrote:
From: Doug Goldstein <cardoe@cardoe.com>
Add LIBVIR_CHECK_VERSION from libvirt upstream so that we can check the version of the library we are compiling against and support a range of libvirt versions. The macro was added to libvirt in 1.2.0 so we must provide it if its not defined. --- libvirt-utils.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
+/** + * libvirt.h provides this as of version 1.1.5, but we want to be able
1.2.0, but we can clean up in a followup if necessary. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

From: Doug Goldstein <cardoe@cardoe.com> virTypedParamsClear() and virTypedParamsFree() were introduced in libvirt 1.0.2. In an effort to keep the code clean bring these two functions to libvirt-python if we're building against a version of libvirt that's older than 1.0.2 --- libvirt-utils.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ libvirt-utils.h | 6 ++++++ 2 files changed, 52 insertions(+) diff --git a/libvirt-utils.c b/libvirt-utils.c index 9c29a1c..d1f6e70 100644 --- a/libvirt-utils.c +++ b/libvirt-utils.c @@ -23,6 +23,7 @@ #include <stddef.h> #include <stdlib.h> #include <unistd.h> +#include <libvirt/libvirt.h> #include "libvirt-utils.h" /** @@ -138,3 +139,48 @@ int virFileClose(int *fdptr) return rc; } + +#if ! LIBVIR_CHECK_VERSION(1, 0, 2) +/** + * virTypedParamsClear: + * @params: the array of the typed parameters + * @nparams: number of parameters in the @params array + * + * Frees all memory used by string parameters. The memory occupied by @params + * is not free; use virTypedParamsFree if you want it to be freed too. + * + * Returns nothing. + */ +void +virTypedParamsClear(virTypedParameterPtr params, + int nparams) +{ + size_t i; + + if (!params) + return; + + for (i = 0; i < nparams; i++) { + if (params[i].type == VIR_TYPED_PARAM_STRING) + VIR_FREE(params[i].value.s); + } +} + +/** + * virTypedParamsFree: + * @params: the array of the typed parameters + * @nparams: number of parameters in the @params array + * + * Frees all memory used by string parameters and the memory occuiped by + * @params. + * + * Returns nothing. + */ +void +virTypedParamsFree(virTypedParameterPtr params, + int nparams) +{ + virTypedParamsClear(params, nparams); + VIR_FREE(params); +} +#endif /* ! LIBVIR_CHECK_VERSION(1, 0, 2) */ diff --git a/libvirt-utils.h b/libvirt-utils.h index 447e81f..0517f9c 100644 --- a/libvirt-utils.h +++ b/libvirt-utils.h @@ -200,4 +200,10 @@ int virFileClose(int *fdptr) # define VIR_FORCE_CLOSE(FD) \ ignore_value(virFileClose(&(FD))) +# if ! LIBVIR_CHECK_VERSION(1, 0, 2) +void virTypedParamsClear(virTypedParameterPtr params, int nparams); + +void virTypedParamsFree(virTypedParameterPtr params, int nparams); +# endif /* ! LIBVIR_CHECK_VERSION(1, 0, 2) */ + #endif /* __LIBVIRT_UTILS_H__ */ -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> The generated libvirt.py modules will be in the build/ directory, so santitytest.py must use that directory. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- sanitytest.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sanitytest.py b/sanitytest.py index ace6792..517054b 100644 --- a/sanitytest.py +++ b/sanitytest.py @@ -1,5 +1,9 @@ #!/usr/bin/python +import sys + +sys.path.insert(0, sys.argv[1]) + import libvirt globals = dir(libvirt) -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- sanitytest.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 sanitytest.py diff --git a/sanitytest.py b/sanitytest.py old mode 100644 new mode 100755 -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Create a setup.py for building libvirt python code and add supporting files Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- .gitignore | 4 + AUTHORS.in | 12 ++ COPYING | 339 +++++++++++++++++++++++++++++++++ COPYING.LESSER | 502 +++++++++++++++++++++++++++++++++++++++++++++++++ MANIFEST.in | 35 ++++ NEWS | 9 + autobuild.sh | 24 +++ libvirt-python.spec.in | 34 ++++ setup.py | 270 ++++++++++++++++++++++++++ 9 files changed, 1229 insertions(+) create mode 100644 .gitignore create mode 100644 AUTHORS.in create mode 100644 COPYING create mode 100644 COPYING.LESSER create mode 100644 MANIFEST.in create mode 100644 NEWS create mode 100755 autobuild.sh create mode 100644 libvirt-python.spec.in create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b859b49 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build/ +dist/ +MANIFEST +*~ diff --git a/AUTHORS.in b/AUTHORS.in new file mode 100644 index 0000000..cee329e --- /dev/null +++ b/AUTHORS.in @@ -0,0 +1,12 @@ + Libvirt Python Binding Authors + ============================== + +The libvirt python binding is maintained by the +libvirt development team, who can be contacted +at + + libvir-list@redhat.com + +The individual contributors are + +@AUTHORS@ diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/COPYING.LESSER b/COPYING.LESSER new file mode 100644 index 0000000..4362b49 --- /dev/null +++ b/COPYING.LESSER @@ -0,0 +1,502 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + <one line to give the library's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + <signature of Ty Coon>, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..d7bc545 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,35 @@ +include AUTHORS +include NEWS +include COPYING +include COPYING.LESSER +include ChangeLog +include examples/consolecallback.py +include examples/dominfo.py +include examples/domrestore.py +include examples/domsave.py +include examples/domstart.py +include examples/esxlist.py +include examples/event-test.py +include examples/topology.py +include generator.py +include libvirt-lxc-override-api.xml +include libvirt-lxc-override.c +include libvirt-override-api.xml +include libvirt-override.c +include libvirt-override.py +include libvirt-override-virConnect.py +include libvirt-override-virDomain.py +include libvirt-override-virDomainSnapshot.py +include libvirt-override-virStoragePool.py +include libvirt-override-virStream.py +include libvirt-python.spec +include libvirt-qemu-override-api.xml +include libvirt-qemu-override.c +include libvirt-utils.h +include libvirt-utils.c +include MANIFEST +include README +include sanitytest.py +include setup.py +include typewrappers.c +include typewrappers.h diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..b92cdf4 --- /dev/null +++ b/NEWS @@ -0,0 +1,9 @@ + Libvirt Python News + =================== + + +Release 1.2.0 +============= + + - Split off from main libvirt package + - Allow to compile against multiple versions of libvirt diff --git a/autobuild.sh b/autobuild.sh new file mode 100755 index 0000000..b3beaf1 --- /dev/null +++ b/autobuild.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +set -ve + +: ${AUTOBUILD_INSTALL_ROOT="$HOME/builder"} + +rm -rf MANIFEST dist build + + +python setup.py sdist + +python setup.py build +python setup.py test +python setup.py install --root="$AUTOBUILD_INSTALL_ROOT" + +type -p /usr/bin/rpmbuild > /dev/null 2>&1 || exit 0 + +if [ -n "$AUTOBUILD_COUNTER" ]; then + EXTRA_RELEASE=".auto$AUTOBUILD_COUNTER" +else + NOW=`date +"%s"` + EXTRA_RELEASE=".$USER$NOW" +fi +rpmbuild --nodeps --define "extra_release $EXTRA_RELEASE" -ta --clean dist/*.tar.gz diff --git a/libvirt-python.spec.in b/libvirt-python.spec.in new file mode 100644 index 0000000..e6c229f --- /dev/null +++ b/libvirt-python.spec.in @@ -0,0 +1,34 @@ + +Summary: The libvirt virtualization API +Name: libvirt-python +Version: @PY_VERSION@ +Release: 1%{?dist}%{?extra_release} +Source0: http://libvirt.org/sources/python/%{name}-%{version}.tar.gz +License: LGPLv2+ +Group: Development/Libraries +BuildRequires: libvirt-devel >= @C_VERSION@ +BuildRequires: python-devel + +%description +The libvirt-python package contains a module that permits applications +written in the Python programming language to use the interface +supplied by the libvirt library to use the virtualization capabilities +of recent versions of Linux (and other OSes). + +%prep +%setup + +%build +CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build + +%install +%{__python} setup.py install --skip-build --root=%{buildroot} +rm -f %{buildroot}%{_libdir}/python*/site-packages/*egg-info + +%files +%defattr(-,root,root) +%doc ChangeLog AUTHORS NEWS README COPYING COPYING.LESSER +%{_libdir}/python*/site-packages/libvirt.py* +%{_libdir}/python*/site-packages/libvirt_qemu.py* +%{_libdir}/python*/site-packages/libvirt_lxc.py* +%{_libdir}/python*/site-packages/libvirtmod* diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..4de9489 --- /dev/null +++ b/setup.py @@ -0,0 +1,270 @@ +#!/usr/bin/python + +from distutils.core import setup, Extension, Command +from distutils.command.build import build +from distutils.command.clean import clean +from distutils.command.sdist import sdist +from distutils.dir_util import remove_tree +from distutils.util import get_platform +from distutils.spawn import spawn +import distutils + +import sys +import datetime +import os +import os.path +import re +import time + +MIN_LIBVIRT = "0.10.2" + +# Hack to stop 'pip install' failing with error +# about missing 'build' dir. +if not os.path.exists("build"): + os.mkdir("build") + +pkgcfg = distutils.spawn.find_executable("pkg-config") + +if pkgcfg is None: + raise Exception("pkg-config binary is required to compile libvirt-python") + +spawn([pkgcfg, + "--print-errors", + "--atleast-version=%s" % MIN_LIBVIRT, + "libvirt"]) + +def get_pkgconfig_data(args, mod, required=True): + """Run pkg-config to and return content associated with it""" + f = os.popen("%s %s %s" % (pkgcfg, " ".join(args), mod)) + + line = f.readline() + if line is not None: + line = line.strip() + + if line is None or line == "": + if required: + raise Exception("Cannot determine '%s' from libvirt pkg-config file" % " ".join(args)) + else: + return "" + + return line + +ldflags = get_pkgconfig_data(["--libs-only-L"], "libvirt", False) +cflags = get_pkgconfig_data(["--cflags"], "libvirt", False) + +module = Extension('libvirtmod', + sources = ['libvirt-override.c', 'build/libvirt.c', 'typewrappers.c', 'libvirt-utils.c'], + libraries = [ "virt" ], + include_dirs = [ "." ]) +if cflags != "": + module.extra_compile_args.append(cflags) +if ldflags != "": + module.extra_link_args.append(ldflags) + + +moduleqemu = Extension('libvirtmod_qemu', + sources = ['libvirt-qemu-override.c', 'build/libvirt-qemu.c', 'typewrappers.c', 'libvirt-utils.c'], + libraries = [ "virt-qemu" ], + include_dirs = [ "." ]) +if cflags != "": + moduleqemu.extra_compile_args.append(cflags) +if ldflags != "": + moduleqemu.extra_link_args.append(ldflags) + +modulelxc = Extension('libvirtmod_lxc', + sources = ['libvirt-lxc-override.c', 'build/libvirt-lxc.c', 'typewrappers.c', 'libvirt-utils.c'], + libraries = [ "virt-lxc" ], + include_dirs = [ "." ]) +if cflags != "": + modulelxc.extra_compile_args.append(cflags) +if ldflags != "": + modulelxc.extra_link_args.append(ldflags) + +class my_build(build): + + def get_api_xml_files(self): + """Check with pkg-config that libvirt is present and extract + the API XML file paths we need from it""" + + libvirt_api = get_pkgconfig_data(["--variable", "libvirt_api"], "libvirt") + + offset = libvirt_api.index("-api.xml") + libvirt_qemu_api = libvirt_api[0:offset] + "-qemu-api.xml" + + offset = libvirt_api.index("-api.xml") + libvirt_lxc_api = libvirt_api[0:offset] + "-lxc-api.xml" + + return (libvirt_api, libvirt_qemu_api, libvirt_lxc_api) + + + def run(self): + apis = self.get_api_xml_files() + + self.spawn(["python", "generator.py", apis[0], apis[1], apis[2]]) + + build.run(self) + +class my_sdist(sdist): + user_options = sdist.user_options + + description = "Update libvirt-python.spec; build sdist-tarball." + + def initialize_options(self): + self.snapshot = None + sdist.initialize_options(self) + + def finalize_options(self): + if self.snapshot is not None: + self.snapshot = 1 + sdist.finalize_options(self) + + def gen_rpm_spec(self): + f1 = open('libvirt-python.spec.in', 'r') + f2 = open('libvirt-python.spec', 'w') + for line in f1: + f2.write(line + .replace('@PY_VERSION@', self.distribution.get_version()) + .replace('@C_VERSION@', MIN_LIBVIRT)) + f1.close() + f2.close() + + def gen_authors(self): + f = os.popen("git log --pretty=format:'%aN <%aE>'") + authors = [] + for line in f: + authors.append(" " + line.strip()) + + authors.sort(key=str.lower) + + f1 = open('AUTHORS.in', 'r') + f2 = open('AUTHORS', 'w') + for line in f1: + f2.write(line.replace('@AUTHORS@', "\n".join(authors))) + f1.close() + f2.close() + + + def gen_changelog(self): + f1 = os.popen("git log '--pretty=format:%H:%ct %an <%ae>%n%n%s%n%b%n'") + f2 = open("ChangeLog", 'w') + + for line in f1: + m = re.match(r'([a-f0-9]+):(\d+)\s(.*)', line) + if m: + t = time.gmtime(int(m.group(2))) + f2.write("%04d-%02d-%02d %s\n" % (t.tm_year, t.tm_mon, t.tm_mday, m.group(3))) + else: + if re.match(r'Signed-off-by', line): + continue + f2.write(" " + line.strip() + "\n") + + f1.close() + f2.close() + + + def run(self): + if not os.path.exists("build"): + os.mkdir("build") + + if os.path.exists(".git"): + try: + self.gen_rpm_spec() + self.gen_authors() + self.gen_changelog() + + sdist.run(self) + + finally: + files = ["libvirt-python.spec", + "AUTHORS", + "ChangeLog"] + for f in files: + if os.path.exists(f): + os.unlink(f) + else: + sdist.run(self) + +class my_rpm(Command): + user_options = [] + + description = "Build src and noarch rpms." + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + """ + Run sdist, then 'rpmbuild' the tar.gz + """ + + self.run_command('sdist') + os.system('rpmbuild -ta --clean dist/libvirt-python-%s.tar.gz' % + self.distribution.get_version()) + +class my_test(Command): + user_options = [ + ('build-base=', 'b', + "base directory for build library"), + ('build-platlib=', None, + "build directory for platform-specific distributions"), + ('plat-name=', 'p', + "platform name to build for, if supported " + "(default: %s)" % get_platform()), + ] + + description = "Run test suite." + + def initialize_options(self): + self.build_base = 'build' + self.build_platlib = None + self.plat_name = None + + def finalize_options(self): + if self.plat_name is None: + self.plat_name = get_platform() + + plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3]) + + if hasattr(sys, 'gettotalrefcount'): + plat_specifier += '-pydebug' + + if self.build_platlib is None: + self.build_platlib = os.path.join(self.build_base, + 'lib' + plat_specifier) + + def run(self): + """ + Run test suite + """ + + self.spawn(["python", "sanitytest.py", self.build_platlib]) + + +class my_clean(clean): + def run(self): + clean.run(self) + + if os.path.exists("build"): + remove_tree("build") + +setup(name = 'libvirt-python', + version = '1.2.0', + url = 'http://www.libvirt.org', + maintainer = 'Libvirt Maintainers', + maintainer_email = 'libvir-list@redhat.com', + description = 'The libvirt virtualization API', + ext_modules = [module, modulelxc, moduleqemu], + py_modules = ["libvirt", "libvirt_qemu", "libvirt_lxc"], + package_dir = { + '': 'build' + }, + cmdclass = { + 'build': my_build, + 'clean': my_clean, + 'sdist': my_sdist, + 'rpm': my_rpm, + 'test': my_test + }) -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> Since we don't always want to build all the modules, and there might be more modules added in the future but we want to retain backwards compatibility with older libvirts, change generator.py to be called once per module instead of with all modules at once. --- generator.py | 24 ++++++++++++------------ setup.py | 4 +++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/generator.py b/generator.py index 9ea29a8..1d8f8f3 100755 --- a/generator.py +++ b/generator.py @@ -17,11 +17,6 @@ import re quiet=True -coreapifile = sys.argv[1] -lxcapifile = sys.argv[2] -qemuapifile = sys.argv[3] - - ####################################################################### # # That part if purely the API acquisition phase from the @@ -1945,13 +1940,18 @@ def lxcBuildWrappers(module): quiet = 0 if not os.path.exists("build"): os.mkdir("build") -if buildStubs("libvirt", coreapifile) < 0: - sys.exit(1) -if buildStubs("libvirt-lxc", lxcapifile) < 0: + +if buildStubs(sys.argv[1], sys.argv[2]) < 0: sys.exit(1) -if buildStubs("libvirt-qemu", qemuapifile) < 0: + +if sys.argv[1] == "libvirt": + buildWrappers(sys.argv[1]) +elif sys.argv[1] == "libvirt-lxc": + lxcBuildWrappers(sys.argv[1]) +elif sys.argv[1] == "libvirt-qemu": + qemuBuildWrappers(sys.argv[1]) +else: + print "ERROR: unknown module %s" % sys.argv[1] sys.exit(1) -buildWrappers("libvirt") -lxcBuildWrappers("libvirt-lxc") -qemuBuildWrappers("libvirt-qemu") + sys.exit(0) diff --git a/setup.py b/setup.py index 4de9489..5b72b09 100644 --- a/setup.py +++ b/setup.py @@ -100,7 +100,9 @@ class my_build(build): def run(self): apis = self.get_api_xml_files() - self.spawn(["python", "generator.py", apis[0], apis[1], apis[2]]) + self.spawn(["python", "generator.py", "libvirt", apis[0]]) + self.spawn(["python", "generator.py", "libvirt-qemu", apis[1]]) + self.spawn(["python", "generator.py", "libvirt-lxc", apis[2]]) build.run(self) -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> Create an array of modules to be built to allow for flexibility to enable or disable some modules in the future and allow for additional modules to be added easily --- setup.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 5b72b09..d641fab 100644 --- a/setup.py +++ b/setup.py @@ -52,6 +52,9 @@ def get_pkgconfig_data(args, mod, required=True): ldflags = get_pkgconfig_data(["--libs-only-L"], "libvirt", False) cflags = get_pkgconfig_data(["--cflags"], "libvirt", False) +c_modules = [] +py_modules = [] + module = Extension('libvirtmod', sources = ['libvirt-override.c', 'build/libvirt.c', 'typewrappers.c', 'libvirt-utils.c'], libraries = [ "virt" ], @@ -61,6 +64,8 @@ if cflags != "": if ldflags != "": module.extra_link_args.append(ldflags) +c_modules.append(module) +py_modules.append("libvirt") moduleqemu = Extension('libvirtmod_qemu', sources = ['libvirt-qemu-override.c', 'build/libvirt-qemu.c', 'typewrappers.c', 'libvirt-utils.c'], @@ -71,6 +76,9 @@ if cflags != "": if ldflags != "": moduleqemu.extra_link_args.append(ldflags) +c_modules.append(moduleqemu) +py_modules.append("libvirt_qemu") + modulelxc = Extension('libvirtmod_lxc', sources = ['libvirt-lxc-override.c', 'build/libvirt-lxc.c', 'typewrappers.c', 'libvirt-utils.c'], libraries = [ "virt-lxc" ], @@ -80,6 +88,10 @@ if cflags != "": if ldflags != "": modulelxc.extra_link_args.append(ldflags) +c_modules.append(modulelxc) +py_modules.append("libvirt_lxc") + + class my_build(build): def get_api_xml_files(self): @@ -258,8 +270,8 @@ setup(name = 'libvirt-python', maintainer = 'Libvirt Maintainers', maintainer_email = 'libvir-list@redhat.com', description = 'The libvirt virtualization API', - ext_modules = [module, modulelxc, moduleqemu], - py_modules = ["libvirt", "libvirt_qemu", "libvirt_lxc"], + ext_modules = c_modules, + py_modules = py_modules, package_dir = { '': 'build' }, -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> The functions that the LXC module wraps did not appear until 1.0.2 so we can't build the module unless we're building against 1.0.2 or newer. --- setup.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index d641fab..bf32e2a 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ from distutils.command.sdist import sdist from distutils.dir_util import remove_tree from distutils.util import get_platform from distutils.spawn import spawn +from distutils.errors import DistutilsExecError import distutils import sys @@ -17,6 +18,7 @@ import re import time MIN_LIBVIRT = "0.10.2" +MIN_LIBVIRT_LXC = "1.0.2" # Hack to stop 'pip install' failing with error # about missing 'build' dir. @@ -33,6 +35,14 @@ spawn([pkgcfg, "--atleast-version=%s" % MIN_LIBVIRT, "libvirt"]) +have_libvirt_lxc=True +try: + spawn([pkgcfg, + "--atleast-version=%s" % MIN_LIBVIRT_LXC, + "libvirt"]) +except DistutilsExecError,e: + have_libvirt_lxc=False + def get_pkgconfig_data(args, mod, required=True): """Run pkg-config to and return content associated with it""" f = os.popen("%s %s %s" % (pkgcfg, " ".join(args), mod)) @@ -79,17 +89,18 @@ if ldflags != "": c_modules.append(moduleqemu) py_modules.append("libvirt_qemu") -modulelxc = Extension('libvirtmod_lxc', - sources = ['libvirt-lxc-override.c', 'build/libvirt-lxc.c', 'typewrappers.c', 'libvirt-utils.c'], - libraries = [ "virt-lxc" ], - include_dirs = [ "." ]) -if cflags != "": - modulelxc.extra_compile_args.append(cflags) -if ldflags != "": - modulelxc.extra_link_args.append(ldflags) +if have_libvirt_lxc: + modulelxc = Extension('libvirtmod_lxc', + sources = ['libvirt-lxc-override.c', 'build/libvirt-lxc.c', 'typewrappers.c', 'libvirt-utils.c'], + libraries = [ "virt-lxc" ], + include_dirs = [ "." ]) + if cflags != "": + modulelxc.extra_compile_args.append(cflags) + if ldflags != "": + modulelxc.extra_link_args.append(ldflags) -c_modules.append(modulelxc) -py_modules.append("libvirt_lxc") + c_modules.append(modulelxc) + py_modules.append("libvirt_lxc") class my_build(build): @@ -114,7 +125,8 @@ class my_build(build): self.spawn(["python", "generator.py", "libvirt", apis[0]]) self.spawn(["python", "generator.py", "libvirt-qemu", apis[1]]) - self.spawn(["python", "generator.py", "libvirt-lxc", apis[2]]) + if have_libvirt_lxc: + self.spawn(["python", "generator.py", "libvirt-lxc", apis[2]]) build.run(self) -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> --- libvirt-override.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index 45c5652..875329e 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -2543,6 +2543,7 @@ cleanup: return py_retval; } +#if LIBVIR_CHECK_VERSION(0, 9, 13) static PyObject * libvirt_virDomainListAllSnapshots(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -2588,6 +2589,7 @@ cleanup: VIR_FREE(snaps); return py_retval; } +#endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */ static PyObject * libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED, @@ -7323,7 +7325,9 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL}, {(char *) "virDomainGetJobStats", libvirt_virDomainGetJobStats, METH_VARARGS, NULL}, {(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 9, 13) {(char *) "virDomainListAllSnapshots", libvirt_virDomainListAllSnapshots, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */ {(char *) "virDomainSnapshotListChildrenNames", libvirt_virDomainSnapshotListChildrenNames, METH_VARARGS, NULL}, {(char *) "virDomainSnapshotListAllChildren", libvirt_virDomainSnapshotListAllChildren, METH_VARARGS, NULL}, {(char *) "virDomainRevertToSnapshot", libvirt_virDomainRevertToSnapshot, METH_VARARGS, NULL}, -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> --- libvirt-override.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index 875329e..fd16916 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -2394,6 +2394,7 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, return py_retval; } +#if LIBVIR_CHECK_VERSION(0, 9, 13) static PyObject * libvirt_virConnectListAllDomains(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -2440,6 +2441,7 @@ cleanup: VIR_FREE(doms); return py_retval; } +#endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */ static PyObject * libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED, @@ -7231,7 +7233,9 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth, METH_VARARGS, NULL}, {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL}, {(char *) "virConnectListDefinedDomains", libvirt_virConnectListDefinedDomains, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 9, 13) {(char *) "virConnectListAllDomains", libvirt_virConnectListAllDomains, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */ {(char *) "virConnectDomainEventRegister", libvirt_virConnectDomainEventRegister, METH_VARARGS, NULL}, {(char *) "virConnectDomainEventDeregister", libvirt_virConnectDomainEventDeregister, METH_VARARGS, NULL}, {(char *) "virConnectDomainEventRegisterAny", libvirt_virConnectDomainEventRegisterAny, METH_VARARGS, NULL}, -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> --- libvirt-override.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index fd16916..e3b781d 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -2648,6 +2648,7 @@ cleanup: return py_retval; } +#if LIBVIR_CHECK_VERSION(0, 9, 13) static PyObject * libvirt_virDomainSnapshotListAllChildren(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -2693,6 +2694,7 @@ cleanup: VIR_FREE(snaps); return py_retval; } +#endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */ static PyObject * libvirt_virDomainRevertToSnapshot(PyObject *self ATTRIBUTE_UNUSED, @@ -7333,7 +7335,9 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virDomainListAllSnapshots", libvirt_virDomainListAllSnapshots, METH_VARARGS, NULL}, #endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */ {(char *) "virDomainSnapshotListChildrenNames", libvirt_virDomainSnapshotListChildrenNames, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 9, 13) {(char *) "virDomainSnapshotListAllChildren", libvirt_virDomainSnapshotListAllChildren, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 9, 13) */ {(char *) "virDomainRevertToSnapshot", libvirt_virDomainRevertToSnapshot, METH_VARARGS, NULL}, {(char *) "virDomainGetBlockJobInfo", libvirt_virDomainGetBlockJobInfo, METH_VARARGS, NULL}, {(char *) "virDomainSetBlockIoTune", libvirt_virDomainSetBlockIoTune, METH_VARARGS, NULL}, -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> --- libvirt-override.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libvirt-override.c b/libvirt-override.c index e3b781d..49068ca 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -6455,7 +6455,7 @@ libvirt_virConnectDomainEventDeregisterAny(ATTRIBUTE_UNUSED PyObject * self, return py_retval; } - +#if LIBVIR_CHECK_VERSION(0, 10, 0) static void libvirt_virConnectCloseCallbackDispatch(virConnectPtr conn ATTRIBUTE_UNUSED, int reason, @@ -6559,6 +6559,7 @@ libvirt_virConnectUnregisterCloseCallback(ATTRIBUTE_UNUSED PyObject * self, py_retval = libvirt_intWrap(ret); return py_retval; } +#endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */ static void libvirt_virStreamEventFreeFunc(void *opaque) @@ -7242,8 +7243,10 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virConnectDomainEventDeregister", libvirt_virConnectDomainEventDeregister, METH_VARARGS, NULL}, {(char *) "virConnectDomainEventRegisterAny", libvirt_virConnectDomainEventRegisterAny, METH_VARARGS, NULL}, {(char *) "virConnectDomainEventDeregisterAny", libvirt_virConnectDomainEventDeregisterAny, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 10, 0) {(char *) "virConnectRegisterCloseCallback", libvirt_virConnectRegisterCloseCallback, METH_VARARGS, NULL}, {(char *) "virConnectUnregisterCloseCallback", libvirt_virConnectUnregisterCloseCallback, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */ {(char *) "virStreamEventAddCallback", libvirt_virStreamEventAddCallback, METH_VARARGS, NULL}, {(char *) "virStreamRecv", libvirt_virStreamRecv, METH_VARARGS, NULL}, {(char *) "virStreamSend", libvirt_virStreamSend, METH_VARARGS, NULL}, -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> --- libvirt-override.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index 49068ca..e14ca26 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -6185,6 +6185,8 @@ libvirt_virConnectDomainEventPMSuspendCallback(virConnectPtr conn ATTRIBUTE_UNUS return ret; } + +#if LIBVIR_CHECK_VERSION(0, 10, 0) static int libvirt_virConnectDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainPtr dom, @@ -6231,6 +6233,7 @@ libvirt_virConnectDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_ LIBVIRT_RELEASE_THREAD_STATE; return ret; } +#endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */ static int libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_UNUSED, @@ -6393,9 +6396,11 @@ libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self, case VIR_DOMAIN_EVENT_ID_PMSUSPEND: cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendCallback); break; +#if LIBVIR_CHECK_VERSION(0, 10, 0) case VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE: cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBalloonChangeCallback); break; +#endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */ case VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK: cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendDiskCallback); break; -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> --- libvirt-override.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index e14ca26..4b728ef 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -1824,6 +1824,7 @@ cleanup: } +#if LIBVIR_CHECK_VERSION(0, 10, 0) static PyObject * libvirt_virDomainPinEmulator(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -1938,6 +1939,7 @@ libvirt_virDomainGetEmulatorPinInfo(PyObject *self ATTRIBUTE_UNUSED, VIR_FREE(cpumap); return pycpumap; } +#endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */ /************************************************************************ @@ -7299,8 +7301,10 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu, METH_VARARGS, NULL}, {(char *) "virDomainPinVcpuFlags", libvirt_virDomainPinVcpuFlags, METH_VARARGS, NULL}, {(char *) "virDomainGetVcpuPinInfo", libvirt_virDomainGetVcpuPinInfo, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 10, 0) {(char *) "virDomainGetEmulatorPinInfo", libvirt_virDomainGetEmulatorPinInfo, METH_VARARGS, NULL}, {(char *) "virDomainPinEmulator", libvirt_virDomainPinEmulator, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */ {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools, METH_VARARGS, NULL}, {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL}, {(char *) "virConnectListAllStoragePools", libvirt_virConnectListAllStoragePools, METH_VARARGS, NULL}, -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- libvirt-qemu-override.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libvirt-qemu-override.c b/libvirt-qemu-override.c index 676e8bf..a8e8c09 100644 --- a/libvirt-qemu-override.c +++ b/libvirt-qemu-override.c @@ -82,6 +82,7 @@ libvirt_qemu_virDomainQemuMonitorCommand(PyObject *self ATTRIBUTE_UNUSED, return py_retval; } +#if LIBVIR_CHECK_VERSION(0, 10, 0) static PyObject * libvirt_qemu_virDomainQemuAgentCommand(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { @@ -111,6 +112,8 @@ libvirt_qemu_virDomainQemuAgentCommand(PyObject *self ATTRIBUTE_UNUSED, PyObject VIR_FREE(result); return py_retval; } +#endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */ + /************************************************************************ * * * The registration stuff * @@ -119,7 +122,9 @@ libvirt_qemu_virDomainQemuAgentCommand(PyObject *self ATTRIBUTE_UNUSED, PyObject static PyMethodDef libvirtQemuMethods[] = { #include "build/libvirt-qemu-export.c" {(char *) "virDomainQemuMonitorCommand", libvirt_qemu_virDomainQemuMonitorCommand, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 10, 0) {(char *) "virDomainQemuAgentCommand", libvirt_qemu_virDomainQemuAgentCommand, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */ {NULL, NULL, 0, NULL} }; -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> --- libvirt-override.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index 4b728ef..0311579 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -3024,6 +3024,7 @@ libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED, return py_retval; } +#if LIBVIR_CHECK_VERSION(0, 10, 2) static PyObject * libvirt_virConnectListAllNetworks(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -3070,6 +3071,7 @@ cleanup: VIR_FREE(nets); return py_retval; } +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ static PyObject * @@ -3465,6 +3467,7 @@ libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED, return py_retval; } +#if LIBVIR_CHECK_VERSION(0, 10, 2) static PyObject * libvirt_virConnectListAllStoragePools(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -3511,6 +3514,7 @@ cleanup: VIR_FREE(pools); return py_retval; } +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ static PyObject * libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED, @@ -3819,6 +3823,7 @@ libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED, return py_retval; } +#if LIBVIR_CHECK_VERSION(0, 10, 2) static PyObject * libvirt_virConnectListAllNodeDevices(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -3865,6 +3870,7 @@ cleanup: VIR_FREE(devices); return py_retval; } +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ static PyObject * libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED, @@ -4030,6 +4036,7 @@ libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED, return py_retval; } +#if LIBVIR_CHECK_VERSION(0, 10, 2) static PyObject * libvirt_virConnectListAllSecrets(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -4076,6 +4083,7 @@ cleanup: VIR_FREE(secrets); return py_retval; } +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ static PyObject * libvirt_virSecretGetValue(PyObject *self ATTRIBUTE_UNUSED, @@ -4250,6 +4258,7 @@ libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED, return py_retval; } +#if LIBVIR_CHECK_VERSION(0, 10, 2) static PyObject * libvirt_virConnectListAllNWFilters(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -4296,6 +4305,7 @@ cleanup: VIR_FREE(filters); return py_retval; } +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ static PyObject * libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED, @@ -4406,6 +4416,7 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED, } +#if LIBVIR_CHECK_VERSION(0, 10, 2) static PyObject * libvirt_virConnectListAllInterfaces(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -4452,6 +4463,7 @@ cleanup: VIR_FREE(ifaces); return py_retval; } +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ static PyObject * libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED, @@ -7272,7 +7284,9 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virConnGetLastError", libvirt_virConnGetLastError, METH_VARARGS, NULL}, {(char *) "virConnectListNetworks", libvirt_virConnectListNetworks, METH_VARARGS, NULL}, {(char *) "virConnectListDefinedNetworks", libvirt_virConnectListDefinedNetworks, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 10, 2) {(char *) "virConnectListAllNetworks", libvirt_virConnectListAllNetworks, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ {(char *) "virNetworkGetUUID", libvirt_virNetworkGetUUID, METH_VARARGS, NULL}, {(char *) "virNetworkGetUUIDString", libvirt_virNetworkGetUUIDString, METH_VARARGS, NULL}, {(char *) "virNetworkLookupByUUID", libvirt_virNetworkLookupByUUID, METH_VARARGS, NULL}, @@ -7307,7 +7321,9 @@ static PyMethodDef libvirtMethods[] = { #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */ {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools, METH_VARARGS, NULL}, {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 10, 2) {(char *) "virConnectListAllStoragePools", libvirt_virConnectListAllStoragePools, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ {(char *) "virStoragePoolGetAutostart", libvirt_virStoragePoolGetAutostart, METH_VARARGS, NULL}, {(char *) "virStoragePoolListVolumes", libvirt_virStoragePoolListVolumes, METH_VARARGS, NULL}, {(char *) "virStoragePoolListAllVolumes", libvirt_virStoragePoolListAllVolumes, METH_VARARGS, NULL}, @@ -7322,23 +7338,31 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virEventInvokeHandleCallback", libvirt_virEventInvokeHandleCallback, METH_VARARGS, NULL}, {(char *) "virEventInvokeTimeoutCallback", libvirt_virEventInvokeTimeoutCallback, METH_VARARGS, NULL}, {(char *) "virNodeListDevices", libvirt_virNodeListDevices, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 10, 2) {(char *) "virConnectListAllNodeDevices", libvirt_virConnectListAllNodeDevices, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ {(char *) "virNodeDeviceListCaps", libvirt_virNodeDeviceListCaps, METH_VARARGS, NULL}, {(char *) "virSecretGetUUID", libvirt_virSecretGetUUID, METH_VARARGS, NULL}, {(char *) "virSecretGetUUIDString", libvirt_virSecretGetUUIDString, METH_VARARGS, NULL}, {(char *) "virSecretLookupByUUID", libvirt_virSecretLookupByUUID, METH_VARARGS, NULL}, {(char *) "virConnectListSecrets", libvirt_virConnectListSecrets, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 10, 2) {(char *) "virConnectListAllSecrets", libvirt_virConnectListAllSecrets, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ {(char *) "virSecretGetValue", libvirt_virSecretGetValue, METH_VARARGS, NULL}, {(char *) "virSecretSetValue", libvirt_virSecretSetValue, METH_VARARGS, NULL}, {(char *) "virNWFilterGetUUID", libvirt_virNWFilterGetUUID, METH_VARARGS, NULL}, {(char *) "virNWFilterGetUUIDString", libvirt_virNWFilterGetUUIDString, METH_VARARGS, NULL}, {(char *) "virNWFilterLookupByUUID", libvirt_virNWFilterLookupByUUID, METH_VARARGS, NULL}, {(char *) "virConnectListNWFilters", libvirt_virConnectListNWFilters, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 10, 2) {(char *) "virConnectListAllNWFilters", libvirt_virConnectListAllNWFilters, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ {(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces, METH_VARARGS, NULL}, {(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 10, 2) {(char *) "virConnectListAllInterfaces", libvirt_virConnectListAllInterfaces, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ {(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU, METH_VARARGS, NULL}, {(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL}, {(char *) "virDomainGetJobStats", libvirt_virDomainGetJobStats, METH_VARARGS, NULL}, -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> --- libvirt-override.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index 0311579..c439403 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -6960,6 +6960,7 @@ cleanup: return py_retval; } +#if LIBVIR_CHECK_VERSION(0, 10, 2) static PyObject * libvirt_virNodeSetMemoryParameters(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -7079,6 +7080,7 @@ cleanup: virTypedParamsFree(params, nparams); return ret; } +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ static PyObject * libvirt_virNodeGetCPUMap(PyObject *self ATTRIBUTE_UNUSED, @@ -7386,8 +7388,10 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virDomainBlockPeek", libvirt_virDomainBlockPeek, METH_VARARGS, NULL}, {(char *) "virDomainMemoryPeek", libvirt_virDomainMemoryPeek, METH_VARARGS, NULL}, {(char *) "virDomainGetDiskErrors", libvirt_virDomainGetDiskErrors, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 10, 2) {(char *) "virNodeGetMemoryParameters", libvirt_virNodeGetMemoryParameters, METH_VARARGS, NULL}, {(char *) "virNodeSetMemoryParameters", libvirt_virNodeSetMemoryParameters, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ {(char *) "virNodeGetCPUMap", libvirt_virNodeGetCPUMap, METH_VARARGS, NULL}, {(char *) "virDomainCreateXMLWithFiles", libvirt_virDomainCreateXMLWithFiles, METH_VARARGS, NULL}, {(char *) "virDomainCreateWithFiles", libvirt_virDomainCreateWithFiles, METH_VARARGS, NULL}, -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> --- libvirt-override.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index c439403..1894c97 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -3569,6 +3569,7 @@ libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED, return py_retval; } +#if LIBVIR_CHECK_VERSION(0, 10, 2) static PyObject * libvirt_virStoragePoolListAllVolumes(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -3616,6 +3617,7 @@ cleanup: VIR_FREE(vols); return py_retval; } +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ static PyObject * @@ -7328,7 +7330,9 @@ static PyMethodDef libvirtMethods[] = { #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ {(char *) "virStoragePoolGetAutostart", libvirt_virStoragePoolGetAutostart, METH_VARARGS, NULL}, {(char *) "virStoragePoolListVolumes", libvirt_virStoragePoolListVolumes, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(0, 10, 2) {(char *) "virStoragePoolListAllVolumes", libvirt_virStoragePoolListAllVolumes, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ {(char *) "virStoragePoolGetInfo", libvirt_virStoragePoolGetInfo, METH_VARARGS, NULL}, {(char *) "virStorageVolGetInfo", libvirt_virStorageVolGetInfo, METH_VARARGS, NULL}, {(char *) "virStoragePoolGetUUID", libvirt_virStoragePoolGetUUID, METH_VARARGS, NULL}, -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> --- libvirt-override.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index 1894c97..1c9d506 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -6251,6 +6251,7 @@ libvirt_virConnectDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_ } #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */ +#if LIBVIR_CHECK_VERSION(1, 0, 0) static int libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainPtr dom, @@ -6297,6 +6298,7 @@ libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_ LIBVIRT_RELEASE_THREAD_STATE; return ret; } +#endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */ static int libvirt_virConnectDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED, @@ -6417,9 +6419,11 @@ libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self, cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventBalloonChangeCallback); break; #endif /* LIBVIR_CHECK_VERSION(0, 10, 0) */ +#if LIBVIR_CHECK_VERSION(1, 0, 0) case VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK: cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendDiskCallback); break; +#endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */ case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED: cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDeviceRemovedCallback); break; -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> --- libvirt-override.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libvirt-override.c b/libvirt-override.c index 1c9d506..173510e 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -419,12 +419,14 @@ cleanup: */ static int getPyNodeCPUCount(virConnectPtr conn) { - int i_retval; + int i_retval = -1; virNodeInfo nodeinfo; +#if LIBVIR_CHECK_VERSION(1, 0, 0) LIBVIRT_BEGIN_ALLOW_THREADS; i_retval = virNodeGetCPUMap(conn, NULL, NULL, 0); LIBVIRT_END_ALLOW_THREADS; +#endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */ if (i_retval < 0) { /* fallback: use nodeinfo */ @@ -7088,6 +7090,7 @@ cleanup: } #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ +#if LIBVIR_CHECK_VERSION(1, 0, 0) static PyObject * libvirt_virNodeGetCPUMap(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -7156,6 +7159,7 @@ error: ret = NULL; goto cleanup; } +#endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */ static PyObject * @@ -7400,7 +7404,9 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virNodeGetMemoryParameters", libvirt_virNodeGetMemoryParameters, METH_VARARGS, NULL}, {(char *) "virNodeSetMemoryParameters", libvirt_virNodeSetMemoryParameters, METH_VARARGS, NULL}, #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ +#if LIBVIR_CHECK_VERSION(1, 0, 0) {(char *) "virNodeGetCPUMap", libvirt_virNodeGetCPUMap, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */ {(char *) "virDomainCreateXMLWithFiles", libvirt_virDomainCreateXMLWithFiles, METH_VARARGS, NULL}, {(char *) "virDomainCreateWithFiles", libvirt_virDomainCreateWithFiles, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> --- libvirt-override.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index 173510e..e24700b 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -4555,6 +4555,7 @@ libvirt_virDomainGetJobInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { return py_retval; } +#if LIBVIR_CHECK_VERSION(1, 0, 3) static PyObject * libvirt_virDomainGetJobStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { @@ -4595,6 +4596,7 @@ cleanup: else return VIR_PY_NONE; } +#endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */ static PyObject * libvirt_virDomainGetBlockJobInfo(PyObject *self ATTRIBUTE_UNUSED, @@ -7379,7 +7381,9 @@ static PyMethodDef libvirtMethods[] = { #endif /* LIBVIR_CHECK_VERSION(0, 10, 2) */ {(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU, METH_VARARGS, NULL}, {(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(1, 0, 3) {(char *) "virDomainGetJobStats", libvirt_virDomainGetJobStats, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */ {(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL}, #if LIBVIR_CHECK_VERSION(0, 9, 13) {(char *) "virDomainListAllSnapshots", libvirt_virDomainListAllSnapshots, METH_VARARGS, NULL}, -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> --- libvirt-override.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index e24700b..dc04152 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -6781,6 +6781,7 @@ libvirt_virDomainSendKey(PyObject *self ATTRIBUTE_UNUSED, return py_retval; } +#if LIBVIR_CHECK_VERSION(1, 0, 3) static PyObject * libvirt_virDomainMigrateGetCompressionCache(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -6807,6 +6808,7 @@ libvirt_virDomainMigrateGetCompressionCache(PyObject *self ATTRIBUTE_UNUSED, return libvirt_ulonglongWrap(cacheSize); } +#endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */ static PyObject * libvirt_virDomainMigrateGetMaxSpeed(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { @@ -7397,7 +7399,9 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virDomainSetBlockIoTune", libvirt_virDomainSetBlockIoTune, METH_VARARGS, NULL}, {(char *) "virDomainGetBlockIoTune", libvirt_virDomainGetBlockIoTune, METH_VARARGS, NULL}, {(char *) "virDomainSendKey", libvirt_virDomainSendKey, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(1, 0, 3) {(char *) "virDomainMigrateGetCompressionCache", libvirt_virDomainMigrateGetCompressionCache, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */ {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL}, {(char *) "virDomainMigrate3", libvirt_virDomainMigrate3, METH_VARARGS, NULL}, {(char *) "virDomainMigrateToURI3", libvirt_virDomainMigrateToURI3, METH_VARARGS, NULL}, -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> When building against versions of libvirt prior to 1.0.2, we can not provide wrappers for virTypedParams* APIs. In addition we don't need to have the helper APIs until 1.1.0 when the first API we wrap starts to use them. --- libvirt-override.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libvirt-override.c b/libvirt-override.c index dc04152..c345dfe 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -254,7 +254,9 @@ cleanup: return NULL; } - +/* While these appeared in libvirt in 1.0.2, we only + * need them in the python from 1.1.0 onwards */ +#if LIBVIR_CHECK_VERSION(1, 1, 0) typedef struct { const char *name; int type; @@ -406,6 +408,7 @@ cleanup: virTypedParamsFree(params, n); return ret; } +#endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */ /* -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> The functions virDomainMigrate3 and virDomainMigrateToURI3 were not added to libvirt until v1.1.0. --- libvirt-override.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index c345dfe..f4d799b 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -6838,6 +6838,7 @@ libvirt_virDomainMigrateGetMaxSpeed(PyObject *self ATTRIBUTE_UNUSED, PyObject *a return py_retval; } +#if LIBVIR_CHECK_VERSION(1, 1, 0) static PyObject * libvirt_virDomainMigrate3(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -6899,6 +6900,7 @@ libvirt_virDomainMigrateToURI3(PyObject *self ATTRIBUTE_UNUSED, virTypedParamsFree(params, nparams); return libvirt_intWrap(ret); } +#endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */ static PyObject * libvirt_virDomainBlockPeek(PyObject *self ATTRIBUTE_UNUSED, @@ -7406,8 +7408,10 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virDomainMigrateGetCompressionCache", libvirt_virDomainMigrateGetCompressionCache, METH_VARARGS, NULL}, #endif /* LIBVIR_CHECK_VERSION(1, 0, 3) */ {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(1, 1, 0) {(char *) "virDomainMigrate3", libvirt_virDomainMigrate3, METH_VARARGS, NULL}, {(char *) "virDomainMigrateToURI3", libvirt_virDomainMigrateToURI3, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */ {(char *) "virDomainBlockPeek", libvirt_virDomainBlockPeek, METH_VARARGS, NULL}, {(char *) "virDomainMemoryPeek", libvirt_virDomainMemoryPeek, METH_VARARGS, NULL}, {(char *) "virDomainGetDiskErrors", libvirt_virDomainGetDiskErrors, METH_VARARGS, NULL}, -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> virDomainCreateXMLWithFiles() and virDomainCreateWithFiles() were not added to libvirt until 1.1.1 --- libvirt-override.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index f4d799b..5f392c0 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -7171,6 +7171,7 @@ error: #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */ +#if LIBVIR_CHECK_VERSION(1, 1, 1) static PyObject * libvirt_virDomainCreateWithFiles(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval = NULL; @@ -7260,6 +7261,7 @@ cleanup: VIR_FREE(files); return py_retval; } +#endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */ /************************************************************************ @@ -7422,8 +7424,10 @@ static PyMethodDef libvirtMethods[] = { #if LIBVIR_CHECK_VERSION(1, 0, 0) {(char *) "virNodeGetCPUMap", libvirt_virNodeGetCPUMap, METH_VARARGS, NULL}, #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */ +#if LIBVIR_CHECK_VERSION(1, 1, 1) {(char *) "virDomainCreateXMLWithFiles", libvirt_virDomainCreateXMLWithFiles, METH_VARARGS, NULL}, {(char *) "virDomainCreateWithFiles", libvirt_virDomainCreateWithFiles, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */ {NULL, NULL, 0, NULL} }; -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> --- libvirt-override.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libvirt-override.c b/libvirt-override.c index 5f392c0..761b6a6 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -6307,6 +6307,7 @@ libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_ } #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */ +#if LIBVIR_CHECK_VERSION(1, 1, 1) static int libvirt_virConnectDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainPtr dom, @@ -6351,6 +6352,7 @@ libvirt_virConnectDomainEventDeviceRemovedCallback(virConnectPtr conn ATTRIBUTE_ LIBVIRT_RELEASE_THREAD_STATE; return ret; } +#endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */ static PyObject * libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self, @@ -6431,10 +6433,11 @@ libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self, cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventPMSuspendDiskCallback); break; #endif /* LIBVIR_CHECK_VERSION(1, 0, 0) */ +#if LIBVIR_CHECK_VERSION(1, 1, 1) case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED: cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDeviceRemovedCallback); break; - +#endif /* LIBVIR_CHECK_VERSION(1, 1, 1) */ case VIR_DOMAIN_EVENT_ID_LAST: break; } -- 1.8.3.1

From: Doug Goldstein <cardoe@cardoe.com> --- libvirt-override.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt-override.c b/libvirt-override.c index 761b6a6..3ef81dd 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -2279,6 +2279,7 @@ libvirt_virConnectGetVersion(PyObject *self ATTRIBUTE_UNUSED, return PyInt_FromLong(hvVersion); } +#if LIBVIR_CHECK_VERSION(1, 1, 3) static PyObject * libvirt_virConnectGetCPUModelNames(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) @@ -2330,6 +2331,7 @@ error: rv = VIR_PY_INT_FAIL; goto done; } +#endif /* LIBVIR_CHECK_VERSION(1, 1, 3) */ static PyObject * libvirt_virConnectGetLibVersion(PyObject *self ATTRIBUTE_UNUSED, @@ -7276,7 +7278,9 @@ static PyMethodDef libvirtMethods[] = { #include "build/libvirt-export.c" {(char *) "virGetVersion", libvirt_virGetVersion, METH_VARARGS, NULL}, {(char *) "virConnectGetVersion", libvirt_virConnectGetVersion, METH_VARARGS, NULL}, +#if LIBVIR_CHECK_VERSION(1, 1, 3) {(char *) "virConnectGetCPUModelNames", libvirt_virConnectGetCPUModelNames, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(1, 1, 3) */ {(char *) "virConnectGetLibVersion", libvirt_virConnectGetLibVersion, METH_VARARGS, NULL}, {(char *) "virConnectOpenAuth", libvirt_virConnectOpenAuth, METH_VARARGS, NULL}, {(char *) "virConnectListDomainsID", libvirt_virConnectListDomainsID, METH_VARARGS, NULL}, -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index bf32e2a..17b4722 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ import os.path import re import time -MIN_LIBVIRT = "0.10.2" +MIN_LIBVIRT = "0.9.11" MIN_LIBVIRT_LXC = "1.0.2" # Hack to stop 'pip install' failing with error -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Entries in the -overrides.xml files should only be recorded if the API also exists in the main API XML file. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- generator.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/generator.py b/generator.py index 1d8f8f3..ea5b8a1 100755 --- a/generator.py +++ b/generator.py @@ -27,6 +27,7 @@ import os import xml.sax debug = 0 +onlyOverrides = False def getparser(): # Attach parser to an unmarshalling object. return both objects. @@ -183,12 +184,18 @@ class docParser(xml.sax.handler.ContentHandler): def function(name, desc, ret, args, file, module, cond): + if onlyOverrides and name not in functions: + return functions[name] = (desc, ret, args, file, module, cond) def qemu_function(name, desc, ret, args, file, module, cond): + if onlyOverrides and name not in qemu_functions: + return qemu_functions[name] = (desc, ret, args, file, module, cond) def lxc_function(name, desc, ret, args, file, module, cond): + if onlyOverrides and name not in lxc_functions: + return lxc_functions[name] = (desc, ret, args, file, module, cond) def enum(type, name, value): @@ -213,16 +220,22 @@ def enum(type, name, value): elif value == 'VIR_DOMAIN_AFFECT_CONFIG': value = 2 if name[-5:] != '_LAST': + if onlyOverrides and name not in enums[type]: + return enums[type][name] = value def lxc_enum(type, name, value): if not lxc_enums.has_key(type): lxc_enums[type] = {} + if onlyOverrides and name not in lxc_enums[type]: + return lxc_enums[type][name] = value def qemu_enum(type, name, value): if not qemu_enums.has_key(type): qemu_enums[type] = {} + if onlyOverrides and name not in qemu_enums[type]: + return qemu_enums[type][name] = value @@ -791,6 +804,7 @@ def buildStubs(module, api_xml): f = open(api_xml) data = f.read() f.close() + onlyOverrides = False (parser, target) = getparser() parser.feed(data) parser.close() @@ -809,6 +823,7 @@ def buildStubs(module, api_xml): f = open(override_api_xml) data = f.read() f.close() + onlyOverrides = True (parser, target) = getparser() parser.feed(data) parser.close() -- 1.8.3.1

FYI in order to test this from a compilation pov I wrote a script which downloaded every older libvirt release and did a client only build and then built the python module against it. I'm attaching the script I used for this I built on Fedora 19 successfully back to 0.9.11 with this, though I had to patch libvirt itself in many cases to even build. Would appreciate someone testing this build on other platforms too. eg RHEL and/or Ubuntu in particular. You might have to tweak/skip some of the patches on other platforms, depending on glibc/kernel versions To run this, save all 4 attached files to a temporary directory. Run the python build and copy the resulting dist/libvirt-python-1.2.0.tar.gz file into the same temporary directory. Then just run build-many.sh When its done check the build/*libvirt-python*.log files to see if any compile warnings/failures occurred. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Daniel P. Berrange wrote:
FYI in order to test this from a compilation pov I wrote a script which downloaded every older libvirt release and did a client only build and then built the python module against it.
I'm attaching the script I used for this
I built on Fedora 19 successfully back to 0.9.11 with this, though I had to patch libvirt itself in many cases to even build. Would appreciate someone testing this build on other platforms too. eg RHEL and/or Ubuntu in particular. You might have to tweak/skip some of the patches on other platforms, depending on glibc/kernel versions
FYI, I build-tested this series against the libvirt versions I'm currently maintaining in various SUSE distros, which included 0.9.11, 1.0.2, 1.0.5, 1.1.2, and 1.1.4 (Factory). Regards, Jim

On Fri, Nov 22, 2013 at 04:22:24PM +0000, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
This patch series is a followup to
https://www.redhat.com/archives/libvir-list/2013-November/msg00712.html
This series is what I consider ready to declare final, ready for the real GIT repo split to be done.
I got a failure to apply the patch set: Applying: Import LIBVIR_CHECK_VERSION macro from libvirt Patch is empty. Was it split wrong? If you would prefer to skip this patch, instead run "git am --skip". To restore the original branch and stop patching run "git am --abort". thinkpad:~/libvirt-python -> git am --skip Applying: Import some virTypedParams* APIs from libvirt .... Applying: VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK appeared in 1.0.0 fatal: sha1 information is lacking or useless (libvirt-override.c). Repository lacks necessary blobs to fall back on 3-way merge. Cannot fall back to three-way merge. Patch failed at 0031 VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK appeared in 1.0.0 The copy of the patch that failed is found in: /home/veillard/libvirt-python/.git/rebase-apply/patch I suggest you simply push your repo to libvirt.org git as libvirt-python.git and just send additional patches which are needed to cleanup the curent libvirt.git, Daniel -- Daniel Veillard | Open Source and Standards, Red Hat veillard@redhat.com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (4)
-
Daniel P. Berrange
-
Daniel Veillard
-
Eric Blake
-
Jim Fehlig