libvirt-python/ericb.git
7 years agoAdd c_pointer method to classes.v1.2.11
Richard W.M. Jones [Thu, 11 Dec 2014 11:16:12 +0000 (11 11:16 +0000)]
Add c_pointer method to classes.

This returns the raw C pointer to the underlying object, eg:

  conn = libvirt.open(None)
  print "0x%x" % conn.c_pointer()   # returns virConnectPtr of the connection
  dom = conn.lookupByName("test")
  print "0x%x" % dom.c_pointer()    # returns virDomainPtr of the domain

The reason behind this is to allow us to transparently pass Python dom
objects through the libguestfs Python API.

https://bugzilla.redhat.com/show_bug.cgi?id=1075164

7 years agooverride: iterate virDomainFSInfo.devAliases using ndevAliases
Tomoki Sekiyama [Mon, 1 Dec 2014 21:23:56 +0000 (1 16:23 -0500)]
override: iterate virDomainFSInfo.devAliases using ndevAliases

Currently devAliases in virDomainFSInfo struct are iterated as a
NULL-terminated list, but that is not guaranteed. It should use
ndevAliases which stores the number of the items in devAliases.

Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama@hds.com>
7 years agofix examples
Pavel Hrdina [Wed, 26 Nov 2014 17:47:17 +0000 (26 18:47 +0100)]
fix examples

The dhcpleases example had an old usage of print function. The formating
of leases record was also wrong.

The event-test example had an old usage of exceptions.

It's mainly to make examples compatible with python3.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoevent: Add bindings for agent lifecycle event
Peter Krempa [Mon, 24 Nov 2014 15:41:39 +0000 (24 16:41 +0100)]
event: Add bindings for agent lifecycle event

Also add the example.

7 years agooverride: Implement bindings for virDomainGetFSInfo as domain.fsInfo
Tomoki Sekiyama [Sat, 22 Nov 2014 01:28:00 +0000 (22 02:28 +0100)]
override: Implement bindings for virDomainGetFSInfo as domain.fsInfo

Implement the function which returns a list of tuples, that contains members
of virDomainFSInfo struct.

Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama@hds.com>
7 years agoAdd dict check for setTime and allow pass 'seconds' parameter
Luyao Huang [Fri, 31 Oct 2014 02:02:16 +0000 (31 10:02 +0800)]
Add dict check for setTime and allow pass 'seconds' parameter

When pass None or a empty dictionary to time, it will report
error. This commit allows a one-element dictionary which contains
just 'seconds' field, which results in the same as passing 0 for
'nseconds' field. Moreover, dict is checked for unknown fields.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
7 years agoCheck return value of libvirt_uintUnwrap
Jiri Denemark [Thu, 6 Nov 2014 09:20:40 +0000 (6 10:20 +0100)]
Check return value of libvirt_uintUnwrap

libvirt_virDomainSendKey didn't check whether libvirt_uintUnwrap
succeeded or not.

https://bugzilla.redhat.com/show_bug.cgi?id=1161039
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7 years agoBump version to 1.2.11 for new dev cycle
John Ferlan [Mon, 3 Nov 2014 15:41:27 +0000 (3 10:41 -0500)]
Bump version to 1.2.11 for new dev cycle

7 years agofix libvirt headers listv1.2.10
Dmitry Guryanov [Tue, 28 Oct 2014 17:29:58 +0000 (28 20:29 +0300)]
fix libvirt headers list

Since libvirt.h has been split out, generator.py
should be fixed accordingly. So add full list of header
files.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
7 years agovirDomainBlockCopy: initialize flags to 0
Pavel Hrdina [Wed, 22 Oct 2014 11:38:55 +0000 (22 13:38 +0200)]
virDomainBlockCopy: initialize flags to 0

An optional argument if not passed isn't modified by the
PyArg_ParseTuple function.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoflags cannot get right value for blockCopy function
Pavel Hrdina [Wed, 22 Oct 2014 09:10:54 +0000 (22 11:10 +0200)]
flags cannot get right value for blockCopy function

When use blockCopy, flags cannot get a right value, because
PyArg_ParseTuple want to get 6 parameters and blockCopy only
pass 5. Flags will get a unpredictable value, this will make
the function fail with error:

unsupported flags (0x7f6c) in function qemuDomainBlockCopy

Signed-off-by: Luyao Huang <lhuang@redhat.com>
7 years agoFix rest of unsigned integer handling
Peter Krempa [Tue, 21 Oct 2014 14:06:41 +0000 (21 16:06 +0200)]
Fix rest of unsigned integer handling

As in the previous patch, fix all places where 'flags' is converted as a
signed argument to unsigned including the python code generator.

7 years agoFix parsing of 'flags' argument for bulk stats functions
Luyao Huang [Tue, 21 Oct 2014 09:04:41 +0000 (21 17:04 +0800)]
Fix parsing of 'flags' argument for bulk stats functions

When 'flags' is set to
'libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS,
python will report a  error:

OverflowError: signed integer is greater than maximum

as VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS is defined as 1<<31.
This happens as PyArg_ParseTuple's formatting string containing 'i' as a
modifier expects a signed integer.

With python >= 2.3, 'I' means unsigned int and 'i' means int so we
should use 'I' in the formatting string.

See: https://docs.python.org/2/c-api/arg.html

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
7 years agoFix function name when parsing arguments in libvirt_virNodeAllocPages
Peter Krempa [Tue, 21 Oct 2014 13:59:21 +0000 (21 15:59 +0200)]
Fix function name when parsing arguments in libvirt_virNodeAllocPages

The override function was copied&pasted from virConnectGetAllDomainStats
and the function name after the colon was not changed. Fix the issue as
an invalid name would appear in the error message.

7 years agoImprove error output when use getTime with a nonzero flags.
Luyao Huang [Mon, 20 Oct 2014 13:55:00 +0000 (20 15:55 +0200)]
Improve error output when use getTime with a nonzero flags.

When give a nonzero flags to getTime, c_retval will get -1 and goto
cleanup. But py_retval still is NULL, so set py_retval =  VIR_PY_NONE.
This will make the output message more correct.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
7 years agoChange the comment in getPyNodeCPUCount method reflecting correct called methods
Pradipta Kr. Banerjee [Wed, 15 Oct 2014 13:54:00 +0000 (15 15:54 +0200)]
Change the comment in getPyNodeCPUCount method reflecting correct called methods

Comment mentions virGetNodeCPUMap whereas the actual method is
virNodeGetCPUMap. Similarly comment mentions virGetNodeInfo whereas the actual
method is virNodeGetInfo

Signed-off-by: Pradipta Kr. Banerjee <bpradip@in.ibm.com>
7 years agosetup.py: fix rpm build to return 1 on error
Pavel Hrdina [Tue, 7 Oct 2014 09:54:15 +0000 (7 11:54 +0200)]
setup.py: fix rpm build to return 1 on error

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agosanitytest: define long for python version >= 3
Martin Kletzander [Tue, 7 Oct 2014 08:35:10 +0000 (7 10:35 +0200)]
sanitytest: define long for python version >= 3

Commit c58c7f362aab37e4961407c2efc8a74925ed9c37 fixed 32-bit python
build but broke build with python3 due to the lack of 'long' in the
newer version of python.  This patch aims to fix it with a simple
string comparison of sys.version and '3'.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7 years agosanitytest: count with the fact that large enums can be long
Martin Kletzander [Tue, 7 Oct 2014 08:08:38 +0000 (7 10:08 +0200)]
sanitytest: count with the fact that large enums can be long

On 32-bit systems, one new flag that has the value of 1 << 31, namely
VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS, fails to fit into an
'int' on python and is therefore of type 'long'.  Fix sanitytest to
count with such fact in order to avoid build failures on 32-bit systems.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7 years agosanitytest: check for exported enums
Martin Kletzander [Mon, 6 Oct 2014 10:26:27 +0000 (6 12:26 +0200)]
sanitytest: check for exported enums

We are already collecting list of enums exported and list of enums we
want to have available.  Event though there was an issue with one enum
fixed with 014d9bbaf368b33a881f1d6b2fd8a5dd285a4f71, there was no test
for it and this commit tries to fix that.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7 years agoPost-release version bump for new dev cycle
Pavel Hrdina [Thu, 2 Oct 2014 12:55:21 +0000 (2 14:55 +0200)]
Post-release version bump for new dev cycle

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoimplement new tunable eventv1.2.9
Pavel Hrdina [Tue, 30 Sep 2014 15:52:29 +0000 (30 17:52 +0200)]
implement new tunable event

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1147639

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoImplement new virNodeAllocPages API
Michal Privoznik [Thu, 25 Sep 2014 15:02:49 +0000 (25 17:02 +0200)]
Implement new virNodeAllocPages API

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
7 years agogenerator: Free strings after libvirt_charPtrWrap
Michal Privoznik [Fri, 12 Sep 2014 08:49:02 +0000 (12 10:49 +0200)]
generator: Free strings after libvirt_charPtrWrap

https://bugzilla.redhat.com/show_bug.cgi?id=1140998

Up till bb3301ba the wrapper was freeing the passed strings for us.
However that changed after the commit. So now we don't free any
strings which results in memory leaks as reported upstream [1]:

==14265== 2,407 bytes in 1 blocks are definitely lost in loss record 1,457 of 1,550
==14265==    at 0x4C2845D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==14265==    by 0x5C46624: xdr_string (in /usr/lib64/libc-2.17.so)
==14265==    by 0xCFD9FCD: xdr_remote_nonnull_string (remote_protocol.c:31)
==14265==    by 0xCFDC2C8: xdr_remote_domain_get_xml_desc_ret (remote_protocol.c:1617)
==14265==    by 0xCFF0811: virNetMessageDecodePayload (virnetmessage.c:407)
==14265==    by 0xCFE68FB: virNetClientProgramCall (virnetclientprogram.c:379)
==14265==    by 0xCFBE8B1: callFull.isra.2 (remote_driver.c:6578)
==14265==    by 0xCFC7F04: remoteDomainGetXMLDesc (remote_driver.c:6600)
==14265==    by 0xCF8167C: virDomainGetXMLDesc (libvirt.c:4380)
==14265==    by 0xCC2C4DF: libvirt_virDomainGetXMLDesc (libvirt.c:1141)
==14265==    by 0x4F12B93: PyEval_EvalFrameEx (in /usr/lib64/libpython2.7.so.1.0)
==14265==    by 0x4F141AC: PyEval_EvalCodeEx (in /usr/lib64/libpython2.7.so.1.0)

The python documentation clearly advise us to call free() [2]. From
an example in their docs:

    PyObject *res;
    char *buf = (char *) malloc(BUFSIZ); /* for I/O */

    if (buf == NULL)
        return PyErr_NoMemory();
    ...Do some I/O operation involving buf...
    res = PyString_FromString(buf);
    free(buf); /* malloc'ed */
    return res;

Moreover, instead of using VIR_FREE() (which we are not exporting),
I'll just go with bare free().

1: https://www.redhat.com/archives/libvir-list/2014-September/msg00736.html
2: https://docs.python.org/2/c-api/memory.html

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
7 years agooverride: Fix two uninitialized variables in convertDomainStatsRecord
Peter Krempa [Tue, 2 Sep 2014 12:39:02 +0000 (2 14:39 +0200)]
override: Fix two uninitialized variables in convertDomainStatsRecord

py_record_domain and py_record_stats would be accessed uninitialized if
an out-of-memory condition would happen in the first loop. Unlikely, but
coverity complained.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1136354

7 years agolibvirt-override: fix some build warnings
Pavel Hrdina [Tue, 2 Sep 2014 09:44:25 +0000 (2 11:44 +0200)]
libvirt-override: fix some build warnings

Remove unused label 'cleanup' in 'libvirt_virConnectGetAllDomainStats'
function and remove unused variable 'conn' in function
'libvirt_virDomainListGetStats'.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoPost-release version bump for new dev cycle
Michal Privoznik [Tue, 2 Sep 2014 09:04:58 +0000 (2 11:04 +0200)]
Post-release version bump for new dev cycle

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
7 years agoImplement API bindings for virDomainBlockCopyv1.2.8
Pavel Hrdina [Mon, 1 Sep 2014 19:58:48 +0000 (1 21:58 +0200)]
Implement API bindings for virDomainBlockCopy

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoAPI: Implement bindings for virDomainListGetStats
Pavel Hrdina [Mon, 1 Sep 2014 19:57:35 +0000 (1 21:57 +0200)]
API: Implement bindings for virDomainListGetStats

Implement the function by returning a list of tuples instead the array
of virDomainStatsRecords and store the typed parameters as dict.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoAPI: Implement bindings for virConnectGetAllDomainStats
Peter Krempa [Thu, 28 Aug 2014 16:32:00 +0000 (28 18:32 +0200)]
API: Implement bindings for virConnectGetAllDomainStats

Implement the function by returning a list of tuples instead the array
of virDomainStatsRecords and store the typed parameters as dict.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agoAPI: Skip 'virDomainStatsRecordListFree'
Peter Krempa [Thu, 28 Aug 2014 16:32:00 +0000 (28 18:32 +0200)]
API: Skip 'virDomainStatsRecordListFree'

The new API function doesn't make sense to be exported in python. The
bindings will return native types instead of the struct array.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agogenerator: resolve one level of enum reference
Pavel Hrdina [Mon, 1 Sep 2014 19:24:42 +0000 (1 21:24 +0200)]
generator: resolve one level of enum reference

In the libvirt.h we have one enum defined by references from another
enum and it leads in wrong order of definitons in python code. To
prevent this we should resolve that references before we generate the
python code.

For now we have only one level of references so we will count with that
in the generator but we should update it in the future to be more
flexible.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7 years agobuild: Fix build warning on libvirt-python
Mo Yuxiang [Fri, 8 Aug 2014 09:55:37 +0000 (8 17:55 +0800)]
build: Fix build warning on libvirt-python

On compiling libvirt-python, we get such a warning:

libvirt-qemu-override.c: In function ‘libvirt_qemu_virConnectDomainQemuMonitorEventRegister’:
libvirt-qemu-override.c:304: warning: suggest explicit braces to avoid ambiguous ‘else’

Py_DECREF is a macro using if/else on older Python releases.
The solution is to add braces.
Python 2.7 and newer has the macro wrapped in a do { } while(0) block.

Signed-off-by: Mo Yuxiang <Moyuxiang@huawei.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
7 years agoFix libvirt_longlongWrap returning a very large value
Zhou Yimin [Mon, 11 Aug 2014 12:59:49 +0000 (11 20:59 +0800)]
Fix libvirt_longlongWrap returning a very large value

If hypervisor is not Xen, the errs in struct _virDomainBlockStats will be -1.
But in KVM when we call domain.blockStats(), errs is 18446744073709551615.

To fix that, this patch has two changes:
1. Replace use of the PyLong_FromUnsignedLongLong with PyLong_FromLongLong
   in function libvirt_longlongWrap
2. If the paramemter of libvirt_longlongWrap is unsigned long long,
   use libvirt_ulonglongWrap instead because of above change.

After this patch, errs is -1 which is consistent with virDomainBlockStats api.

Signed-off-by: Zhou Yimin <zhouyimin@huawei.com>
Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
7 years agomaint: document use of libvirt's run script
Eric Blake [Mon, 4 Aug 2014 17:09:34 +0000 (4 11:09 -0600)]
maint: document use of libvirt's run script

Ever since libvirt commit 78c09530, it's easier to just use the
run script.

* README: Mention run script.

Signed-off-by: Eric Blake <eblake@redhat.com>
7 years agoBump version to 1.2.8 for new dev cycle
Eric Blake [Tue, 22 Jul 2014 16:07:53 +0000 (22 18:07 +0200)]
Bump version to 1.2.8 for new dev cycle

Signed-off-by: Eric Blake <eblake@redhat.com>
7 years agospec: Reorganize to satisfy buggy spectoolv1.2.7
Jiri Denemark [Tue, 29 Jul 2014 14:24:48 +0000 (29 16:24 +0200)]
spec: Reorganize to satisfy buggy spectool

spectool parses a specfile and strips everything but a preamble.
However, if the first section is preceded by %if clause, it keeps it
there which then makes rpmbuild complain about unmatched %if. Let's make
the buggy tool happy by moving sections around so that the first one is
not in any conditional.

8 years agoBump version to 1.2.7 for new dev cycle
Martin Kletzander [Tue, 22 Jul 2014 16:07:53 +0000 (22 18:07 +0200)]
Bump version to 1.2.7 for new dev cycle

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
8 years agoImplement new virNetworkGetDHCPLeases APIv1.2.6v1.2.6-rc2
Nehal J Wani [Wed, 25 Jun 2014 22:45:30 +0000 (26 04:15 +0530)]
Implement new virNetworkGetDHCPLeases API

This API returns a list of DHCP leases for all network interfaces
connected to the given virtual network or limited output just for one
interface if mac is specified.

Example Output:
[{'iface': 'virbr3', 'ipaddr': '192.168.150.181', 'hostname': 'ubuntu14',
    'expirytime': 1403737495L, 'prefix': 24, 'clientid': None,
    'mac': '52:54:00:e8:73:eb', 'iaid': None, 'type': 0},
 {'iface': 'virbr3', 'ipaddr': '2001:db8:ca2:2:1::bd', 'hostname': 'fedora20-test',
    'expirytime': 1403738587L, 'prefix': 64, 'clientid': '00:04:b1:d8:86:42:e1:6a:aa:cf:d5:86:94:23:6f:94:04:cd',
    'mac': '52:54:00:5b:40:98', 'iaid': '5980312', 'type': 1}]

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
8 years agomaint: document development against uninstalled libvirt
Eric Blake [Wed, 25 Jun 2014 16:52:53 +0000 (25 10:52 -0600)]
maint: document development against uninstalled libvirt

Thanks to Dan's recent work in libvirt.git, it is much easier to
develop against uninstalled libvirt.  Mention how.

* README: More details.

Signed-off-by: Eric Blake <eblake@redhat.com>
8 years agobuild: use correct int conversion in NodeGetFreePages
Nehal J Wani [Wed, 25 Jun 2014 16:18:05 +0000 (25 21:48 +0530)]
build: use correct int conversion in NodeGetFreePages

Commit c8ba859bc7 introduced a compiler warning while un-wrapping
a python object to uint in libvirt_virNodeGetFreePages.

On compiling libvirt-python against libvirt 1.2.6, we get:

libvirt-override.c: In function ‘libvirt_virNodeGetFreePages’:
libvirt-override.c:7811:9: warning: pointer targets in passing argument 2 of ‘libvirt_intUnwrap’ differ in signedness [-Wpointer-sign]
         if (libvirt_intUnwrap(tmp, &pages[i]) < 0)
         ^
In file included from libvirt-override.c:24:0:
typewrappers.h:169:5: note: expected ‘int *’ but argument is of type ‘unsigned int *’
 int libvirt_intUnwrap(PyObject *obj, int *val);
     ^

Signed-off-by: Eric Blake <eblake@redhat.com>
8 years agoImplement new virNodeGetFreePages API
Michal Privoznik [Fri, 20 Jun 2014 07:08:39 +0000 (20 09:08 +0200)]
Implement new virNodeGetFreePages API

The API expose information on host's free pages counts. For easier
access, in python this API returns a dictionary such as:

In [4]: conn.getFreePages([2048,1*1024*1024], -1, 5)
Out[4]:
{-1: {2048: 114, 1048576: 4},
 0: {2048: 3, 1048576: 1},
 1: {2048: 100, 1048576: 1},
 2: {2048: 10, 1048576: 1},
 3: {2048: 1, 1048576: 1}}

At the top level of the returned dictionary there's a pair of <NUMA
node> and another dictionary that contains detailed information on
each supported page size. The information then consists of fairs of
<page size> and <count of free pages>.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
8 years agoCorrect virDomainMigrateToURI3 definition
Jason Andryuk [Thu, 5 Jun 2014 15:43:25 +0000 (5 11:43 -0400)]
Correct virDomainMigrateToURI3 definition

dconnuri is a string, so update the definition to match.  Without this,
the generated python would fail when passed a string.

8 years agobuild: provide wrapper makefile
Eric Blake [Wed, 18 Jun 2014 19:17:52 +0000 (18 13:17 -0600)]
build: provide wrapper makefile

After years of finger training, I'm so used to 'make check' just
working, that I lose quite a bit of time re-learning that in this
project, it is spelled 'python setup.py build check'.  A shim
makefile bridges the gap.

* Makefile: New file.

Signed-off-by: Eric Blake <eblake@redhat.com>
8 years agoevent-test: add missing events
Eric Blake [Wed, 18 Jun 2014 19:01:52 +0000 (18 13:01 -0600)]
event-test: add missing events

Update the example to be able to trace all events.

* examples/event-test.py (main): Match full list of domain events.
(myDomainEventIOErrorReasonCallback)
(myDomainEventControlErrorCallback)
(myDomainEventBlockJobCallback, myDomainEventBlockJob2Callback)
(blockJobTypeToString, blockJobStatusToString): New functions.

Signed-off-by: Eric Blake <eblake@redhat.com>
8 years agoblockjob: support new BLOCK_JOB_2 event
Eric Blake [Wed, 18 Jun 2014 16:49:27 +0000 (18 10:49 -0600)]
blockjob: support new BLOCK_JOB_2 event

Libvirt 1.2.6 is introducing a new block job event that passes disk
information by target device rather than host file name.  At the
python level, we are just a passthrough, so we can reuse all the
existing code and just wire up the new enum value.

* libvirt-override-virConnect.py
(_dispatchDomainEventBlockPullCallback): Rename...
(_dispatchDomainEventBlockJobCallback): ...to this, and make
generic to both events.
* libvirt-override.c
(libvirt_virConnectDomainEventBlockJobCallback): Match naming.
(libvirt_virConnectDomainEventRegisterAny): Allow new registration.

Signed-off-by: Eric Blake <eblake@redhat.com>
8 years agoBump version to 1.2.6 for new dev cycle
Martin Kletzander [Mon, 2 Jun 2014 04:54:56 +0000 (2 06:54 +0200)]
Bump version to 1.2.6 for new dev cycle

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
8 years agofix leak in memoryStats with older pythonv1.2.5
Martin Kletzander [Tue, 27 May 2014 09:40:05 +0000 (27 11:40 +0200)]
fix leak in memoryStats with older python

libvirt_virDomainMemoryStats() function creates a dictionary without
any checks whether the additions were successful, whether the python
objects were created and, most importantly, without decrementing the
reference count on the objects added to the dictionary.  This is
somehow not an issue with current upstream versions, however with
python 2.6 this exposes a leak in our bindings.  The following patch
works on both old and new CPython versions and is already used in
other parts of the code, so it's also most straightforward.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1099860

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
8 years agoImplement virDomain{Get,Set}Time APIs
Michal Privoznik [Mon, 19 May 2014 13:04:44 +0000 (19 15:04 +0200)]
Implement virDomain{Get,Set}Time APIs

While the setter can be generated automatically, the getter is not.
However, it would be a lot easier if they both share the same logic:
a python dictionary to represent the time: dict['seconds'] to
represent seconds, and dict['nseconds'] to represent nanoseconds.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
8 years agooverride: add virDomainFSFreeze and virDomainFSThaw API
Tomoki Sekiyama [Fri, 9 May 2014 23:21:08 +0000 (9 19:21 -0400)]
override: add virDomainFSFreeze and virDomainFSThaw API

Add binding for the new virDomainFSFreeze and virDomainFSThaw functions
added in libvirt 1.2.5. These require override since these take a list
of mountpoints path string. The methods are named 'fsFreeze' and
'fsThaw'.

Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama@hds.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
8 years agoBump version to 1.2.5 for new dev cycle
Martin Kletzander [Mon, 5 May 2014 13:46:47 +0000 (5 15:46 +0200)]
Bump version to 1.2.5 for new dev cycle

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
8 years agobuild: add BuildRequires for python-lxml and python3-lxmlv1.2.4
Laine Stump [Mon, 7 Apr 2014 11:19:45 +0000 (7 14:19 +0300)]
build: add BuildRequires for python-lxml and python3-lxml

python-lxml is likely always already present anyway (due to so many
packages being dependent on it), but at least on my F20 system,
python3-lxml wasn't installed, leading to a failure of "python
setup.py rpm" without an informative error message.

8 years agoincrement version post-release
Laine Stump [Mon, 7 Apr 2014 11:24:46 +0000 (7 14:24 +0300)]
increment version post-release

As is now done with libvirt. git head will always have the version
number of the expected *next* release.

8 years agoFix nosetests usage with python3v1.2.3
Daniel P. Berrange [Wed, 2 Apr 2014 14:33:53 +0000 (2 16:33 +0200)]
Fix nosetests usage with python3

Add RPM deps on python/python3-nose, make RPM build run the
test suite and invoke nosetests using correct python binary

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agoFix potential crash when setting partial cpu/memory/numa/interface limits on domains
Brian Rak [Thu, 27 Mar 2014 15:32:09 +0000 (27 11:32 -0400)]
Fix potential crash when setting partial cpu/memory/numa/interface limits on domains

The number of parameters in new_params is not guaranteed to be the
same as the number of parameters in params.  Use the correct count
when freeing new_params to avoid crashes.

8 years agosetup.py: Allow running --help or clean without pkg-config
Cole Robinson [Sat, 22 Mar 2014 23:22:34 +0000 (22 19:22 -0400)]
setup.py: Allow running --help or clean without pkg-config

If pkg-config isn't installed, or a too old libvirt, we can't even
do 'python setup.py --help' without throwing an exception.

Have the pkg-config checks and validation only throw an exception if
being called from the 'build' step.

https://bugzilla.redhat.com/show_bug.cgi?id=1074170

8 years agosetup.py: Make have_libvirt_lxc a function
Cole Robinson [Sat, 22 Mar 2014 23:14:07 +0000 (22 19:14 -0400)]
setup.py: Make have_libvirt_lxc a function

This means we call it twice for a build operation, but I don't think
that's a big deal.

8 years agosetup.py: Move module list building to its own function
Cole Robinson [Sat, 22 Mar 2014 23:08:26 +0000 (22 19:08 -0400)]
setup.py: Move module list building to its own function

Makes it a bit more clear what all that code is used for, rather than
intermixing it with function definitions.

Besides the comment additions, this is a no-op and just reindents the
block, into a function.

8 years agosetup.py: Remove unused import
Cole Robinson [Sat, 22 Mar 2014 23:00:02 +0000 (22 19:00 -0400)]
setup.py: Remove unused import

8 years agoqemu: support arbitrary monitor events
Eric Blake [Tue, 4 Feb 2014 23:14:16 +0000 (4 16:14 -0700)]
qemu: support arbitrary monitor events

Wrap the new virConnectDomainQemuMonitorEventRegister function
added in libvirt 1.2.3.  This patch copies heavily from
network events (commit 6ea5be0) and from event loop callbacks
in libvirt-override.c, since in the libvirt_qemu module, we
must expose top-level functions rather than class members.

* generator.py (qemu_skip_function): Don't generate event code.
(qemuBuildWrappers): Delay manual portion until after imports.
* libvirt-qemu-override.py (qemuMonitorEventRegister)
(qemuMonitorEventDeregister): New file.
* libvirt-qemu-override.c
(libvirt_qemu_virConnectDomainQemuMonitorEventFreeFunc)
(libvirt_qemu_virConnectDomainQemuMonitorEventCallback)
(libvirt_qemu_virConnectDomainQemuMonitorEventRegister)
(libvirt_qemu_virConnectDomainQemuMonitorEventDeregister)
(libvirt_qemu_lookupPythonFunc, getLibvirtQemuDictObject)
(getLibvirtQemuModuleObject): New functions.

Signed-off-by: Eric Blake <eblake@redhat.com>
8 years agoevent: fix domain reference bugs
Eric Blake [Mon, 24 Mar 2014 16:37:25 +0000 (24 10:37 -0600)]
event: fix domain reference bugs

Noticed this bug while adding qemu monitor events; there's probably
lots of other misuse of libvirt_virDomainPtrWrap, but for now I'm
limiting the fix to all copied-and-pasted event callbacks, since
I'm about to copy it again in the next patch.  While at it, check
for failure to extract the "conn" key from the opaque callback
struct, and hoist that check to occur before we reach the point
where it is harder to undo on failure (the network code was the
only code that had it in the right place, but then it failed to
restore thread state on failure).

The graphics callback is still not clean; but incremental
improvements are better than nothing.

* libvirt-override.c (libvirt_virConnectDomainEventCallback)
(libvirt_virConnectDomainEvetnLifecycleCallback)
(libvirt_virConnectDomainEventGenericCallback)
(libvirt_virConnectDomainEventRTCChangeCallback)
(libvirt_virConnectDomainEventWatchdogCallback)
(libvirt_virConnectDomainEventIOErrorCallback)
(libvirt_virConnectDomainEventIOErrorReasonCallback)
(libvirt_virConnectDomainEventGraphicsCallback)
(libvirt_virConnectDomainEventBlockJobCallback)
(libvirt_virConnectDomainEventDiskChangeCallback)
(libvirt_virConnectDomainEventTrayChangeCallback)
(libvirt_virConnectDomainEventPMWakeupCallback)
(libvirt_virConnectDomainEventPMSuspendCallback)
(libvirt_virConnectDomainEventBalloonChangeCallback)
(libvirt_virConnectDomainEventPMSuspendDiskCallback)
(libvirt_virConnectDomainEventDeviceRemovedCallback): Don't pass
NULL to PyObject_CallMethod.
(libvirt_virConnectNetworkEventLifecycleCallback): Likewise, and
don't corrupt thread state.

Signed-off-by: Eric Blake <eblake@redhat.com>
8 years agogenerator: Add virConnectDomainQemuMonitorEventCallback to skipped_types
Martin Kletzander [Tue, 25 Mar 2014 10:49:24 +0000 (25 11:49 +0100)]
generator: Add virConnectDomainQemuMonitorEventCallback to skipped_types

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
8 years agomaint: balance {} usage
Eric Blake [Mon, 24 Mar 2014 17:01:23 +0000 (24 11:01 -0600)]
maint: balance {} usage

Emacs gets lost when finding function boundaries when #ifdef
sections do not have balanced {}.

* libvirt-override.c (libvirt_PyString_Check): New define.
(virPyDictToTypedParams): Avoid unbalanced {} across ifdef.

Signed-off-by: Eric Blake <eblake@redhat.com>
8 years agomaint: Add ctags configuration file and ignore the output
Peter Krempa [Mon, 24 Mar 2014 18:15:02 +0000 (24 19:15 +0100)]
maint: Add ctags configuration file and ignore the output

Add the config file to ease creation of tags to help navigation in
editors.

8 years agomaint: set up preferred emacs settings
Eric Blake [Mon, 24 Mar 2014 16:27:00 +0000 (24 10:27 -0600)]
maint: set up preferred emacs settings

Copy the relevant settings from libvirt.git, so that emacs users
maintain the style previously used before the two repos split.

* .dir-locals.el: New file.

Signed-off-by: Eric Blake <eblake@redhat.com>
8 years agomaint: ignore .pyc files
Eric Blake [Fri, 21 Mar 2014 18:49:19 +0000 (21 12:49 -0600)]
maint: ignore .pyc files

* .gitignore: Add exemption.

Signed-off-by: Eric Blake <eblake@redhat.com>
8 years agooverride: Return NULL on python failure in getCPUModelNames
Cole Robinson [Thu, 20 Mar 2014 17:57:24 +0000 (20 13:57 -0400)]
override: Return NULL on python failure in getCPUModelNames

Eric pointed this out on the last patch, but I pushed it before noticing
his message.

8 years agooverride: GetCPUModelNames should return None on failure
Cole Robinson [Thu, 20 Mar 2014 17:27:12 +0000 (20 13:27 -0400)]
override: GetCPUModelNames should return None on failure

Right now, on failure, libvirt.py doesn't raise an exception and just
returns -1 to the user.

8 years agoAdd test for setting scheduler parameters
Daniel P. Berrange [Tue, 18 Mar 2014 11:22:27 +0000 (18 11:22 +0000)]
Add test for setting scheduler parameters

Add a test setting scheduler parameters to validate the
previous bugfix to strncpy of field names.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agoAdd support for running unit tests with nose
Daniel P. Berrange [Tue, 18 Mar 2014 11:11:48 +0000 (18 11:11 +0000)]
Add support for running unit tests with nose

Make the 'python setup.py test' able to run unit tests
found under tests/ through the 'nosetests' command

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agosetPyVirTypedParameter: free whole return variable on error
Michal Privoznik [Tue, 18 Mar 2014 08:20:00 +0000 (18 09:20 +0100)]
setPyVirTypedParameter: free whole return variable on error

The @ret value is built in a loop. However, if in one iteration
there's an error, we should free all the fields built so far. For
instance, if there's an error and the previous item was
type of VIR_TYPED_PARAM_STRING we definitely must free it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
8 years agosetPyVirTypedParameter: Copy full field name
Michal Privoznik [Tue, 18 Mar 2014 08:12:24 +0000 (18 09:12 +0100)]
setPyVirTypedParameter: Copy full field name

In the setPyVirTypedParameter we try to produce virTypedParameter
array from a python dictionary. However, when copying field name into
item in returned array, we use strncpy() as the field name is fixed
length array. To determine its size we use sizeof() but mistakenly
dereference it resulting in sizeof(char) which equals to 1 byte.
Moreover, there's no need for using sizeof() when we have a global
macro to tell us the length of the field name:
VIR_TYPED_PARAM_FIELD_LENGTH.

And since array is allocated using VIR_ALLOC() we are sure the memory
is initially filled with zeros. Hence, there's no need to terminate
string we've just copied into field name with '\0' character. It's
there for sure too as we copy up to field length - 1.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
8 years agoPost release version bump to 1.2.3
Daniel P. Berrange [Mon, 3 Mar 2014 12:04:07 +0000 (3 12:04 +0000)]
Post release version bump to 1.2.3

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agoRelease of libvirt-python 1.2.2v1.2.2
Daniel Veillard [Sun, 2 Mar 2014 14:42:36 +0000 (2 22:42 +0800)]
Release of libvirt-python 1.2.2

8 years agogenerator: Skip exporting only sentinelsv1.2.2-rc2
Martin Kletzander [Thu, 20 Feb 2014 15:35:02 +0000 (20 16:35 +0100)]
generator: Skip exporting only sentinels

When enum type has '_LAST' in its name, but is not the last type in
that enum, it's skipped even though it shouldn't be.  Currently, this
is the case for only VIR_NETWORK_UPDATE_COMMAND_ADD_LAST inside an
enum virNetworkUpdateCommand.

Also, since _LAST types can have other enums instead of values, that
needs to be filtered out using a try-except when converting the value.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
8 years agoFix stream related spelling mistakes
Philipp Hahn [Thu, 13 Feb 2014 08:46:19 +0000 (13 09:46 +0100)]
Fix stream related spelling mistakes

Consistent spelling of all-uppercase I/O.

Signed-off-by: Philipp Hahn <hahn@univention.de>
8 years agoexamples: demonstrate network events
Eric Blake [Wed, 5 Feb 2014 00:22:22 +0000 (4 17:22 -0700)]
examples: demonstrate network events

Commit 6ea5be0 added network event callback support, so we might
as well demonstrate that it works by updating our example.

* examples/event-test.py: Add network event, fix typos.

Signed-off-by: Eric Blake <eblake@redhat.com>
8 years agomaint: ignore editor files
Eric Blake [Tue, 4 Feb 2014 23:34:24 +0000 (4 16:34 -0700)]
maint: ignore editor files

* .gitignore: Exclude emacs cruft.

Signed-off-by: Eric Blake <eblake@redhat.com>
8 years agoMerge tag 'v1.2.1'
Eric Blake [Mon, 3 Feb 2014 21:28:09 +0000 (3 14:28 -0700)]
Merge tag 'v1.2.1'

Release of libvirt-python-1.2.1

8 years agoFix calling of virStreamSend method
Robie Basak [Thu, 23 Jan 2014 14:24:12 +0000 (23 14:24 +0000)]
Fix calling of virStreamSend method

Change d40861 removed the 'len' argument from the virStreamSend
C level wrapper, but forgot to remove it from the python level
wrapper.

Reported-by: Robie Basak <robie.basak@canonical.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agoRelease of libvirt-python-1.2.1v1.2.1
Daniel Veillard [Thu, 16 Jan 2014 09:33:29 +0000 (16 17:33 +0800)]
Release of libvirt-python-1.2.1

8 years agovirStream.sendAll() fix raising an undeclared varv1.2.1-rc2
Doug Goldstein [Sat, 11 Jan 2014 03:11:04 +0000 (10 21:11 -0600)]
virStream.sendAll() fix raising an undeclared var

The exception is raised from the variable 'e', which was undeclared in
this context. Used code that is compatible with old and new Python
versions.

8 years agoAdd space after comma for consistency with code stylev1.2.1-rc1
Doug Goldstein [Thu, 2 Jan 2014 15:52:13 +0000 (2 09:52 -0600)]
Add space after comma for consistency with code style

8 years agodefine __GNUC_PREREQ macro before using it
Doug Goldstein [Sun, 29 Dec 2013 22:52:15 +0000 (29 16:52 -0600)]
define __GNUC_PREREQ macro before using it

We brought over use of the __GNUC_PREREQ macro from libvirt but didn't
bring over the definition of it. This brings over the macro from libvirt
sources.

8 years agoRewrite libvirt_charPtrUnwrap to work with Python 3.0->3.2
Daniel P. Berrange [Thu, 12 Dec 2013 18:15:05 +0000 (12 18:15 +0000)]
Rewrite libvirt_charPtrUnwrap to work with Python 3.0->3.2

The PyUnicode_AsUTF8 method doesn't exist prior to Python 3.3.
It is also somewhat inefficient, so rewrite it to use an
intermediate PyBytes object.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agoAdd python3 to the automated build and RPM
Daniel P. Berrange [Wed, 11 Dec 2013 16:31:03 +0000 (11 16:31 +0000)]
Add python3 to the automated build and RPM

This updates autobuild.sh to test the python3 build process.
The RPM specfile is changed to build a libvirt-python3 RPM
on Fedora > 18

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agoSkip network event callbacks in sanity test
Daniel P. Berrange [Wed, 11 Dec 2013 16:38:43 +0000 (11 16:38 +0000)]
Skip network event callbacks in sanity test

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agoFix return type in override method for virStreamRecv
Daniel P. Berrange [Wed, 11 Dec 2013 16:27:27 +0000 (11 16:27 +0000)]
Fix return type in override method for virStreamRecv

The virStreamRecv override returns a PyObject not an int

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agosanitytest: remove use of string.lower()
Daniel P. Berrange [Mon, 9 Dec 2013 15:12:25 +0000 (9 15:12 +0000)]
sanitytest: remove use of string.lower()

Call lower() directly on the string object instance, not
the class

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agosanitytest: Fix broken comparison between int and string
Daniel P. Berrange [Mon, 9 Dec 2013 15:11:44 +0000 (9 15:11 +0000)]
sanitytest: Fix broken comparison between int and string

Python2 was forgiving of a comparison between an int and string
but Python3 gets very upset.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agooverride: Switch virStreamSend wrapper to use libvirt_charPtrSizeUnwrap
Daniel P. Berrange [Mon, 9 Dec 2013 14:53:34 +0000 (9 14:53 +0000)]
override: Switch virStreamSend wrapper to use libvirt_charPtrSizeUnwrap

Instead of using a 'z#i' format string to receive byte array,
use 'O' and then libvirt_charPtrSizeUnwrap. This lets us hide
the Python 3 vs 2 differences in typewrappers.c

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agooverride: Conditionalize use of PyString_Check and PyInt_Check
Daniel P. Berrange [Mon, 9 Dec 2013 14:17:10 +0000 (9 14:17 +0000)]
override: Conditionalize use of PyString_Check and PyInt_Check

The PyString and PyInt classes are gone in Python 3, so we must
conditionalize their use to be Python 2 only.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agotypewrappers: PyInt/PyLong merge for Python3
Daniel P. Berrange [Mon, 9 Dec 2013 14:00:19 +0000 (9 14:00 +0000)]
typewrappers: PyInt/PyLong merge for Python3

In Python3 the PyInt / PyLong types have merged into a single
PyLong type. Conditionalize the use of PyInt to Python 2 only

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agotypewrappers: Replace use of PyString class
Daniel P. Berrange [Thu, 5 Dec 2013 17:10:55 +0000 (5 17:10 +0000)]
typewrappers: Replace use of PyString class

Replace use of PyString with either PyBytes or PyUnicode.
The former is used for buffers with explicit sizes, which
are used by APIs processing raw bytes.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agooverride: Replace PyInt_AsLong with helper
Daniel P. Berrange [Mon, 9 Dec 2013 14:24:08 +0000 (9 14:24 +0000)]
override: Replace PyInt_AsLong with helper

Replace use of the PyInt_AsLong libvirt_intUnwrap helper.
This isolates the need for Python3 specific code in one
place

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agooverride: Replace Py{Int,Long}_FromLong with helpers
Daniel P. Berrange [Thu, 5 Dec 2013 16:08:40 +0000 (5 16:08 +0000)]
override: Replace Py{Int,Long}_FromLong with helpers

Replace use of the PyInt_FromLong and PyLong_FromLongLong
with libvirt_{int,uint,longlong,ulonglong}Wrap helpers.
This isolates the need for Python3 specific code in one
place.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agooverride: Replace PyString_AsString with libvirt_charPtrUnwrap
Daniel P. Berrange [Thu, 5 Dec 2013 16:36:41 +0000 (5 16:36 +0000)]
override: Replace PyString_AsString with libvirt_charPtrUnwrap

Replace calls to PyString_AsString with the helper method
libvirt_charPtrUnwrap. This isolates the code that will
change in Python3.

In making this change, all callers now have responsibility
for free'ing the string.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agooverride: Replace PyString_FromString with libvirt_constcharPtrWrap
Daniel P. Berrange [Thu, 5 Dec 2013 16:03:15 +0000 (5 16:03 +0000)]
override: Replace PyString_FromString with libvirt_constcharPtrWrap

Make use of libvirt_constcharPtrWrap in all override code,
to match generated code. This will isolate Python3 specific
changes in one place.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agosanitytest: Fix libvirtError class handling for Python 2.4
Daniel P. Berrange [Thu, 5 Dec 2013 12:12:28 +0000 (5 12:12 +0000)]
sanitytest: Fix libvirtError class handling for Python 2.4

The Exception class hiearchy in Python 2.4 reports different
data types than in later Python versions. As a result the
type(libvirt.libvirtError) does not return 'type'. We just
special case handling of this class.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
8 years agooverride: Fix native module registration to work with Python3
Daniel P. Berrange [Tue, 3 Dec 2013 15:42:49 +0000 (3 15:42 +0000)]
override: Fix native module registration to work with Python3

The way native modules are registered has completely
changed, so the code must be #ifdef'd for Python2 & 3

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>