| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Zane C. Bowers-Hadley |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::CBSD::create; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
80705
|
use strict; |
|
|
1
|
|
|
|
|
12
|
|
|
|
1
|
|
|
|
|
35
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
73
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.0.1'; # VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
495
|
use Rex::Logger; |
|
|
1
|
|
|
|
|
11702
|
|
|
|
1
|
|
|
|
|
73
|
|
|
13
|
1
|
|
|
1
|
|
633
|
use Rex::Helper::Run; |
|
|
1
|
|
|
|
|
87945
|
|
|
|
1
|
|
|
|
|
84
|
|
|
14
|
1
|
|
|
1
|
|
12
|
use Term::ANSIColor qw(colorstrip); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
1491
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub execute { |
|
17
|
0
|
|
|
0
|
0
|
|
my ( $class, %opts ) = @_; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#make sure we have the very minimum needed |
|
20
|
|
|
|
|
|
|
# also that each value is sane |
|
21
|
0
|
|
|
|
|
|
my @required_keys = ( 'name', 'vm_os_type', 'vm_os_profile' ); |
|
22
|
0
|
|
|
|
|
|
foreach my $key (@required_keys) { |
|
23
|
0
|
0
|
|
|
|
|
if ( !defined( $opts{$key} ) ) { |
|
24
|
0
|
|
|
|
|
|
die 'Required key "' . $key . '" not defined'; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# make sure it does not contain any tabs, spaces, =, \. /, ', ", or new lines. |
|
28
|
0
|
0
|
|
|
|
|
if ( $opts{$key} =~ /[\t\ \=\\\/\'\"\n]/ ) { |
|
29
|
|
|
|
|
|
|
die 'The value "' |
|
30
|
0
|
|
|
|
|
|
. $opts{$key} |
|
31
|
|
|
|
|
|
|
. '" for key "' |
|
32
|
|
|
|
|
|
|
. $key |
|
33
|
|
|
|
|
|
|
. '" matched /[\t\ \=\/\\\'\"\n]/, meaning it is not a valid value'; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $command |
|
38
|
|
|
|
|
|
|
= 'env NOINTER=1 cbsd bcreate jname="' |
|
39
|
|
|
|
|
|
|
. $opts{name} |
|
40
|
|
|
|
|
|
|
. '" vm_os_type="' |
|
41
|
|
|
|
|
|
|
. $opts{vm_os_type} |
|
42
|
|
|
|
|
|
|
. '" vm_os_profile="' |
|
43
|
|
|
|
|
|
|
. $opts{vm_os_profile} |
|
44
|
0
|
|
|
|
|
|
. '" inter=0'; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# the variables to check for. |
|
47
|
0
|
|
|
|
|
|
my @variables = ( |
|
48
|
|
|
|
|
|
|
'bhyve_vnc_tcp_bind', 'imgsize', 'interface2', 'nic_flags', |
|
49
|
|
|
|
|
|
|
'nic_flags2', 'quiet', 'removejconf', 'runasap', |
|
50
|
|
|
|
|
|
|
'vm_cpus', 'vm_ram', 'zfs_snapsrc', 'ci_gw4', |
|
51
|
|
|
|
|
|
|
'ci_interface2', 'ci_interface_mtu', 'ci_interface_mtu2', 'ci_ip4_addr', |
|
52
|
|
|
|
|
|
|
'ci_ip4_addr2', 'ci_user_pubkey', 'ci_user_pw_user', 'ci_user_pw_root' |
|
53
|
|
|
|
|
|
|
); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# add each found variable to the command |
|
56
|
0
|
|
|
|
|
|
foreach my $key (@variables) { |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if ( defined( $opts{$key} ) ) { |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# make sure it does not contain any tabs, single/double quotes, and new lines |
|
61
|
0
|
0
|
|
|
|
|
if ( $opts{$key} =~ /[\t\'\"\n]/ ) { |
|
62
|
|
|
|
|
|
|
die 'The value "' |
|
63
|
0
|
|
|
|
|
|
. $opts{$key} |
|
64
|
|
|
|
|
|
|
. '" for key "' |
|
65
|
|
|
|
|
|
|
. $key |
|
66
|
|
|
|
|
|
|
. '" matched /[\t\'\"\n]/, meaning it is not a valid value'; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
if ( defined( $opts{$key} ) ) { |
|
70
|
0
|
|
|
|
|
|
$command = $command.' ' . $key . '="' . $opts{$key} . '"'; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
Rex::Logger::debug( "Creating a new CBSD VM via... " . $command ); |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $returned = i_run( $command, fail_ok => 1 ); |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# the output is colorized |
|
80
|
0
|
|
|
|
|
|
$returned = colorstrip($returned); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# test after no such as that will also exit non-zero |
|
83
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
|
84
|
0
|
|
|
|
|
|
die( "Error running '" . $command . "' returned... " . $returned ); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $returned; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |