line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Resource; |
6
|
|
|
|
|
|
|
|
7
|
32
|
|
|
32
|
|
414
|
use v5.12.5; |
|
32
|
|
|
|
|
141
|
|
8
|
32
|
|
|
32
|
|
162
|
use warnings; |
|
32
|
|
|
|
|
68
|
|
|
32
|
|
|
|
|
1577
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.3'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
32
|
|
|
32
|
|
364
|
use Rex::Constants; |
|
32
|
|
|
|
|
121
|
|
|
32
|
|
|
|
|
222
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @CURRENT_RES; |
15
|
|
|
|
|
|
|
|
16
|
55
|
100
|
|
55
|
0
|
356
|
sub is_inside_resource { ref $CURRENT_RES[-1] ? 1 : 0 } |
17
|
18
|
|
|
18
|
0
|
203
|
sub get_current_resource { $CURRENT_RES[-1] } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
36
|
|
|
36
|
0
|
114
|
my $that = shift; |
21
|
36
|
|
33
|
|
|
301
|
my $proto = ref($that) || $that; |
22
|
36
|
|
|
|
|
142
|
my $self = {@_}; |
23
|
|
|
|
|
|
|
|
24
|
36
|
|
|
|
|
83
|
bless( $self, $proto ); |
25
|
|
|
|
|
|
|
|
26
|
36
|
|
|
|
|
259
|
$self->{__status__} = "unchanged"; |
27
|
|
|
|
|
|
|
|
28
|
36
|
|
|
|
|
111
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
0
|
0
|
sub name { (shift)->{name}; } |
32
|
14
|
|
|
14
|
0
|
218
|
sub display_name { (shift)->{display_name}; } |
33
|
0
|
|
|
0
|
0
|
0
|
sub type { (shift)->{type}; } |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub call { |
36
|
4
|
|
|
4
|
0
|
23
|
my ( $self, $name, %params ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
4
|
50
|
|
|
|
35
|
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
|
|
|
|
|
19
|
push @CURRENT_RES, $self; |
49
|
|
|
|
|
|
|
|
50
|
4
|
|
|
|
|
33
|
$self->set_all_parameters(%params); |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
21
|
$self->{res_name} = $name; |
53
|
4
|
|
33
|
|
|
52
|
$self->{res_ensure} = $params{ensure} ||= present; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Rex::get_current_connection()->{reporter} |
56
|
4
|
|
|
|
|
20
|
->report_resource_start( type => $self->display_name, name => $name ); |
57
|
|
|
|
|
|
|
|
58
|
4
|
|
|
|
|
15
|
my $failed = 0; |
59
|
|
|
|
|
|
|
eval { |
60
|
4
|
|
|
|
|
35
|
$self->{cb}->( \%params ); |
61
|
4
|
|
|
|
|
6972
|
1; |
62
|
4
|
50
|
|
|
|
8
|
} 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
|
|
|
|
45
|
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
|
|
|
|
|
19
|
changed => 0, |
78
|
|
|
|
|
|
|
failed => $failed, |
79
|
|
|
|
|
|
|
message => $self->display_name . " not changed.", |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
4
|
50
|
33
|
|
|
29
|
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
|
|
|
|
|
110
|
pop @CURRENT_RES; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub was_updated { |
94
|
4
|
|
|
4
|
0
|
21
|
my ($self) = @_; |
95
|
|
|
|
|
|
|
|
96
|
4
|
50
|
66
|
|
|
24
|
if ( $self->changed || $self->created || $self->removed ) { |
|
|
|
66
|
|
|
|
|
97
|
1
|
|
|
|
|
3
|
return 1; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
3
|
|
|
|
|
22
|
return 0; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub changed { |
104
|
5
|
|
|
5
|
0
|
30
|
my ( $self, $changed ) = @_; |
105
|
|
|
|
|
|
|
|
106
|
5
|
100
|
|
|
|
38
|
if ( defined $changed ) { |
107
|
1
|
|
|
|
|
11
|
$self->{__status__} = "changed"; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else { |
110
|
4
|
100
|
|
|
|
81
|
return ( $self->{__status__} eq "changed" ? 1 : 0 ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub created { |
115
|
3
|
|
|
3
|
0
|
20
|
my ( $self, $created ) = @_; |
116
|
|
|
|
|
|
|
|
117
|
3
|
50
|
|
|
|
29
|
if ( defined $created ) { |
118
|
0
|
|
|
|
|
0
|
$self->{__status__} = "created"; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else { |
121
|
3
|
50
|
|
|
|
58
|
return ( $self->{__status__} eq "created" ? 1 : 0 ); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub removed { |
126
|
3
|
|
|
3
|
0
|
31
|
my ( $self, $removed ) = @_; |
127
|
|
|
|
|
|
|
|
128
|
3
|
50
|
|
|
|
29
|
if ( defined $removed ) { |
129
|
0
|
|
|
|
|
0
|
$self->{__status__} = "removed"; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
else { |
132
|
3
|
50
|
|
|
|
101
|
return ( $self->{__status__} eq "removed" ? 1 : 0 ); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub message { |
137
|
1
|
|
|
1
|
0
|
4
|
my ( $self, $message ) = @_; |
138
|
|
|
|
|
|
|
|
139
|
1
|
50
|
|
|
|
3
|
if ( defined $message ) { |
140
|
0
|
|
|
|
|
0
|
$self->{message} = $message; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
else { |
143
|
1
|
|
33
|
|
|
23
|
return ( $self->{message} || ( $self->display_name . " changed." ) ); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub set_parameter { |
148
|
4
|
|
|
4
|
0
|
23
|
my ( $self, $key, $value ) = @_; |
149
|
4
|
|
|
|
|
24
|
$self->{__res_parameters__}->{$key} = $value; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub set_all_parameters { |
153
|
4
|
|
|
4
|
0
|
18
|
my ( $self, %params ) = @_; |
154
|
4
|
|
|
|
|
40
|
$self->{__res_parameters__} = \%params; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub get_all_parameters { |
158
|
12
|
|
|
12
|
0
|
68
|
my ($self) = @_; |
159
|
12
|
|
|
|
|
80
|
return $self->{__res_parameters__}; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; |