| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Zane C. Bowers-Hadley |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::CBSD::bstart; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
67646
|
use strict; |
|
|
1
|
|
|
|
|
10
|
|
|
|
1
|
|
|
|
|
30
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
39
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.1.0'; # VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
439
|
use Rex::Logger; |
|
|
1
|
|
|
|
|
10528
|
|
|
|
1
|
|
|
|
|
37
|
|
|
13
|
1
|
|
|
1
|
|
427
|
use Rex::Helper::Run; |
|
|
1
|
|
|
|
|
76787
|
|
|
|
1
|
|
|
|
|
73
|
|
|
14
|
1
|
|
|
1
|
|
9
|
use Term::ANSIColor qw(colorstrip); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1916
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub execute { |
|
17
|
0
|
|
|
0
|
0
|
|
my ( $class, $vm, %opts ) = @_; |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
if ( !defined($vm) ) { |
|
20
|
0
|
|
|
|
|
|
die('No VM name defined'); |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# make sure all the VM is sane |
|
24
|
0
|
0
|
|
|
|
|
if ( $opts{vn} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) |
|
25
|
|
|
|
|
|
|
{ |
|
26
|
|
|
|
|
|
|
die 'The value either for "vm", "' |
|
27
|
|
|
|
|
|
|
. $opts{vm} |
|
28
|
0
|
|
|
|
|
|
. '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value'; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my $command='cbsd bstart jname=' . $vm; |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
if (defined($opts{checkpoint})) { |
|
34
|
|
|
|
|
|
|
# make sure all the VM is sane |
|
35
|
0
|
0
|
|
|
|
|
if ( $opts{checkpoint} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
|
|
|
|
|
|
die 'The value either for "checkpoint", "' |
|
38
|
|
|
|
|
|
|
. $opts{checkpoint} |
|
39
|
0
|
|
|
|
|
|
. '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value'; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$command=$command." checkpoint='".$opts{checkpoint}."'"; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
Rex::Logger::debug( "CBSD VM start via... ".$command ); |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $returned = i_run( 'cbsd bstart jname=' . $vm, fail_ok => 1 ); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# the output is colorized |
|
50
|
0
|
|
|
|
|
|
$returned = colorstrip($returned); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# check for failures caused by it not existing |
|
53
|
0
|
0
|
|
|
|
|
if ( $returned =~ /^No\ such/ ) { |
|
54
|
0
|
|
|
|
|
|
die( '"' . $vm . '" does not exist' ); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# check for failures caused by it already running |
|
58
|
0
|
0
|
|
|
|
|
if ( $returned =~ /already\ running/ ) { |
|
59
|
0
|
|
|
|
|
|
die( '"' . $vm . '" is already running' ); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# test after no such as that will also exit non-zero |
|
63
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
|
64
|
0
|
|
|
|
|
|
die( "Error running 'cbsd bstart " . $vm . "'" ); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return 1; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |