1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2024-10-26 16:25:10 +03:00
Commit Graph

212 Commits

Author SHA1 Message Date
Richard W.M. Jones
e3da7ade42 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
2014-12-11 11:21:36 +00: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
Dmitry Guryanov
8e09c79a07 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>
2014-10-28 12:06:50 -06: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
Michal Privoznik
a03b509d1c Implement new virNodeAllocPages API
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-09-26 12:01:17 +02:00
Michal Privoznik
4acfb16940 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>
2014-09-12 11:00:57 +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
Peter Krempa
7edf050a26 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>
2014-09-01 22:11:56 +02:00
Pavel Hrdina
62cfebc2e1 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>
2014-09-01 22:11:48 +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
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
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
Eric Blake
e3da8f178e 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>
2014-03-25 09:12:22 -06:00
Martin Kletzander
4b85a34448 generator: Add virConnectDomainQemuMonitorEventCallback to skipped_types
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-03-25 11:49:42 +01:00
Martin Kletzander
014d9bbaf3 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>
2014-02-20 17:12:45 +01: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
c2da294180 generator: Sort enums and functions when generating code
To assist in diff comparisons between code generated with
different versions of Python, do an explicit sort of all
functions and enums.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-09 13:50:48 +00:00
Daniel P. Berrange
dec4ff10ff generator: Remove use of string.replace and string.find functions
Call the 'replace' and 'find' functions directly on the
string variables, instead of via the 'string' module.
Python3 only accepts the latter syntax

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-09 13:50:42 +00:00
Daniel P. Berrange
394d88324c generator: Update to use sort() 'key' param
The sort() method previously took either a comparator function
or a key function. Only the latter is supported in Python3.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-09 13:50:32 +00:00
Daniel P. Berrange
3ae0a76d88 generator: Remove use of 'has_key' function
The code 'XXX.has_key(YYYY)' must be changed to be of
the form  'YYY in XXXX' which works in Python2 and 3

As an added complication, if 'YYY in XXX' is used against
an object overriding the '__getitem__' method it does not
work in Python 2.4. Instead we must use 'YYY in XXX.keys()'

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-09 13:47:23 +00:00
Doug Goldstein
ec15ea947b Update exception catching in generated code
Use a syntax for exception handling that works in both Python 2 and
Python 3. The new syntax is 'except Exception as e:' but this does not
work in older Pythons so we use the most compatible way by just catching
the exception and getting the type and the exception value after the
fact.
2013-12-05 12:06:53 +00:00
Doug Goldstein
0634769595 generator: Support exceptions in Python 2 and 3
Use a syntax for exception handling that works in both Python 2 and
Python 3
2013-12-05 12:06:53 +00:00
Daniel P. Berrange
f7addb7e6c generator: Cast iterators to a list() explicitly
In python3 various methods list 'dict.keys()' do not
return a list, so we must explicitly cast the result.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-04 18:10:00 +00:00
Daniel P. Berrange
dcbbb23072 Revert accidental change to exception handling syntax
The previous commit changed the exception handling syntax to
use 'as' instead of a ','. This doesn't work with python 2.4

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-04 18:04:27 +00:00
Daniel P. Berrange
2b8bb538a3 generator: Invoke print("...") instead of print "..."
The 'print' method must be called as a function in python3,
ie with brackets.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-04 17:08:33 +00:00
Daniel P. Berrange
8bc78e12c1 generator: Remove string.lower(XXX) with XXX.lower()
In python3 the string.lower() method doesn't exist, the
lower() function can only be executed against a string
variable directly. Python2 supported both approaches so
this change is compatible

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-04 17:08:28 +00:00
Daniel P. Berrange
978ec4a4ec generator: Don't use 'list' as a variable name
In python3 if we use 'list' as a variable name it causes it
to hide the corresponding 'list()' function from the entire
function that holds the variable.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-04 17:08:19 +00:00
Daniel P. Berrange
9f1c4e3d94 Skip copying manually written python for C APIs which don't exist
If the libvirt-override-virXXXX.py file has methods which call
C APIs that don't exist in the version of libvirt built against
we need to skip copying their code.

eg for 0.9.13 libvirt we should not copy the 'listAllDomains'
method.

The way this works is that it breaks the override file into
individual methods by looking for ' def '. It then collects
the contents until the next method start, whereupon it looks
for a libvirtmod.XXXXXX API call. It checks if the XXXXX part
is present in the XML description we have, and if not, it
discards the entire method.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-28 11:54:02 +00:00
Daniel P. Berrange
590f338b23 Fix code for avoiding overrides of non-existant functions
When reading/writing a global variable from inside a method
it must be declared as a global, otherwise a local variable
by the same name will be used.

Special case the virConnectListDomainsID method which is
bizarrely renamed for no obvious reason.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-28 11:52:32 +00:00
Daniel P. Berrange
9f02373b5e Deal with old filenames for events/error functions
Older libvirt has files named 'events' and 'virterror'
rather than 'virevent' and 'virerror'. This is visible
in the API XML files. We must look for both names to
ensure we don't lose generation of methods with older
versions of libvirt.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-28 11:52:20 +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
9bc81a156d Avoid generating the methods in multiple classes
The python code generator tries to figure out what class a
method should be in by looking at the list of arguments for
any which are object types. Unfortunately missing break
statements meant that methods which have multiple object
arguments (eg migrate as a virDomainPtr followed by a
virConnectPtr) got added to multiple classes.

The following incorrect methods are removed by this change

   virStream.download       (dup of virStorageVol.download)
   virStream.screenshot     (dup of virDomain.screenshot)
   virStream.upload         (dup of virStorageVol.upload)
   virConnect.migrate       (dup of virDomain.migrate)
   virConnect.migrate2      (dup of virDomain.migrate2)
   virConnect.migrate3      (dup of virDomain.migrate3)
   virConnect.migrateToURI3 (dup of virDomain.migrateToURI3)

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-27 11:07:45 +00:00
Daniel P. Berrange
edb16fd5c1 Don't include virDomainSnapshotRef in python API
The reference counting API is for internal use only. Attempts
to use it from python application code will cause havoc.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-27 11:07:19 +00:00
Daniel P. Berrange
6f82518edc Ensure API overrides only used if API exists
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>
2013-11-22 15:59:43 +00:00
Doug Goldstein
3878fbd548 Break generator.py to be called per module
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.
2013-11-22 15:58:06 +00:00
Daniel P. Berrange
19453b7836 Update generator for new code layout
Change the generator.py to

 - Take XML API file names on command line
 - Generate data in build/ directory instead of cwd
2013-11-22 15:58:05 +00:00
Doug Goldstein
45ac117cf6 python: remove virConnectGetCPUModelNames from globals
Commit de51dc9c9aed0e615c8b301cccb89f4859324eb0 primarily added
virConnectGetCPUModelNames as libvirt.getCPUModelNames(conn, arch)
instead of libvirt.virConnect.getCPUModelNames(arch) so revert the code
that does the former while leaving the code that does the later.

This is the rest of the patch that was ACK'd by Dan but I committed only
the partial patch in 6a8b8ae.
2013-11-21 14:20:45 -06:00
Doug Goldstein
4b6944d3c0 python: remove virConnectGetCPUModelNames from globals
Commit de51dc9c9aed0e615c8b301cccb89f4859324eb0 primarily added
virConnectGetCPUModelNames as libvirt.getCPUModelNames(conn, arch)
instead of libvirt.virConnect.getCPUModelNames(arch) so revert the code
that does the former while leaving the code that does the later.
2013-11-21 08:47:08 -06:00
Eric Blake
90461df0ca maint: avoid 'const fooPtr' in python bindings
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can).  But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).

Fix up offenders in the python bindings.

* python/generator.py (py_types): Drop useless conversions.
* python/libvirt-override.c (getPyVirTypedParameter)
(setPyVirTypedParameter): Use intended type.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-14 14:34:37 -06:00
Giuseppe Scrivano
357df252fb python: add bindings for virConnectGetCPUModelNames
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-09-23 16:59:39 -06:00
Giuseppe Scrivano
9d091faa7d libvirt: add new public API virConnectGetCPUModelNames
The new function virConnectGetCPUModelNames allows to retrieve the list
of CPU models known by the hypervisor for a specific architecture.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-09-23 15:41:50 -06:00
Oskari Saarenmaa
44dce1e00f docs, comments: minor typo fixes
Signed-off-by: Oskari Saarenmaa <os@ohmu.fi>
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-09-10 17:06:41 -06:00
Claudio Bley
1f01027098 python: simplify complicated conditional assignment 2013-08-23 10:54:58 +02:00
Claudio Bley
d101d3bce8 Test for object identity when checking for None in Python
Consistently use "is" or "is not" to compare variables to None,
because doing so is preferrable, as per PEP 8
(http://www.python.org/dev/peps/pep-0008/#programming-recommendations):

> Comparisons to singletons like None should always be done with is or
> is not, never the equality operators.
2013-08-23 08:12:26 +02:00
Daniel P. Berrange
03e7cacfa2 Introduce new domain create APIs to pass pre-opened FDs to LXC
With container based virt, it is useful to be able to pass
pre-opened file descriptors to the container init process.
This allows for containers to be auto-activated from incoming
socket connections, passing the active socket into the container.

To do this, introduce a pair of new APIs, virDomainCreateXMLWithFiles
and virDomainCreateWithFiles, which accept an array of file
descriptors. For the LXC driver, UNIX file descriptor passing
will be used to send them to libvirtd, which will them pass
them down to libvirt_lxc, which will then pass them to the container
init process.

This will only be implemented for LXC right now, but the design
is generic enough it could work with other hypervisors, hence
I suggest adding this to libvirt.so, rather than libvirt-lxc.so

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-18 11:01:14 +01:00
Jiri Denemark
1c94615878 Extensible migration APIs
This patch introduces two new APIs virDomainMigrate3 and
virDomainMigrateToURI3 that may be used in place of their older
variants. These new APIs take optional migration parameters (such as
bandwidth, domain XML, ...) in an array of virTypedParameters, which
makes adding new parameters easier as there's no need to introduce new
APIs whenever a new migration parameter needs to be added. Both APIs are
backward compatible and will automatically use older migration calls in
case the new calls are not supported as long as the typed parameters
array does not contain any parameter which was not supported by the
older calls.
2013-06-25 01:24:53 +02:00
Guannan Ren
109e7e30b2 python: set default value to optional arguments
When prefixing with string (optional) or optional in the description
of arguments to libvirt C APIs, in python, these arguments will be
set as optional arugments, for example:

 * virDomainSaveFlags:
 * @domain: a domain object
 * @to: path for the output file
 * @dxml: (optional) XML config for adjusting guest xml used on restore
 * @flags: bitwise-OR of virDomainSaveRestoreFlags

 the corresponding python APIs is
 restoreFlags(self, frm, dxml=None, flags=0)

The following python APIs are changed to:
 blockCommit(self, disk, base, top, bandwidth=0, flags=0)
 blockPull(self, disk, bandwidth=0, flags=0)
 blockRebase(self, disk, base, bandwidth=0, flags=0)
 migrate(self, dconn, flags=0, dname=None, uri=None, bandwidth=0)
 migrate2(self, dconn, dxml=None, flags=0, dname=None, uri=None, bandwidth=0)
 migrateToURI(self, duri, flags=0, dname=None, bandwidth=0)
 migrateToURI2(self, dconnuri=None, miguri=None, dxml=None, flags=0, \
               dname=None, bandwidth=0)
 saveFlags(self, to, dxml=None, flags=0)
 migrate(self, domain, flags=0, dname=None, uri=None, bandwidth=0)
 migrate2(self, domain, dxml=None, flags=0, dname=None, uri=None, bandwidth=0)
 restoreFlags(self, frm, dxml=None, flags=0)
2013-03-26 12:34:49 +08:00