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

870 Commits

Author SHA1 Message Date
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
Doug Goldstein
3af0f02351 setup: Drop unused exception variable
Drop the unused exception variable in setup.py. This has the benefit
of dropping syntax that is not valid with 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
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
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
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
Doug Goldstein
9d9e2513c0 setup: Use user requested python binary
When setup.py is kicked off with a python interpreter other than the
system 'python', (e.g. python2.7 setup.py build) the build process would
switch to 'python' and not use python2.7 as requested by the user. We
should always respect the user requested python interpreter and use it.
2013-12-03 11:26:17 -06:00
Daniel P. Berrange
4fe9994338 Improve quality of sanitytest check
Validate that every public API method is mapped into the python
and that every python method has a sane C API.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
v1.2.0
2013-11-28 13:37:55 +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
b9579cb6fd Fix misc RPM specfile flaws
Fix the RPM summary line, add placeholder %changelog tag,
make %setup quiet, add Url: tag and filter out bogus
provides and add example programs as docs.

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>
v1.2.0-rc2
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
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
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
Doug Goldstein
3b314e4124 Call virGetLastError from mod rather than py wrapper
All other code always calls the methods from the mod rather than using
the python wrapper so this matches the state of all other callers.
2013-11-26 12:54:59 -06: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
Martin Kletzander
e81d4dce75 Make setup.py executable
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2013-11-26 14:33:31 +01:00
Daniel P. Berrange
409273ad3e Update README file contents and add HACKING file
The previous README file from the python code is more like a
HACKING file. Rename it and update the content. Then add a
basic README file

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-26 11:44:19 +00:00
Eric Blake
cabb24db9f maint: next release is 1.2.0
No other hits for:
git grep '1\.1\.5'

* libvirt-utils.h: Fix comment.

Signed-off-by: Eric Blake <eblake@redhat.com>
v1.2.0-rc1
2013-11-25 08:49:44 -07: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
Daniel P. Berrange
45eb6b995c Relax min required libvirt to version 0.9.11
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-22 15:59:39 +00:00
Doug Goldstein
b8de31ae0c virConnectGetCPUModelNames API appeared in 1.1.3 2013-11-22 15:59:25 +00:00
Daniel P. Berrange
298233168c VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED appeared in 1.1.1 2013-11-22 15:58:07 +00:00
Doug Goldstein
33b2b09b7f virDomainCreateXMLWithFiles and virDomainCreateWithFiles APIs appeared in 1.1.1
virDomainCreateXMLWithFiles() and virDomainCreateWithFiles() were not
added to libvirt until 1.1.1
2013-11-22 15:58:07 +00:00
Doug Goldstein
f721af9e54 virDomainMigrate3 and virDomainMigrateToURI3 appeared in 1.1.0
The functions virDomainMigrate3 and virDomainMigrateToURI3 were not
added to libvirt until v1.1.0.
2013-11-22 15:58:07 +00:00
Doug Goldstein
24c5e9b994 virTypedParams* API appeared in 1.0.2 and used in 1.1.0
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.
2013-11-22 15:58:07 +00:00
Doug Goldstein
121d123af4 virDomainMigrateGetCompressionCache API appeared in 1.0.3 2013-11-22 15:58:07 +00:00
Doug Goldstein
e5da225dd0 virDomainGetJobStats API appeared in 1.0.3 2013-11-22 15:58:07 +00:00
Doug Goldstein
810126620a virNodeGetCPUMap API appeared in 1.0.0 2013-11-22 15:58:07 +00:00
Daniel P. Berrange
7cc872b35b VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK appeared in 1.0.0 2013-11-22 15:58:07 +00:00
Doug Goldstein
38b2d9304f virStoragePoolListAllVolumes API appeared in 0.10.2 2013-11-22 15:58:07 +00:00
Doug Goldstein
f55e27f210 virNode{Get,Set}MemoryParameters API appeared in 0.10.2 2013-11-22 15:58:07 +00:00
Doug Goldstein
f13a882e00 virConnectListAll* APIs appeared in 0.10.2 2013-11-22 15:58:07 +00:00
Daniel P. Berrange
a7651a3284 virDomainQemuAgentCommand appeared in 0.10.0
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-22 15:58:06 +00:00
Doug Goldstein
6a050c8f43 virDomainPinEmulator and virDomainGetEmulatorPinInfo APIs appeared in 0.10.0 2013-11-22 15:58:06 +00:00
Daniel P. Berrange
bebe13660f VIR_DOMAIN_EVENT_ID_BALLOON_CHANGED appeared in 0.10.0 2013-11-22 15:58:06 +00:00
Doug Goldstein
cfe670927e virConnect{Unr,R}egisterCloseCallback API appeared in 0.10.0 2013-11-22 15:58:06 +00:00
Doug Goldstein
23e65b47e1 virDomainSnapshotListAllChildren API appeared in 0.9.13 2013-11-22 15:58:06 +00:00
Doug Goldstein
0ee14795fd virConnectListAllDomains API appeared in 0.9.13 2013-11-22 15:58:06 +00:00