| 1 | # | ||
| 2 | # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net> | ||
| 3 | # | ||
| 4 | |||
| 5 | package Rex::Virtualization::CBSD::bdisk_list; | ||
| 6 | |||
| 7 | use strict; | ||
| 8 | use warnings; | ||
| 9 | |||
| 10 | our $VERSION = '0.0.1'; # VERSION | ||
| 11 | |||
| 12 | use Rex::Logger; | ||
| 13 | use Rex::Helper::Run; | ||
| 14 | use Term::ANSIColor qw(colorstrip); | ||
| 15 | |||
| 16 | sub execute { | ||
| 17 | my ($class) = @_; | ||
| 18 | |||
| 19 | Rex::Logger::debug( | ||
| 20 | "Getting CBSD VM list of disk images via cbsd bhyve-dsk-list display=jname,dsk_controller,dsk_path,dsk_size,dsk_sectorsize,bootable,dsk_zfs_guid header=0" | ||
| 21 | ); | ||
| 22 | |||
| 23 | my @disks; | ||
| 24 | |||
| 25 | # header=0 is needed to avoid including code to exclude it | ||
| 26 | # if display= is changed, the parsing order needs updated | ||
| 27 | my $found = i_run( | ||
| 28 | 'cbsd bhyve-dsk-list display=jname,dsk_controller,dsk_path,dsk_size,dsk_sectorsize,bootable,dsk_zfs_guid header=0', | ||
| 29 | fail_ok => 1 | ||
| 30 | ); | ||
| 31 | if ( $? != 0 ) { | ||
| 32 | die( | ||
| 33 | "Error running 'cbsd bhyve-dsk-list display=jname,dsk_controller,dsk_path,dsk_size,dsk_sectorsize,bootable,dsk_zfs_guid header=0'" | ||
| 34 | ); | ||
| 35 | } | ||
| 36 | |||
| 37 | # remove it here so the data can be safely used else where | ||
| 38 | $found = colorstrip($found); | ||
| 39 | |||
| 40 | my @found_lines = split( /\n/, $found ); | ||
| 41 | |||
| 42 | foreach my $line (@found_lines) { | ||
| 43 | my %disk; | ||
| 44 | |||
| 45 | # needs to be updated if display= is ever changed | ||
| 46 | ( | ||
| 47 | $disk{'vm'}, $disk{'controller'}, $disk{'path'}, $disk{'size'}, | ||
| 48 | $disk{'sectorsize'}, $disk{'bootable'}, $disk{'zfs_guid'} | ||
| 49 | ) = split( /[\ \t]+/, $line ); | ||
| 50 | push( @disks, \%disk ); | ||
| 51 | } | ||
| 52 | |||
| 53 | return \@disks; | ||
| 54 | } | ||
| 55 | |||
| 56 | 1; |