| 1 | package Linux::Virt::Plugin::LXC; | ||||||||||||
| 2 | { | ||||||||||||
| 3 | 2 | $Linux::Virt::Plugin::LXC::VERSION = '0.15'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | 2 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | $Linux::Virt::Plugin::LXC::AUTHORITY = 'cpan:TEX'; | |||||||||||
| 7 | } | ||||||||||||
| 8 | # ABSTRACT: LXC (Linux Containers) plugin for Linux::Virt | ||||||||||||
| 9 | |||||||||||||
| 10 | 2 | ▶ | use 5.010_000; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 2 | ▶ | use mro 'c3'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 2 | ▶ | use feature ':5.10'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 2 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 2 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | |||||||||||||
| 17 | # use IO::Handle; | ||||||||||||
| 18 | # use autodie; | ||||||||||||
| 19 | # use MooseX::Params::Validate; | ||||||||||||
| 20 | |||||||||||||
| 21 | 2 | extends 'Linux::Virt::Plugin'; | |||||||||||
| 22 | |||||||||||||
| 23 | 0 | ▶ | sub _init_priority { return 10; } | ||||||||||
|
Subroutine
_init_priority: not called CC=1 SCAR=6.9
| |||||||||||||
| 24 | |||||||||||||
| 25 | 0 | ▶ | sub is_host { | ||||||||||
|
Subroutine
is_host: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 26 | 0 | my $self = shift; | |||||||||||
| 27 | 0 | ▶ | my $opts = shift || {}; | ||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 28 | |||||||||||||
| 29 | 0 | my $cmd = '/usr/bin/lxc-checkconfig'; | |||||||||||
| 30 | 0 | ▶ | return unless -x $cmd; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 0 | return $self->sys()->run_cmd( $cmd, $opts ); | |||||||||||
| 32 | } ## end sub is_host | ||||||||||||
| 33 | |||||||||||||
| 34 | 0 | ▶ | sub is_vm { | ||||||||||
|
Subroutine
is_vm: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||
| 36 | |||||||||||||
| 37 | # TODO can't find out, yet :( | ||||||||||||
| 38 | 0 | return; | |||||||||||
| 39 | } ## end sub is_vm | ||||||||||||
| 40 | |||||||||||||
| 41 | 0 | ▶ | sub vms { | ||||||||||
|
Subroutine
vms: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||
| 43 | 0 | my $vserver_ref = shift; | |||||||||||
| 44 | 0 | ▶ | my $opts = shift || {}; | ||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 45 | |||||||||||||
| 46 | 0 | ▶ | return unless -x '/usr/bin/lxc-ls'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | 0 | ▶ | return unless -x '/usr/bin/lxc-info'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | |||||||||||||
| 49 | 0 | local $ENV{LANG} = 'C'; | |||||||||||
| 50 | 0 | my $LXC; | |||||||||||
| 51 | 0 | ▶ | if ( !open( $LXC, '-|', '/usr/bin/lxc-ls' ) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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> ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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} ) { | |||||||||||
| 66 | 0 | ▶ | next if !$vserver_ref->{$vs}{'virt'}{'type'} eq 'lxc'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | 0 | local $opts->{'CaptureOutput'} = 1; | |||||||||||
| 68 | 0 | my $status = $self->sys()->run_cmd( '/usr/bin/lxc-info --name=' . $vs, $opts ); | |||||||||||
| 69 | 0 | ▶ | if ( $status !~ m/RUNNING/ ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | 2 | ▶ | no Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 77 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 78 | |||||||||||||
| 79 | 2 | 1; | |||||||||||
| 80 | |||||||||||||
| 81 | __END__ | ||||||||||||