summaryrefslogtreecommitdiff
path: root/generator.py
Commit message (Collapse)AuthorAgeFilesLines
...
* generator: Remove use of string.replace and string.find functionsDaniel P. Berrange2013-12-091-3/+3
| | | | | | | | 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>
* generator: Update to use sort() 'key' paramDaniel P. Berrange2013-12-091-22/+8
| | | | | | | 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>
* generator: Remove use of 'has_key' functionDaniel P. Berrange2013-12-091-54/+54
| | | | | | | | | | | 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>
* Update exception catching in generated codeDoug Goldstein2013-12-051-4/+8
| | | | | | | | 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.
* generator: Support exceptions in Python 2 and 3Doug Goldstein2013-12-051-2/+4
| | | | | Use a syntax for exception handling that works in both Python 2 and Python 3
* generator: Cast iterators to a list() explicitlyDaniel P. Berrange2013-12-041-19/+19
| | | | | | | 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>
* Revert accidental change to exception handling syntaxDaniel P. Berrange2013-12-041-2/+2
| | | | | | | 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>
* generator: Invoke print("...") instead of print "..."Daniel P. Berrange2013-12-041-21/+21
| | | | | | | The 'print' method must be called as a function in python3, ie with brackets. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* generator: Remove string.lower(XXX) with XXX.lower()Daniel P. Berrange2013-12-041-45/+45
| | | | | | | | | 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>
* generator: Don't use 'list' as a variable nameDaniel P. Berrange2013-12-041-4/+4
| | | | | | | | 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>
* Skip copying manually written python for C APIs which don't existDaniel P. Berrange2013-11-281-1/+41
| | | | | | | | | | | | | | | | | | 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>
* Fix code for avoiding overrides of non-existant functionsDaniel P. Berrange2013-11-281-0/+6
| | | | | | | | | | | 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>
* Deal with old filenames for events/error functionsDaniel P. Berrange2013-11-281-2/+5
| | | | | | | | | | 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>
* Add missing binding of security model/label APIsv1.2.0-rc2Daniel P. Berrange2013-11-271-3/+3
| | | | | | | | The virNodeGetSecurityModel, virDomainGetSecurityLabel and virDomainGetSecurityLabelList methods were disabled in the python binding for inexplicable reasons. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Avoid generating the methods in multiple classesDaniel P. Berrange2013-11-271-0/+2
| | | | | | | | | | | | | | | | | | | | | 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>
* Don't include virDomainSnapshotRef in python APIDaniel P. Berrange2013-11-271-1/+2
| | | | | | | 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>
* Ensure API overrides only used if API existsDaniel P. Berrange2013-11-221-0/+15
| | | | | | | 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>
* Break generator.py to be called per moduleDoug Goldstein2013-11-221-12/+12
| | | | | | | 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.
* Update generator for new code layoutDaniel P. Berrange2013-11-221-44/+25
| | | | | | | Change the generator.py to - Take XML API file names on command line - Generate data in build/ directory instead of cwd
* python: remove virConnectGetCPUModelNames from globalsDoug Goldstein2013-11-211-0/+1
| | | | | | | | | | 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.
* python: remove virConnectGetCPUModelNames from globalsDoug Goldstein2013-11-211-1/+0
| | | | | | | 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.
* maint: avoid 'const fooPtr' in python bindingsCVE-2013-4401CVE-2013-4400-2CVE-2013-4400-1Eric Blake2013-10-141-11/+0
| | | | | | | | | | | | | | | '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>
* python: add bindings for virConnectGetCPUModelNamesv1.1.3-rc2v1.1.3-rc1CVE-2013-4399Giuseppe Scrivano2013-09-231-1/+1
| | | | | Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com> Signed-off-by: Eric Blake <eblake@redhat.com>
* libvirt: add new public API virConnectGetCPUModelNamesGiuseppe Scrivano2013-09-231-0/+1
| | | | | | | | 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>
* docs, comments: minor typo fixesCVE-2013-4311CVE-2013-4296Oskari Saarenmaa2013-09-101-4/+4
| | | | | Signed-off-by: Oskari Saarenmaa <os@ohmu.fi> Signed-off-by: Eric Blake <eblake@redhat.com>
* python: simplify complicated conditional assignmentv1.1.2-rc1Claudio Bley2013-08-231-2/+1
|
* Test for object identity when checking for None in PythonClaudio Bley2013-08-231-15/+15
| | | | | | | | | 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.
* Introduce new domain create APIs to pass pre-opened FDs to LXCDaniel P. Berrange2013-07-181-0/+3
| | | | | | | | | | | | | | | | | | | | 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>
* Extensible migration APIsJiri Denemark2013-06-251-0/+2
| | | | | | | | | | | | | 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.
* python: set default value to optional argumentsv1.0.4-rc2v1.0.4Guannan Ren2013-03-261-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* python:remove semicolon in python codev1.0.4-rc1Guannan Ren2013-03-221-1/+1
| | | | | | This breaked "make syntax-check" testing Pushed under trivial rule
* python: treat flags as default argument with value 0Guannan Ren2013-03-221-0/+2
| | | | | | | | | | | The following four functions have not changed because default arguments have to come after positional arguments. Changing them will break the the binding APIs. migrate(self, dconn, flags, dname, uri, bandwidth): migrate2(self, dconn, dxml, flags, dname, uri, bandwidth): migrateToURI(self, duri, flags, dname, bandwidth): migrateToURI2(self, dconnuri, miguri, dxml, flags, dname, bandwidth):
* python: Fix emulatorpin API bindingsPeter Krempa2013-03-211-0/+2
| | | | | | | | | | The addition of emulator pinning APIs didn't think of doing the right job with python APIs for them. The default generator produced unusable code for this. This patch switches to proper code as in the case of domain Vcpu pining. This change can be classified as a python API-breaker but in the state the code was before I doubt anyone was able to use it successfully.
* python: fix bindings that don't raise an exceptionGuannan Ren2013-03-211-6/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For example: >>> dom.memoryStats() libvir: QEMU Driver error : Requested operation is not valid:\ domain is not running There are six such python API functions like so. The root reason is that generator.py script checks the type of return value of a python stub function defined in libvirt-api.xml or libvirt-override-api.xml to see whether to add the raise clause or not in python wrapper code in libvirt.py. The type of return value is supposed to be C types. For those stub functions which return python non-integer data type like string, list, tuple, dictionary, the existing type in functions varies from each other which leads problem like this. Currently, in generator.py, it maintains a buggy whitelist for stub functions returning a list type. I think it is easy to forget adding new function name in the whitelist. This patch makes the value of type consistent with C type "char *" in libvirt-override-api.xml. For python, any of types could be printed as string, so I choose "char *" in this case. And the comment in xml could explain it when adding new function definition. <function name='virNodeGetCPUStats' file='python'> ... - <return type='virNodeCPUStats' info='...'/> + <return type='char *' info='...'/> ... </function>
* Apply security label when entering LXC namespacesDaniel P. Berrange2013-03-131-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a new virDomainLxcEnterSecurityLabel() function as a counterpart to virDomainLxcEnterNamespaces(), which can change the current calling process to have a new security context. This call runs client side, not in libvirtd so we can't use the security driver infrastructure. When entering a namespace, the process spawned from virsh will default to running with the security label of virsh. The actual desired behaviour is to run with the security label of the container most of the time. So this changes virsh lxc-enter-namespace command to invoke the virDomainLxcEnterSecurityLabel method. The current behaviour is: LABEL PID TTY TIME CMD system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 1 pts/0 00:00:00 systemd system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 3 pts/1 00:00:00 sh system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 24 ? 00:00:00 systemd-journal system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 29 ? 00:00:00 dhclient staff_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 47 ? 00:00:00 ps Note the ps command is running as unconfined_t, After this patch, The new behaviour is this: virsh -c lxc:/// lxc-enter-namespace dan -- /bin/ps -eZ LABEL PID TTY TIME CMD system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 1 pts/0 00:00:00 systemd system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 3 pts/1 00:00:00 sh system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 24 ? 00:00:00 systemd-journal system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 32 ? 00:00:00 dhclient system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 38 ? 00:00:00 ps The '--noseclabel' flag can be used to skip security labelling. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* python: fix fd leak in generator.pyv1.0.3Guannan Ren2013-03-011-0/+3
|
* python: fix typoes and repeated global vars referencesGuannan Ren2013-03-011-5/+2
|
* Introduce virDomainMigrate*CompressionCache APIsJiri Denemark2013-02-221-0/+1
| | | | | Introduce virDomainMigrateGetCompressionCache and virDomainMigrateSetCompressionCache APIs.
* Introduce virDomainGetJobStats APIJiri Denemark2013-02-221-0/+1
| | | | This is an extensible version of virDomainGetJobInfo.
* Remove more trailing semicolons in Python filesGuido Günther2013-02-071-73/+73
|
* Fix missing error constants in libvirt python moduleDaniel P. Berrange2013-02-051-1/+3
| | | | | | | | | | The previous change to the generator, changed too much - only the functions are in 'virerror.c', the constants remained in 'virerror.h' which could not be renamed for API compat reasons. Add a test case to sanity check the generated python bindings Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* complete virterror->virerror name changeSerge Hallyn2013-01-311-2/+2
| | | | | | | | | Without these two string changes in generator.py, the virGetLastError wrapper does not get created in /usr/share/pyshared/libvirt.py. Noticed when running tests with virt-install. Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
* python: Fix bindings for virDomainSnapshotGet{Domain,Connect}v1.0.2-rc2v1.0.2CVE-2013-0170Jiri Denemark2013-01-241-1/+3
| | | | | | | | | | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=895882 virDomainSnapshot.getDomain() and virDomainSnapshot.getConnect() wrappers around virDomainSnapshotGet{Domain,Connect} were not supposed to be ever implemented. The class should contain proper domain() and connect() accessors that fetch python objects stored internally within the class. While domain() was already provided, connect() was missing. This patch adds connect() method to virDomainSnapshot class and reimplements getDomain() and getConnect() methods as aliases to domain() and connect() for backward compatibility.
* Make python objects inherit from 'object' base classDaniel P. Berrange2013-01-241-1/+1
| | | | | | | | | | | | | As of python >= 2.2, it is recommended that all objects inherit from the 'object' base class. We already require python >= 2.3 for libvirt for thread macro support, so we should follow this best practice. See also http://stackoverflow.com/questions/4015417/python-class-inherits-object Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* Introduce virTypedParamsClear public APIv1.0.2-rc1Jiri Denemark2013-01-181-0/+1
| | | | | The function is just a renamed public version of former virTypedParameterArrayClear.
* Add virTypedParams* APIsJiri Denemark2013-01-181-0/+19
| | | | | | | Working with virTypedParameters in clients written in C is ugly and requires all clients to duplicate the same code. This set of APIs makes this code for manipulating with virTypedParameters integral part of libvirt so that all clients may benefit from it.
* Fix build due to previous LXC patchDaniel P. Berrange2013-01-141-0/+1
| | | | | | Mark virDomainLxcEnterNamespace as skipped in python binding and remove reference to lxcDomainOpenNamespace which doesn't arrive until a later patch
* Introduce an LXC specific public API & libraryDaniel P. Berrange2013-01-141-1/+171
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch introduces support for LXC specific public APIs. In common with what was done for QEMU, this creates a libvirt_lxc.so library and libvirt/libvirt-lxc.h header file. The actual APIs are int virDomainLxcOpenNamespace(virDomainPtr domain, int **fdlist, unsigned int flags); int virDomainLxcEnterNamespace(virDomainPtr domain, unsigned int nfdlist, int *fdlist, unsigned int *noldfdlist, int **oldfdlist, unsigned int flags); which provide a way to use the setns() system call to move the calling process into the container's namespace. It is not practical to write in a generically applicable manner. The nearest that we could get to such an API would be an API which allows to pass a command + argv to be executed inside a container. Even if we had such a generic API, this LXC specific API is still useful, because it allows the caller to maintain the current process context, in particular any I/O streams they have open. NB the virDomainLxcEnterNamespace() API is special in that it runs client side, so does not involve the internal driver API. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
* python: Adapt to virevent renameMichal Privoznik2012-12-281-1/+1
| | | | | | | | | | | | | | | | | | | With our recent renames under src/util/* we forgot to adapt python wrapper code generator. This results in some methods being not exposed: $ python examples/domain-events/events-python/event-test.py Using uri:qemu:///system Traceback (most recent call last): File "examples/domain-events/events-python/event-test.py", line 585, in <module> main() File "examples/domain-events/events-python/event-test.py", line 543, in main virEventLoopPureStart() File "examples/domain-events/events-python/event-test.py", line 416, in virEventLoopPureStart virEventLoopPureRegister() File "examples/domain-events/events-python/event-test.py", line 397, in virEventLoopPureRegister libvirt.virEventRegisterImpl(virEventAddHandleImpl, AttributeError: 'module' object has no attribute 'virEventRegisterImpl'
* Bind connection close callback APIs to python bindingDaniel P. Berrange2012-12-041-2/+3
| | | | | | | | | Add code in the python binding to cope with the new APIs virConnectRegisterCloseCallback and virConnectUnregisterCloseCallback. Also demonstrate their use in the python domain events demo Signed-off-by: Daniel P. Berrange <berrange@redhat.com>