File: events.pl

package info (click to toggle)
libsys-virt-perl 11.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,036 kB
  • sloc: perl: 2,175; sh: 12; makefile: 3
file content (50 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/perl


use Sys::Virt;
use Sys::Virt::Event;

my $uri = shift @ARGV;

Sys::Virt::Event::register_default();

my $quit = 0;

my $c = Sys::Virt->new(uri => $uri, readonly => 1);

sub lifecycle_event {
    my $conn = shift;
    my $dom = shift;
    my $event = shift;
    my $detail = shift;

    printf "%s %s %d %d\n", $conn->get_uri, $dom->get_name, $event, $detail;
}

sub agent_lifecycle_event {
    my $conn = shift;
    my $dom = shift;
    my $state = shift;
    my $reason = shift;

    printf "Agent %s %s state=%d reason=%d\n", $conn->get_uri, $dom->get_name, $state, $reason;
}

$c->domain_event_register_any(undef,
			      Sys::Virt::Domain::EVENT_ID_LIFECYCLE,
			      \&lifecycle_event);
$c->domain_event_register_any(undef,
			      Sys::Virt::Domain::EVENT_ID_AGENT_LIFECYCLE,
			      \&agent_lifecycle_event);

$c->register_close_callback(
    sub {
	my $con = shift ;
	my $reason = shift ;
	print "Closed reason=$reason\n";
	$quit = 1;
    });

while (!$quit) {
    Sys::Virt::Event::run_default();
}