| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Tapper::Cmd::Cobbler; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
|
3
|
|
|
|
|
|
|
$Tapper::Cmd::Cobbler::VERSION = '5.0.11'; |
|
4
|
2
|
|
|
2
|
|
96799
|
use warnings; |
|
|
2
|
|
|
|
|
18
|
|
|
|
2
|
|
|
|
|
67
|
|
|
5
|
2
|
|
|
2
|
|
13
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
42
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
544
|
use Moose; |
|
|
2
|
|
|
|
|
469959
|
|
|
|
2
|
|
|
|
|
14
|
|
|
8
|
2
|
|
|
2
|
|
14361
|
use Tapper::Model 'model'; |
|
|
2
|
|
|
|
|
1098997
|
|
|
|
2
|
|
|
|
|
122
|
|
|
9
|
2
|
|
|
2
|
|
17
|
use Tapper::Config; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
57
|
|
|
10
|
2
|
|
|
2
|
|
2137
|
use Net::OpenSSH; |
|
|
2
|
|
|
|
|
54715
|
|
|
|
2
|
|
|
|
|
94
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
23
|
use parent 'Tapper::Cmd'; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
17
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub get_mac_address |
|
18
|
|
|
|
|
|
|
{ |
|
19
|
0
|
|
|
0
|
1
|
0
|
my ($self, $host) = @_; |
|
20
|
0
|
|
|
|
|
0
|
my ($retval) = map{$_->value} grep{ $_->entry eq 'mac_address'} $host->features->all; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
21
|
0
|
|
|
|
|
0
|
return $retval; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub cobbler_execute |
|
26
|
|
|
|
|
|
|
{ |
|
27
|
0
|
|
|
0
|
1
|
0
|
my ($self, @command) = @_; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
my $cfg = Tapper::Config->subconfig; |
|
30
|
0
|
|
|
|
|
0
|
my $cobbler_host = $cfg->{cobbler}->{host}; |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
0
|
my $output; |
|
33
|
0
|
0
|
|
|
|
0
|
if ($cobbler_host) { |
|
34
|
0
|
|
|
|
|
0
|
my $user = $cfg->{cobbler}->{user}; |
|
35
|
0
|
|
|
|
|
0
|
my $ssh = Net::OpenSSH->new("$user\@$cobbler_host"); |
|
36
|
0
|
0
|
|
|
|
0
|
$ssh->error and die "ssh $user\@$cobbler_host failed: ".$ssh->error; |
|
37
|
0
|
0
|
|
|
|
0
|
if (wantarray) { |
|
38
|
0
|
|
|
|
|
0
|
my @output = $ssh->capture({ quote_args => 1 }, @command); |
|
39
|
0
|
0
|
|
|
|
0
|
$ssh->error and die "Calling ".(join (" ",@command))." on $cobbler_host failed: ".$ssh->error; |
|
40
|
0
|
|
|
|
|
0
|
return @output; |
|
41
|
|
|
|
|
|
|
} else { |
|
42
|
0
|
|
|
|
|
0
|
my $output = $ssh->capture({ quote_args => 1 }, @command); |
|
43
|
0
|
0
|
|
|
|
0
|
$ssh->error and die "Calling ".(join (" ",@command))." on $cobbler_host failed: ".$ssh->error; |
|
44
|
0
|
|
|
|
|
0
|
return $output; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} else { |
|
47
|
0
|
|
|
|
|
0
|
return qx( @command ); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub host_new |
|
53
|
|
|
|
|
|
|
{ |
|
54
|
1
|
|
|
1
|
1
|
86861
|
my ($self, $name, $options) = @_; |
|
55
|
1
|
|
50
|
|
|
10
|
my $default = $options->{default} || 'default'; |
|
56
|
|
|
|
|
|
|
|
|
57
|
1
|
50
|
|
|
|
10
|
return (join "",("Need a string as first argument in ", |
|
58
|
|
|
|
|
|
|
__FILE__, |
|
59
|
|
|
|
|
|
|
", line ", |
|
60
|
|
|
|
|
|
|
__LINE__, |
|
61
|
|
|
|
|
|
|
". You provided a ", |
|
62
|
|
|
|
|
|
|
ref $name)) |
|
63
|
|
|
|
|
|
|
if ref $name; |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $host = model('TestrunDB')->resultset('Host')->find({name => $name}); |
|
66
|
0
|
0
|
|
|
|
|
return "Host '$name' does not exist in the database" if not $host; |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
0
|
|
|
|
my $mac = $options->{mac} || $self->get_mac_address($host); |
|
69
|
0
|
0
|
|
|
|
|
return "Missing mac address for host '$name'" if not $mac; |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my @command = split(" ","cobbler system copy --name $default --newname $name --mac-address $mac"); |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return $self->cobbler_execute(@command); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub host_del |
|
79
|
|
|
|
|
|
|
{ |
|
80
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my @command = split(" ", "cobbler system remove --name $name"); |
|
83
|
0
|
|
|
|
|
|
return $self->cobbler_execute(@command); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub host_list |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
0
|
|
|
0
|
1
|
|
my ($self, $search) = @_; |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my @command = qw/cobbler system find/; |
|
92
|
0
|
0
|
0
|
|
|
|
if ($search and ref($search) eq 'HASH') { |
|
93
|
|
|
|
|
|
|
KEY: |
|
94
|
0
|
|
|
|
|
|
foreach my $key (keys %$search) { |
|
95
|
0
|
|
|
|
|
|
push @command, "--$key", $search->{$key}; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
0
|
|
|
|
|
|
return $self->cobbler_execute(@command); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub host_update |
|
104
|
|
|
|
|
|
|
{ |
|
105
|
0
|
|
|
0
|
1
|
|
my ($self, $name, $options) = @_; |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
return (join "",("Need a string as first argument in ", |
|
108
|
|
|
|
|
|
|
__FILE__, |
|
109
|
|
|
|
|
|
|
", line ", |
|
110
|
|
|
|
|
|
|
__LINE__, |
|
111
|
|
|
|
|
|
|
". You provided a ", |
|
112
|
|
|
|
|
|
|
ref $name)) |
|
113
|
|
|
|
|
|
|
if ref $name; |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my @command = qw/cobbler system edit --name/; |
|
116
|
0
|
|
|
|
|
|
push @command, $name; |
|
117
|
0
|
|
|
|
|
|
foreach my $key (keys %$options) { |
|
118
|
0
|
|
|
|
|
|
push @command, "--$key", $options->{$key}; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
0
|
|
|
|
|
|
return $self->cobbler_execute(@command); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; # End of Tapper::Cmd::Cobbler |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=pod |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=encoding UTF-8 |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 NAME |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Tapper::Cmd::Cobbler |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This project offers backend functions for all Tapper projects. This |
|
142
|
|
|
|
|
|
|
module offers access to Cobbler database manipulation. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
use Tapper::Cmd::Cobbler; |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
my $bar = Tapper::Cmd::Cobbler->new(); |
|
147
|
|
|
|
|
|
|
$bar->host_new($hostname); |
|
148
|
|
|
|
|
|
|
... |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 NAME |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Tapper::Cmd::Testrun - Backend functions for manipluation of the cobbler database |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 METHODS |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 get_mac_address |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Retrieve the mac address of a host from features available in DB. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
@param Tapper::Schema::TestrunDB::Result::Host - host object |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
@return string - mac address |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 cobbler_execute |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Execute a Cobbler command. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
@param string - command |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
@return string - output of cobbler |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 host_new |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Add a new host to Cobbler. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
@param string - name of new host |
|
177
|
|
|
|
|
|
|
@optparam hash ref - additional options, may contain |
|
178
|
|
|
|
|
|
|
* default => name of the system to copy from, "default" if empty |
|
179
|
|
|
|
|
|
|
* mac => mac address of the system, get from HostFeatures if empty |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
@return success - 0 |
|
182
|
|
|
|
|
|
|
@return error - error message |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 host_del |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Remove a host from Cobbler. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
@param string - name of host to remove |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
@return success - 0 |
|
191
|
|
|
|
|
|
|
@return error - error message |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 host_list |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
List systems that Cobbler already knows, either all or all matching a |
|
196
|
|
|
|
|
|
|
given criteria. |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
@optparam hashref - list of criteria to match, possible criteria are |
|
199
|
|
|
|
|
|
|
* name |
|
200
|
|
|
|
|
|
|
* status (one of development,testing,acceptance,production) |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
@return success - list of system names |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 host_update |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Change a number of ascpects of a given host. |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
@param string - hostname |
|
209
|
|
|
|
|
|
|
@param hashref - list of aspects to change with new values |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
@return success - 0 |
|
212
|
|
|
|
|
|
|
@return error - error string |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 AUTHOR |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
AMD OSRC Tapper Team, C<< <tapper at amd64.org> >> |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Copyright 2012 AMD OSRC Tapper Team, all rights reserved. |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
This program is released under the following license: freebsd |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 AUTHORS |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=over 4 |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=item * |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item * |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Tapper Team <tapper-ops@amazon.com> |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=back |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
This software is Copyright (c) 2020 by Advanced Micro Devices, Inc.. |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
This is free software, licensed under: |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=cut |