line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Rex::WebUI::Model::RexInterface; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
530
|
use Rex -base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Rex::Batch; |
9
|
|
|
|
|
|
|
use Rex::Group; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Data::Dumper; |
12
|
|
|
|
|
|
|
use Try::Tiny; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { bless {}, shift } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub get_task |
18
|
|
|
|
|
|
|
{ |
19
|
|
|
|
|
|
|
my ($self, $task) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $tasklist = $self->get_tasklist; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
if ($tasklist->is_task("$task")) { |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
warn "Loading task: $task"; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$task = { |
28
|
|
|
|
|
|
|
%{$tasklist->get_task($task)->get_data}, |
29
|
|
|
|
|
|
|
name => $task, |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return $task; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else { |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
warn "task '$task' not found"; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return undef; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_tasks |
43
|
|
|
|
|
|
|
{ |
44
|
|
|
|
|
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $tasks; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
if ($tasks = $self->{tasks}) { |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$self->log->debug("Tasks already loaded"); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $tasklist = $self->get_tasklist; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$tasks = [ $tasklist->get_tasks ]; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# get the task details for each - possibly more info we want here |
59
|
|
|
|
|
|
|
foreach my $task (@$tasks) { |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$task = { |
62
|
|
|
|
|
|
|
name => $task, |
63
|
|
|
|
|
|
|
desc => $tasklist->get_desc("$task") || $task, |
64
|
|
|
|
|
|
|
}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return $tasks; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get_tasklist |
72
|
|
|
|
|
|
|
{ |
73
|
|
|
|
|
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
if (my $tasklist = $self->{tasklist}) { |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return $tasklist; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else { |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$self->load_rexfile; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $tasklist = Rex::TaskList->create(); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return $self->{tasklist} = $tasklist; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub get_servers |
90
|
|
|
|
|
|
|
{ |
91
|
|
|
|
|
|
|
my $self = shift; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $servers = []; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $tasks = $self->get_tasks; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# build a list of server names from the task list |
98
|
|
|
|
|
|
|
foreach my $task (@$tasks) { |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$task = $self->get_task($task->{name}); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $task_servers = $task->{server}; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
next unless $task_servers && scalar @$task_servers > 0; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
foreach my $server (@$task_servers) { |
107
|
|
|
|
|
|
|
push @$servers, $server->{name} unless $server->{name} ~~ $servers; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# expand server list into hashrefs, adding info from db if available |
112
|
|
|
|
|
|
|
# TODO: add db interface |
113
|
|
|
|
|
|
|
foreach my $server (@$servers) { |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$server = { name => $server}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
return $servers; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub load_rexfile |
122
|
|
|
|
|
|
|
{ |
123
|
|
|
|
|
|
|
my ($self, $rexfile) = @_; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
$rexfile = $self->{rexfile} || "SampleRexfile" unless $rexfile; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
$Rex::TaskList::task_list = {}; |
129
|
|
|
|
|
|
|
$self->{tasks} = undef; |
130
|
|
|
|
|
|
|
delete $self->{tasks}; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$self->{tasklist} = undef; |
133
|
|
|
|
|
|
|
delete $self->{tasklist}; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Is rexfile already loaded? |
136
|
|
|
|
|
|
|
if (exists $self->{rexfiles}->{$rexfile}) { |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
warn "Rexfile already loaded: $rexfile, use tasklist from cache"; |
139
|
|
|
|
|
|
|
$Rex::TaskList::task_list = $self->{rexfiles}->{$rexfile}; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$self->{rexfile} = $rexfile; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
return 1; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# workaround namespace issues - Rex::CLI is handled already for this issue |
147
|
|
|
|
|
|
|
if (defined _hacky_do_rexfile($rexfile)) { |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
warn "Loaded Rexfile: $rexfile"; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
$self->{rexfile} = $rexfile; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
$self->{rexfiles}->{$rexfile} = $Rex::TaskList::task_list; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
return 1; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
else { |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
warn "Error loading Rexfile: $rexfile - $@"; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
return $self->{rexfile} = undef; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub _hacky_do_rexfile |
166
|
|
|
|
|
|
|
{ |
167
|
|
|
|
|
|
|
my $filename = shift; |
168
|
|
|
|
|
|
|
my $rexfile = eval { local(@ARGV, $/) = ($filename); <>; }; |
169
|
|
|
|
|
|
|
eval "package Rex::CLI; use Rex -base; $rexfile"; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
if($@) { |
172
|
|
|
|
|
|
|
die("Error loading Rexfile: $@"); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
return $rexfile; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# I'm getting a weird conflict with Rex::Commands::run_task so I'm renaming this to something more obscure |
179
|
|
|
|
|
|
|
sub do_run_task |
180
|
|
|
|
|
|
|
{ |
181
|
|
|
|
|
|
|
my ($self, $task_name, $server_name, $temp_logfile) = @_; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Rex::Config->set_log_filename($temp_logfile) if $temp_logfile; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
my $result; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
try { |
188
|
|
|
|
|
|
|
$result = Rex::Commands::run_task("$task_name", on => $server_name); |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Rex::Logger::info("DONE"); |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
return $result; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
catch { |
195
|
|
|
|
|
|
|
Rex::Logger::info("Task Failed: $_", 'error'); |
196
|
|
|
|
|
|
|
return undef; |
197
|
|
|
|
|
|
|
}; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub options |
201
|
|
|
|
|
|
|
{ |
202
|
|
|
|
|
|
|
my ($self, $opts) = @_; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
$Rex::Logger::debug = $opts->{debug} if exists $opts->{debug}; |
205
|
|
|
|
|
|
|
$Rex::Cache::USE = $opts->{cache} if exists $opts->{cache}; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
1; |
210
|
|
|
|
|
|
|
|