Commit Graph

33 Commits

Author SHA1 Message Date
Daniel P. Berrange
1465876a04 Bind connection close callback APIs to python binding
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>
2012-12-04 13:50:11 +00:00
Michal Privoznik
adb29a8869 Introduce new VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR event
This is supposed to be thrown every time we need to pause domain
because of API execution (e.g. qemuDomainSaveInternal) but fails
to restore it back after. In this case, domain remains paused,
however, none of existing reasons can fit this scenario.
2012-11-07 12:06:05 +01:00
Martin Kletzander
60f96bfc88 tests: Fix domain-events python test
There was a missing method in python implementation of domain-events
test and this patch adds that.
2012-10-16 16:37:29 +02:00
Martin Kletzander
7ba5defb5a Add support for SUSPEND_DISK event
This patch adds support for SUSPEND_DISK event; both lifecycle and
separated.  The support is added for QEMU, machines are changed to
PMSUSPENDED, but as QEMU sends SHUTDOWN afterwards, the state changes
to shut-off.  This and much more needs to be done in order for libvirt
to work with transient devices, wake-ups etc.  This patch is not
aiming for that functionality.
2012-10-15 12:09:10 +02:00
Ján Tomko
149c87b49d Various typos and misspellings 2012-10-12 00:03:43 +02:00
Jiri Denemark
e2a7f97b2b examples: Fix event detail printing in python test
If there is only one detail string for a particular event, we need to pu
comma after the string otherwise the string itself will be taken as a
list and only its first character will be printed out. For example,

    myDomainEventCallback1 EVENT: Domain fedora17(12) Shutdown F

instead of the desired

    myDomainEventCallback1 EVENT: Domain fedora17(12) Shutdown Finished
2012-09-07 09:38:22 +02:00
Jiri Denemark
fc4115e8d6 Add PMSUSPENDED life cycle event
While PMSUSPENDED state was added a long time ago, we didn't have
corresponding life cycle event.
2012-09-07 09:38:22 +02:00
Jiri Denemark
462c211232 examples: Update strings for event details 2012-08-09 15:34:47 +02:00
Royce Lv
5e62ba3428 adding handling EINTR to poll to make it more robust
some system call and signal will interrupt poll,
making event loop stops and fails to react events and keepalive message
from libvirt.
adding handling EINTR to poll to make it more robust

Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com>
2012-07-23 17:40:21 -06:00
Daniel P. Berrange
7ed6d7dda7 Define public API for receiving guest memory balloon events
When the guest changes its memory balloon applications may want
to know what the new value is, without having to periodically
poll on XML / domain info. Introduce a "balloon change" event
to let apps see this

* include/libvirt/libvirt.h.in: Define the
  virConnectDomainEventBalloonChangeCallback callback
  and VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE constant
* python/libvirt-override-virConnect.py,
  python/libvirt-override.c: Wire up helpers for new event
* daemon/remote.c: Helper for serializing balloon event
* examples/domain-events/events-c/event-test.c,
  examples/domain-events/events-python/event-test.py: Add
  example of balloon event usage
* src/conf/domain_event.c, src/conf/domain_event.h: Handling
  of balloon events
* src/remote/remote_driver.c: Add handler of balloon events
* src/remote/remote_protocol.x: Define wire protocol for
  balloon events
* src/remote_protocol-structs: Likewise.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-07-14 16:02:26 +08:00
Osier Yang
487c063381 Add support for the suspend event
This patch introduces a new event type for the QMP event
SUSPEND:

    VIR_DOMAIN_EVENT_ID_PMSUSPEND

The event doesn't take any data, but considering there might
be reason for wakeup in future, the callback definition is:

typedef void
(*virConnectDomainEventSuspendCallback)(virConnectPtr conn,
                                        virDomainPtr dom,
                                        int reason,
                                        void *opaque);

"reason" is unused currently, always passes "0".
2012-03-23 23:12:18 +08:00
Osier Yang
57ddcc235a Add support for the wakeup event
This patch introduces a new event type for the QMP event
WAKEUP:

    VIR_DOMAIN_EVENT_ID_PMWAKEUP

The event doesn't take any data, but considering there might
be reason for wakeup in future, the callback definition is:

typedef void
(*virConnectDomainEventWakeupCallback)(virConnectPtr conn,
                                       virDomainPtr dom,
                                       int reason,
                                       void *opaque);

"reason" is unused currently, always passes "0".
2012-03-23 23:12:14 +08:00
Osier Yang
a26a1969c3 Add support for event tray moved of removable disks
This patch introduces a new event type for the QMP event
DEVICE_TRAY_MOVED, which occurs when the tray of a removable
disk is moved (i.e opened or closed):

    VIR_DOMAIN_EVENT_ID_TRAY_CHANGE

The event's data includes the device alias and the reason
for tray status' changing, which indicates why the tray
status was changed. Thus the callback definition for the event
is:

enum {
    VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN = 0,
    VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE,

\#ifdef VIR_ENUM_SENTINELS
    VIR_DOMAIN_EVENT_TRAY_CHANGE_LAST
\#endif
} virDomainEventTrayChangeReason;

typedef void
(*virConnectDomainEventTrayChangeCallback)(virConnectPtr conn,
                                           virDomainPtr dom,
                                           const char *devAlias,
                                           int reason,
                                           void *opaque);
2012-03-23 23:10:26 +08:00
Jiri Denemark
9bfa132c70 examples: Update event tests for shutdown event 2011-12-05 17:35:29 +01:00
Jiri Denemark
6e945da567 Add keepalive support into domain-events examples 2011-11-24 12:00:10 +01:00
Michal Privoznik
baf2ff7e90 startupPolicy: Emit event on disk source dropping
If a disk source gets dropped because it is not accessible,
mgmt application might want to be informed about this. Therefore
we need to emit an event. The event presented in this patch
is however a bit superset of what written above. The reason is simple:
an intention to be easily expanded, e.g. on 'user ejected disk
in guest' events. Therefore, callback gets source string and disk alias
(which should be unique among a domain) and reason (an integer);
2011-10-25 09:27:10 +02:00
Philipp Hahn
f319b553c1 example: Support debug output and loop switch
Add support for enabling debug output via command line option.
Allow to toggle the loop implementation between pure-Python and
native-C.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2011-10-12 16:18:32 -06:00
Philipp Hahn
78adf5099f example: Redirect --help output to stdout/stderr
When --help is requested, print usage() to stdout.
When an illegal option is passed, print usage to stderr.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2011-10-12 16:14:28 -06:00
Philipp Hahn
08d56e24b0 example: Fix argument handling
sys.argv contains the original command line arguments, while args only
contains the arguments not handled by getopt(). Currently this is no
problem since --help is the only command line option passable, which
terminates the process, so the code is never reached. Any option added
in the future will reveal the bug.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2011-10-12 16:11:54 -06:00
Cole Robinson
f2fb235b1d python: events: Fix C->Python handle callback prototype
If registering our own event loop implementation written in python,
any handles or timeouts callbacks registered by libvirt C code must
be wrapped in a python function. There is some argument trickery that
makes this all work, by wrapping the user passed opaque value in
a tuple, along with the callback function.

Problem is, the current setup requires the user's event loop to know
about this trickery, rather than just treating the opaque value
as truly opaque.

Fix this in a backwards compatible manner, and adjust the example
python event loop to do things the proper way.
2011-06-21 10:08:48 -04:00
Daniel P. Berrange
0c97e70b74 Update event loop example programs to demonstrate best practice
The example C event loop code is a nasty hack and not compliant
with the require API semantics. Delete this, so that developers
don't mistakenly copy it. Instead call the new public event loop
APIs.

Update the python event loop example, so that it can optionally
use the public event APIs, as an alternative to the pure python
code. The pure python event code is a good working example, so
don't delete it.

Also make the python example use a read only connection to avoid
authentication prompts

* examples/domain-events/events-c/event-test.c: Replace event
  loop code with use of public APIs
* examples/domain-events/events-python/event-test.py: Allow
  optional use of new public event APIs
2011-03-29 10:59:46 +01:00
Daniel P. Berrange
331d7b09a7 Prevent overfilling of self-pipe in python event loop
If the event loop takes a very long time todo something, it is
possible for the 'self pipe' buffer to become full at which
point the entire event loop + remote driver deadlock. Use a
boolean flag to ensure we have strict one-in, one-out behaviour
on writes/reads of the 'self pipe'
2011-01-28 11:48:27 +00:00
Cole Robinson
8f3b6bc2dd event-test: Simplify debug on/off
Make it easy to change debugging if being used by a client program.
2011-01-10 14:44:04 -05:00
Daniel P. Berrange
de8ecb12cb Fix printing of event detail in python events demo program
The events demo program is slightly misleading printing

  myDomainEventCallback1 EVENT: Domain f14i686(-1) Added

which is not distinguishing Add vs Update events. It should have
been doing

  myDomainEventCallback1 EVENT: Domain f14i686(-1) Defined Updated

* examples/domain-events/events-python/event-test.py: Fully print
  event detail info string
2010-04-22 17:15:48 +01:00
Daniel P. Berrange
6df7d55d39 Fix up python bindings for new event callbacks
The generator was disabled for the new event callbacks, since they
need to be hand written. This patch  adds the C and python glue to
expose the new APIs in the python binding. The python example
program is extended to demonstrate of the code

* python/libvirt-override.c: Registration and dispatch of events
   at the C layer
* python/libvirt-override-virConnect.py: Python glue for events
* examples/domain-events/events-python/event-test.py: Demo use
  of new event callbacks
2010-04-08 12:41:40 +01:00
Philipp Hahn
1cfbfaa697 python example: poll(-0.001) does not sleep forever
The conversion from seconds to milliseconds should only be done for
actual delays >= 0, not for the magic -1 value used for infinite
timeouts.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2010-03-24 10:26:23 +01:00
Daniel P. Berrange
93f77250b3 Rewrite example domain events programm for python
The existing python demo for domain events does not fully
implement the event loop contract. This makes the code useless
for real world applications. This change re-writes the demo so
that it has a full event loop implementation which is suitable
for application usage & better demonstrates integration

* examples/domain-events/events-python/event-test.py: Rewrite
  to include a real world usable event loop implementation
2009-10-09 13:05:10 +01:00
Jim Meyering
07613d2020 remove all trailing blank lines
by running this command:
git ls-files -z | xargs -0 perl -pi -0777 -e 's/\n\n+$/\n/'
This is in preparation for a more strict make syntax-check
rule that will detect trailing blank lines.
2009-07-16 15:06:42 +02:00
Daniel P. Berrange
7c99cb93c5 Fix python domain events example & binding 2009-05-28 11:02:11 +00:00
Daniel P. Berrange
c673689430 Fix python bindings events code (David Lively) 2008-11-24 19:28:12 +00:00
Daniel P. Berrange
6d41cb87d3 Change public API for virEventAddHandle to allow multiple registrations per FD 2008-11-19 16:19:36 +00:00
Daniel P. Berrange
d3d54d2fc9 Add domain events detail information 2008-11-17 16:43:00 +00:00
Daniel Veillard
7b716fce8e * python/Makefile.am python/generator.py python/libvir.c
python/libvir.py python/libvirt_wrap.h python/types.c:
  adds support for events from the python bindings, also
  improves the generator allowing to embbed per function
  definition files, patch by Ben Guthro
* examples/domain-events/events-python/event-test.py: also
  adds a programming example
Daniel
2008-10-31 10:13:45 +00:00