File Coverage

lib/Rex/Virtualization/LibVirt/option.pm
Criterion Covered Total %
statement 11 27 40.7
branch 0 8 0.0
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 15 41 36.5


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Virtualization::LibVirt::option;
6              
7 1     1   14 use v5.12.5;
  1         3  
8 1     1   6 use warnings;
  1         2  
  1         53  
9              
10             our $VERSION = '1.14.2.3'; # TRIAL VERSION
11              
12 1     1   7 use Rex::Logger;
  1         2  
  1         14  
13 1     1   24 use Rex::Helper::Run;
  1         12  
  1         366  
14              
15             my $FUNC_MAP = {
16             max_memory => "setmaxmem",
17             memory => "setmem",
18             };
19              
20             sub execute {
21 0     0 0   my ( $class, $arg1, %opt ) = @_;
22 0           my $virt_settings = Rex::Config->get("virtualization");
23             chomp( my $uri =
24 0 0         ref($virt_settings) ? $virt_settings->{connect} : i_run "virsh uri" );
25              
26 0 0         unless ($arg1) {
27 0           die("You have to define the vm name!");
28             }
29              
30 0           my $dom = $arg1;
31 0           Rex::Logger::debug("setting some options for: $dom");
32              
33 0           for my $opt ( keys %opt ) {
34 0           my $val = $opt{$opt};
35              
36 0 0         unless ( exists $FUNC_MAP->{$opt} ) {
37 0           Rex::Logger::info("$opt can't be set right now.");
38 0           next;
39             }
40              
41 0           my $func = $FUNC_MAP->{$opt};
42 0           i_run "virsh -c $uri $func '$dom' '$val'", fail_ok => 1;
43 0 0         if ( $? != 0 ) {
44 0           Rex::Logger::info( "Error setting $opt to $val on $dom ($@)", "warn" );
45             }
46              
47             }
48              
49             }
50              
51             1;