| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Helper::Rexfile::ParamLookup; |
|
6
|
|
|
|
|
|
|
|
|
7
|
32
|
|
|
32
|
|
438
|
use v5.12.5; |
|
|
32
|
|
|
|
|
134
|
|
|
8
|
32
|
|
|
32
|
|
185
|
use warnings; |
|
|
32
|
|
|
|
|
75
|
|
|
|
32
|
|
|
|
|
1539
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.3'; # VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
32
|
|
|
32
|
|
414
|
use Devel::Caller; |
|
|
32
|
|
|
|
|
85373
|
|
|
|
32
|
|
|
|
|
1642
|
|
|
13
|
32
|
|
|
32
|
|
288
|
use Data::Dumper; |
|
|
32
|
|
|
|
|
68
|
|
|
|
32
|
|
|
|
|
1950
|
|
|
14
|
|
|
|
|
|
|
require Rex::Exporter; |
|
15
|
|
|
|
|
|
|
require Rex::Commands; |
|
16
|
|
|
|
|
|
|
|
|
17
|
32
|
|
|
32
|
|
203
|
use base qw(Rex::Exporter); |
|
|
32
|
|
|
|
|
76
|
|
|
|
32
|
|
|
|
|
2178
|
|
|
18
|
32
|
|
|
32
|
|
236
|
use vars qw (@EXPORT); |
|
|
32
|
|
|
|
|
175
|
|
|
|
32
|
|
|
|
|
14502
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
@EXPORT = qw(param_lookup); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub param_lookup { |
|
23
|
10
|
|
|
10
|
0
|
157
|
my ( $key, $default ) = @_; |
|
24
|
|
|
|
|
|
|
|
|
25
|
10
|
|
|
|
|
69
|
my $ret; |
|
26
|
|
|
|
|
|
|
|
|
27
|
10
|
|
|
|
|
117
|
my ($caller_pkg) = caller(0); |
|
28
|
|
|
|
|
|
|
|
|
29
|
10
|
|
|
|
|
85
|
my @args = Devel::Caller::caller_args(1); |
|
30
|
10
|
100
|
|
|
|
245
|
if ( ref $args[0] eq "HASH" ) { |
|
31
|
7
|
100
|
|
|
|
33
|
if ( exists $args[0]->{$key} ) { |
|
32
|
5
|
|
|
|
|
26
|
$ret = $args[0]->{$key}; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
10
|
100
|
|
|
|
41
|
if ( !$ret ) { |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# check if cmdb is loaded |
|
39
|
5
|
|
|
|
|
1091
|
my ($use_cmdb) = grep { m/CMDB\.pm/ } keys %INC; |
|
|
1342
|
|
|
|
|
2069
|
|
|
40
|
5
|
50
|
|
|
|
64
|
if ($use_cmdb) { |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# look inside cmdb |
|
43
|
5
|
|
|
|
|
25
|
my $cmdb_key = "${caller_pkg}::$key"; |
|
44
|
5
|
|
|
|
|
49
|
$ret = Rex::Commands::get( Rex::CMDB::cmdb($cmdb_key) ); |
|
45
|
|
|
|
|
|
|
|
|
46
|
5
|
50
|
|
|
|
20
|
if ( !$ret ) { |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# check in resource |
|
49
|
5
|
100
|
|
|
|
38
|
if ( Rex::Resource->is_inside_resource ) { |
|
50
|
2
|
|
|
|
|
17
|
$cmdb_key = |
|
51
|
|
|
|
|
|
|
Rex::Resource->get_current_resource->display_name . "::$key"; |
|
52
|
2
|
|
|
|
|
20
|
$ret = Rex::Commands::get( Rex::CMDB::cmdb($cmdb_key) ); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
5
|
100
|
|
|
|
48
|
if ( !$ret ) { |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# check in task |
|
58
|
4
|
|
|
|
|
35
|
my $task = Rex::Commands::task(); |
|
59
|
4
|
50
|
|
|
|
19
|
if ($task) { |
|
60
|
4
|
|
|
|
|
14
|
my $task_name = $task->{name}; |
|
61
|
4
|
|
|
|
|
22
|
$task_name =~ s/:/::/; |
|
62
|
4
|
|
|
|
|
30
|
$cmdb_key = $task_name . "::$key"; |
|
63
|
4
|
|
|
|
|
35
|
$ret = Rex::Commands::get( Rex::CMDB::cmdb($cmdb_key) ); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
5
|
100
|
|
|
|
69
|
if ( !$ret ) { |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# check in global namespace |
|
71
|
4
|
|
|
|
|
18
|
$ret = Rex::Commands::get( Rex::CMDB::cmdb($key) ); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
10
|
100
|
|
|
|
76
|
if ( !$ret ) { |
|
77
|
3
|
|
|
|
|
8
|
$ret = $default; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
10
|
100
|
|
|
|
78
|
if ( Rex::Resource->is_inside_resource ) { |
|
81
|
4
|
|
|
|
|
22
|
Rex::Resource->get_current_resource()->set_parameter( $key => $ret ); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
10
|
100
|
|
|
|
43
|
if ( !Rex::Resource->is_inside_resource ) { |
|
85
|
6
|
|
|
|
|
28
|
Rex::Commands::task()->set_opt( $key => $ret ); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
10
|
|
|
|
|
91
|
return $ret; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=pod |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Rex::Helper::Rexfile::ParamLookup - A command to manage task parameters. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
A command to manage task parameters. Additionally it register the parameters as template values. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This module also looks inside a CMDB (if present) for a valid key. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
task "setup", sub { |
|
107
|
|
|
|
|
|
|
my $var = param_lookup "param_name", "default_value"; |
|
108
|
|
|
|
|
|
|
}; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 LOOKUP |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
First I checks the task parameters for a valid parameter. If none is found and if a CMDB is used, it will look inside the cmdb. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
If your module is named "Rex::NTP" than it will first look if the key "Rex::NTP::param_name" exists. If it doesn't exists it checks for the key "param_name". |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |