line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Linux::Virt::Plugin::LXC; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Linux::Virt::Plugin::LXC::VERSION = '0.15'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
1
|
|
|
1
|
|
6057
|
$Linux::Virt::Plugin::LXC::AUTHORITY = 'cpan:TEX'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: LXC (Linux Containers) plugin for Linux::Virt |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
36
|
use 5.010_000; |
|
1
|
|
|
|
|
29
|
|
|
1
|
|
|
|
|
45
|
|
11
|
1
|
|
|
1
|
|
6
|
use mro 'c3'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
12
|
1
|
|
|
1
|
|
32
|
use feature ':5.10'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
159
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use Moose; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
15
|
1
|
|
|
1
|
|
10783
|
use namespace::autoclean; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
12
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# use IO::Handle; |
18
|
|
|
|
|
|
|
# use autodie; |
19
|
|
|
|
|
|
|
# use MooseX::Params::Validate; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
extends 'Linux::Virt::Plugin'; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
0
|
|
|
sub _init_priority { return 10; } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub is_host { |
26
|
0
|
|
|
0
|
|
|
my $self = shift; |
27
|
0
|
|
0
|
|
|
|
my $opts = shift || {}; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $cmd = '/usr/bin/lxc-checkconfig'; |
30
|
0
|
0
|
|
|
|
|
return unless -x $cmd; |
31
|
0
|
|
|
|
|
|
return $self->sys()->run_cmd( $cmd, $opts ); |
32
|
|
|
|
|
|
|
} ## end sub is_host |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub is_vm { |
35
|
0
|
|
|
0
|
|
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# TODO can't find out, yet :( |
38
|
0
|
|
|
|
|
|
return; |
39
|
|
|
|
|
|
|
} ## end sub is_vm |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub vms { |
42
|
0
|
|
|
0
|
|
|
my $self = shift; |
43
|
0
|
|
|
|
|
|
my $vserver_ref = shift; |
44
|
0
|
|
0
|
|
|
|
my $opts = shift || {}; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
return unless -x '/usr/bin/lxc-ls'; |
47
|
0
|
0
|
|
|
|
|
return unless -x '/usr/bin/lxc-info'; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
local $ENV{LANG} = 'C'; |
50
|
0
|
|
|
|
|
|
my $LXC; |
51
|
0
|
0
|
|
|
|
|
if ( !open( $LXC, '-|', '/usr/bin/lxc-ls' ) ) { |
52
|
0
|
|
|
|
|
|
my $msg = "Could not execute /usr/bin/lxc-ls! Is lxc installed?: $!"; |
53
|
0
|
|
|
|
|
|
$self->logger()->log( message => $msg, level => 'warning', ); |
54
|
0
|
|
|
|
|
|
return; |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
while ( my $line = <$LXC> ) { |
57
|
0
|
|
|
|
|
|
$line =~ s/^\s+//; |
58
|
0
|
|
|
|
|
|
$line =~ s/\s+$//; |
59
|
0
|
|
|
|
|
|
my $name = $line; |
60
|
0
|
|
|
|
|
|
$vserver_ref->{$name}{'virt'}{'type'} = 'lxc'; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} ## end while ( my $line = <$LXC>) |
63
|
0
|
|
|
|
|
|
close($LXC); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
foreach my $vs ( keys %{$vserver_ref} ) { |
|
0
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
next if !$vserver_ref->{$vs}{'virt'}{'type'} eq 'lxc'; |
67
|
0
|
|
|
|
|
|
local $opts->{'CaptureOutput'} = 1; |
68
|
0
|
|
|
|
|
|
my $status = $self->sys()->run_cmd( '/usr/bin/lxc-info --name=' . $vs, $opts ); |
69
|
0
|
0
|
|
|
|
|
if ( $status !~ m/RUNNING/ ) { |
70
|
0
|
|
|
|
|
|
delete( $vserver_ref->{$vs} ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} ## end foreach my $vs ( keys %{$vserver_ref...}) |
73
|
0
|
|
|
|
|
|
return 1; |
74
|
|
|
|
|
|
|
} ## end sub vms |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
1
|
|
665
|
no Moose; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
77
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=pod |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=encoding utf-8 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Linux::Virt::Plugin::LXC - LXC (Linux Containers) plugin for Linux::Virt |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 METHODS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 is_host |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Returns a true value if this is run on a LXC capable host. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 is_vm |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Returns a true value if this is run inside an LXC guest. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 vms |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Returns a list of all LXC VMs on the local host. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 NAME |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Linux::Virt::Plugin::LXC - LXC plugin for Linux::Virt. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 AUTHOR |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Dominik Schulz <dominik.schulz@gauner.org> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Dominik Schulz. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
118
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |