| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Resource; |
|
6
|
|
|
|
|
|
|
|
|
7
|
32
|
|
|
32
|
|
424
|
use v5.12.5; |
|
|
32
|
|
|
|
|
124
|
|
|
8
|
32
|
|
|
32
|
|
188
|
use warnings; |
|
|
32
|
|
|
|
|
73
|
|
|
|
32
|
|
|
|
|
1897
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.3'; # TRIAL VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
32
|
|
|
32
|
|
417
|
use Rex::Constants; |
|
|
32
|
|
|
|
|
90
|
|
|
|
32
|
|
|
|
|
218
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @CURRENT_RES; |
|
15
|
|
|
|
|
|
|
|
|
16
|
55
|
100
|
|
55
|
0
|
380
|
sub is_inside_resource { ref $CURRENT_RES[-1] ? 1 : 0 } |
|
17
|
18
|
|
|
18
|
0
|
217
|
sub get_current_resource { $CURRENT_RES[-1] } |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
|
20
|
36
|
|
|
36
|
0
|
99
|
my $that = shift; |
|
21
|
36
|
|
33
|
|
|
339
|
my $proto = ref($that) || $that; |
|
22
|
36
|
|
|
|
|
149
|
my $self = {@_}; |
|
23
|
|
|
|
|
|
|
|
|
24
|
36
|
|
|
|
|
87
|
bless( $self, $proto ); |
|
25
|
|
|
|
|
|
|
|
|
26
|
36
|
|
|
|
|
253
|
$self->{__status__} = "unchanged"; |
|
27
|
|
|
|
|
|
|
|
|
28
|
36
|
|
|
|
|
113
|
return $self; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
0
|
0
|
sub name { (shift)->{name}; } |
|
32
|
14
|
|
|
14
|
0
|
242
|
sub display_name { (shift)->{display_name}; } |
|
33
|
0
|
|
|
0
|
0
|
0
|
sub type { (shift)->{type}; } |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub call { |
|
36
|
4
|
|
|
4
|
0
|
26
|
my ( $self, $name, %params ) = @_; |
|
37
|
|
|
|
|
|
|
|
|
38
|
4
|
50
|
|
|
|
26
|
if ( ref $name eq "HASH" ) { |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# multiple resource call |
|
41
|
0
|
|
|
|
|
0
|
for my $n ( keys %{$name} ) { |
|
|
0
|
|
|
|
|
0
|
|
|
42
|
0
|
|
|
|
|
0
|
$self->call( $n, %{ $name->{$n} } ); |
|
|
0
|
|
|
|
|
0
|
|
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
return; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
4
|
|
|
|
|
21
|
push @CURRENT_RES, $self; |
|
49
|
|
|
|
|
|
|
|
|
50
|
4
|
|
|
|
|
37
|
$self->set_all_parameters(%params); |
|
51
|
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
30
|
$self->{res_name} = $name; |
|
53
|
4
|
|
33
|
|
|
57
|
$self->{res_ensure} = $params{ensure} ||= present; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Rex::get_current_connection()->{reporter} |
|
56
|
4
|
|
|
|
|
21
|
->report_resource_start( type => $self->display_name, name => $name ); |
|
57
|
|
|
|
|
|
|
|
|
58
|
4
|
|
|
|
|
14
|
my $failed = 0; |
|
59
|
|
|
|
|
|
|
eval { |
|
60
|
4
|
|
|
|
|
36
|
$self->{cb}->( \%params ); |
|
61
|
4
|
|
|
|
|
5972
|
1; |
|
62
|
4
|
50
|
|
|
|
10
|
} or do { |
|
63
|
0
|
|
|
|
|
0
|
Rex::Logger::info( $@, "error" ); |
|
64
|
0
|
|
|
|
|
0
|
Rex::Logger::info( "Resource execution failed: $name", "error" ); |
|
65
|
0
|
|
|
|
|
0
|
$failed = 1; |
|
66
|
|
|
|
|
|
|
}; |
|
67
|
|
|
|
|
|
|
|
|
68
|
4
|
100
|
|
|
|
23
|
if ( $self->was_updated ) { |
|
69
|
|
|
|
|
|
|
Rex::get_current_connection()->{reporter}->report( |
|
70
|
1
|
|
|
|
|
4
|
changed => 1, |
|
71
|
|
|
|
|
|
|
failed => $failed, |
|
72
|
|
|
|
|
|
|
message => $self->message, |
|
73
|
|
|
|
|
|
|
); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
else { |
|
76
|
|
|
|
|
|
|
Rex::get_current_connection()->{reporter}->report( |
|
77
|
3
|
|
|
|
|
29
|
changed => 0, |
|
78
|
|
|
|
|
|
|
failed => $failed, |
|
79
|
|
|
|
|
|
|
message => $self->display_name . " not changed.", |
|
80
|
|
|
|
|
|
|
); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
4
|
50
|
33
|
|
|
23
|
if ( exists $params{on_change} && $self->was_updated ) { |
|
84
|
0
|
|
|
|
|
0
|
$params{on_change}->( $self->{__status__} ); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Rex::get_current_connection()->{reporter} |
|
88
|
4
|
|
|
|
|
19
|
->report_resource_end( type => $self->display_name, name => $name ); |
|
89
|
|
|
|
|
|
|
|
|
90
|
4
|
|
|
|
|
119
|
pop @CURRENT_RES; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub was_updated { |
|
94
|
4
|
|
|
4
|
0
|
19
|
my ($self) = @_; |
|
95
|
|
|
|
|
|
|
|
|
96
|
4
|
50
|
66
|
|
|
35
|
if ( $self->changed || $self->created || $self->removed ) { |
|
|
|
|
66
|
|
|
|
|
|
97
|
1
|
|
|
|
|
4
|
return 1; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
3
|
|
|
|
|
26
|
return 0; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub changed { |
|
104
|
5
|
|
|
5
|
0
|
20
|
my ( $self, $changed ) = @_; |
|
105
|
|
|
|
|
|
|
|
|
106
|
5
|
100
|
|
|
|
33
|
if ( defined $changed ) { |
|
107
|
1
|
|
|
|
|
12
|
$self->{__status__} = "changed"; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
else { |
|
110
|
4
|
100
|
|
|
|
78
|
return ( $self->{__status__} eq "changed" ? 1 : 0 ); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub created { |
|
115
|
3
|
|
|
3
|
0
|
24
|
my ( $self, $created ) = @_; |
|
116
|
|
|
|
|
|
|
|
|
117
|
3
|
50
|
|
|
|
36
|
if ( defined $created ) { |
|
118
|
0
|
|
|
|
|
0
|
$self->{__status__} = "created"; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
else { |
|
121
|
3
|
50
|
|
|
|
83
|
return ( $self->{__status__} eq "created" ? 1 : 0 ); |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub removed { |
|
126
|
3
|
|
|
3
|
0
|
20
|
my ( $self, $removed ) = @_; |
|
127
|
|
|
|
|
|
|
|
|
128
|
3
|
50
|
|
|
|
27
|
if ( defined $removed ) { |
|
129
|
0
|
|
|
|
|
0
|
$self->{__status__} = "removed"; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
else { |
|
132
|
3
|
50
|
|
|
|
85
|
return ( $self->{__status__} eq "removed" ? 1 : 0 ); |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub message { |
|
137
|
1
|
|
|
1
|
0
|
9
|
my ( $self, $message ) = @_; |
|
138
|
|
|
|
|
|
|
|
|
139
|
1
|
50
|
|
|
|
4
|
if ( defined $message ) { |
|
140
|
0
|
|
|
|
|
0
|
$self->{message} = $message; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
else { |
|
143
|
1
|
|
33
|
|
|
11
|
return ( $self->{message} || ( $self->display_name . " changed." ) ); |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub set_parameter { |
|
148
|
4
|
|
|
4
|
0
|
21
|
my ( $self, $key, $value ) = @_; |
|
149
|
4
|
|
|
|
|
32
|
$self->{__res_parameters__}->{$key} = $value; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub set_all_parameters { |
|
153
|
4
|
|
|
4
|
0
|
16
|
my ( $self, %params ) = @_; |
|
154
|
4
|
|
|
|
|
38
|
$self->{__res_parameters__} = \%params; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub get_all_parameters { |
|
158
|
12
|
|
|
12
|
0
|
48
|
my ($self) = @_; |
|
159
|
12
|
|
|
|
|
78
|
return $self->{__res_parameters__}; |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; |