1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-12-13 00:23:49 +03:00
Commit Graph

307 Commits

Author SHA1 Message Date
Peter Krempa
acc47bcb71 event: Add bindings for agent lifecycle event
Also add the example.
2014-11-24 17:53:12 +01:00
Tomoki Sekiyama
c6def1bf95 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>
2014-11-24 17:30:49 +01:00
Luyao Huang
3d1d3fd52a 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>
2014-11-11 15:58:12 +01:00
Jiri Denemark
8dcdc7f2b4 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>
2014-11-06 11:45:05 +01:00
Pavel Hrdina
309be0a148 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>
2014-10-22 13:38:55 +02:00
Pavel Hrdina
a7303a56b5 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>
2014-10-22 11:11:28 +02:00
Peter Krempa
7aaa02b47a 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.
2014-10-22 09:43:47 +02:00
Luyao Huang
b3aa7da4bb 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>
2014-10-22 09:43:47 +02:00
Peter Krempa
7bfe4e3cf6 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.
2014-10-22 09:43:43 +02:00
Luyao Huang
d8b7aa4b18 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>
2014-10-20 17:06:12 +02:00
Pradipta Kr. Banerjee
8feae56ce4 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>
2014-10-16 09:26:58 +02:00
Pavel Hrdina
714aa155e8 implement new tunable event
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1147639

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2014-09-30 19:15:29 +02:00
Michal Privoznik
a03b509d1c Implement new virNodeAllocPages API
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-09-26 12:01:17 +02:00
Peter Krempa
23e22c2df1 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
2014-09-02 14:41:12 +02:00
Pavel Hrdina
bc6da3214c 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>
2014-09-02 11:49:42 +02:00
Pavel Hrdina
0379d2a31a Implement API bindings for virDomainBlockCopy
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2014-09-02 00:29:26 +02:00
Pavel Hrdina
5ead8c1b0c 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>
2014-09-01 22:12:46 +02:00
Peter Krempa
285487954f 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>
2014-09-01 22:12:18 +02:00
Zhou Yimin
86ee51ce97 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>
2014-08-11 16:28:26 +02:00
Nehal J Wani
bdb64c7641 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>
2014-06-27 10:39:19 +02:00
Nehal J Wani
e272f51b36 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>
2014-06-25 10:45:07 -06:00
Michal Privoznik
c8ba859bc7 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>
2014-06-20 09:08:39 +02:00
Eric Blake
09a14b5d5e 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>
2014-06-18 10:49:27 -06:00
Martin Kletzander
28386e476e 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>
2014-05-27 17:33:44 +02:00
Michal Privoznik
bcacc418a3 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>
2014-05-20 17:26:17 +02:00
Tomoki Sekiyama
c5bbd5bd9d 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>
2014-05-16 15:45:25 +02:00
Brian Rak
71fd954092 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.
2014-03-31 14:09:40 +02:00
Eric Blake
493ca0883d 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>
2014-03-25 09:12:22 -06:00
Eric Blake
df17d37276 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>
2014-03-24 12:48:46 -06:00
Cole Robinson
097a479e91 override: Return NULL on python failure in getCPUModelNames
Eric pointed this out on the last patch, but I pushed it before noticing
his message.
2014-03-20 13:57:24 -04:00
Cole Robinson
33e39093ca 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.
2014-03-20 13:53:25 -04:00
Michal Privoznik
69c4600d61 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>
2014-03-18 14:43:10 +01:00
Michal Privoznik
412c93a7b9 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>
2014-03-18 14:43:00 +01:00
Daniel P. Berrange
faaf2a4835 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>
2013-12-11 16:27:27 +00:00
Daniel P. Berrange
d40861012c 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>
2013-12-11 16:14:46 +00:00
Daniel P. Berrange
e6551e60ce 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>
2013-12-11 16:14:46 +00:00
Daniel P. Berrange
d021f89dfc 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>
2013-12-11 16:12:54 +00:00
Daniel P. Berrange
a933b7f5d1 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>
2013-12-11 16:12:54 +00:00
Daniel P. Berrange
aac76e7630 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>
2013-12-11 16:12:54 +00:00
Daniel P. Berrange
e5161dec9e 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>
2013-12-11 16:12:54 +00:00
Daniel P. Berrange
1b4dc72140 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>
2013-12-11 16:12:54 +00:00
Daniel P. Berrange
bb3301ba78 Don't free passed in args in libvirt_charPtrWrap / libvirt_charPtrSizeWrap
Functions should not make assumptions about the memory management
callers use for parameters

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 16:12:14 +00:00
Cédric Bosdonnat
6ea5be0dd2 Added python binding for the new network events API
The new network events code requires manual binding code to
be written.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-11 15:39:09 +00:00
Daniel P. Berrange
7e68c27960 Revert "Optimize callback lookup in event handlers"
This reverts commit 084729e269.

The PyImport_ImportModuleNoBlock method does not exist in
python 2.4

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-04 18:05:21 +00:00
Daniel P. Berrange
084729e269 Optimize callback lookup in event handlers
The event handler code currently invokes PyImport_ImportModule
which is very heavyweight. This is not in fact required, since
we know the libvirt module has already been imported. We can
thus use PyImport_ImportModuleNoBlock and do away with the
global variables caching the imported module reference.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-04 17:07:13 +00:00
Daniel P. Berrange
7f842365b1 Fix use of virDomainEventRegister in python bindings
If an app used the virDomainEventRegister binding instead
of the virDomainEventRegisterAny binding, it would never
have its callback invoked. This is because the code for
dispatching from the C libvirt_virConnectDomainEventCallback
method was totally fubar.

If DEBUG macro was set in the python build the error would
become visible

  "libvirt_virConnectDomainEventCallback dom_class is not a class!"

The code in libvirt_virConnectDomainEventCallback was
inexplicably complex and has apparently never worked. The
fix is to write it the same way as the other callback handlers.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-04 14:52:48 +00:00
Daniel P. Berrange
197153c67e Add missing binding of security model/label APIs
The virNodeGetSecurityModel, virDomainGetSecurityLabel and
virDomainGetSecurityLabelList methods were disabled in the
python binding for inexplicable reasons.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-27 11:11:23 +00:00
Daniel P. Berrange
d05f105992 Make block pull event dispatcher private
The method dispatchDomainEventBlockPullCallback which is
used internally to dispatch block pull events to the python
application code was missing the leading '_', to denote that
it was private.  All other event callback helpers have a
leading '_'. No application should have been using this so
it is justifiable to rename it.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-27 11:07:24 +00:00
Don Dugger
8dd64f07ea Return right error code for baselineCPU
This Python interface code is returning a -1 on errors for the
`baselineCPU' API.  Since this API is supposed to return a pointer
the error return value should really be VIR_PY_NONE.

Signed-off-by: Don Dugger <donald.d.dugger@intel.com>
2013-11-26 16:54:01 +00:00
Doug Goldstein
b8de31ae0c virConnectGetCPUModelNames API appeared in 1.1.3 2013-11-22 15:59:25 +00:00