File Coverage

blib/lib/Linux/Virt/Plugin/KVM.pm
Criterion Covered Total %
statement 19 39 48.7
branch 0 8 0.0
condition n/a
subroutine 7 11 63.6
pod n/a
total 26 58 44.8


line stmt bran cond sub pod time code
1             package Linux::Virt::Plugin::KVM;
2             {
3             $Linux::Virt::Plugin::KVM::VERSION = '0.15';
4             }
5             BEGIN {
6 1     1   3724 $Linux::Virt::Plugin::KVM::AUTHORITY = 'cpan:TEX';
7             }
8             # ABSTRACT: KVM plugin for Linux::Virt
9              
10 1     1   71 use 5.010_000;
  1         4  
  1         43  
11 1     1   7 use mro 'c3';
  1         2  
  1         108  
12 1     1   38 use feature ':5.10';
  1         2  
  1         210  
13              
14 1     1   8 use Moose;
  1         3  
  1         11  
15 1     1   11748 use namespace::autoclean;
  1         4  
  1         10  
16              
17             # use IO::Handle;
18             # use autodie;
19             # use MooseX::Params::Validate;
20              
21             extends 'Linux::Virt::Plugin::Libvirt';
22              
23 0     0     sub _init_priority { return 10; }
24              
25             sub _init_type {
26 0     0     return 'kvm';
27             }
28              
29             sub is_host {
30 0     0     my $proc_modules = '/proc/modules';
31 0 0         if ( open( my $FH, '<', $proc_modules ) ) {
32 0           my @lines = <$FH>;
33 0           close($FH);
34 0           foreach my $line ( @lines ) {
35              
36             # is the kvm_{intel,amd,...} module loaded?
37 0 0         if ( $line =~ m/^kvm_/i ) {
38 0           close($FH);
39 0           return 1;
40             }
41             } ## end while ( my $line = <$FH> )
42             } ## end if ( open( my $FH, "<"...))
43 0           return;
44             } ## end sub is_host
45              
46             sub is_vm {
47              
48 0     0     my $proc_cpuinfo = '/proc/cpuinfo';
49 0 0         if ( open( my $FH, '<', $proc_cpuinfo ) ) {
50 0           my @lines = <$FH>;
51 0           close($FH);
52 0           foreach my $line ( @lines ) {
53             # is this a QEMU CPU?
54 0 0         if ( $line =~ m/QEMU Virtual CPU/i ) {
55 0           close($FH);
56 0           return 1;
57             }
58             } ## end while ( my $line = <$FH> )
59             } ## end if ( open( my $FH, '<'...))
60 0           return;
61             } ## end sub is_vm
62              
63 1     1   566 no Moose;
  1         3  
  1         6  
64             __PACKAGE__->meta->make_immutable;
65              
66             1;
67              
68             __END__
69              
70             =pod
71              
72             =encoding utf-8
73              
74             =head1 NAME
75              
76             Linux::Virt::Plugin::KVM - KVM plugin for Linux::Virt
77              
78             =head1 METHODS
79              
80             =head2 is_host
81              
82             Returns a true value if run on a KVM capable host.
83              
84             =head2 is_vm
85              
86             Returns a true value if run inside a KVM VM.
87              
88             =head1 NAME
89              
90             Linux::Virt::Plugin::KVM - KVM plugin for Linux::Virt.
91              
92             =head1 AUTHOR
93              
94             Dominik Schulz <dominik.schulz@gauner.org>
95              
96             =head1 COPYRIGHT AND LICENSE
97              
98             This software is copyright (c) 2012 by Dominik Schulz.
99              
100             This is free software; you can redistribute it and/or modify it under
101             the same terms as the Perl 5 programming language system itself.
102              
103             =cut