add nic_list

This commit is contained in:
Zane C. B-H 2021-10-12 06:21:51 -05:00
parent 113630f7ed
commit 8f66898ea0
3 changed files with 86 additions and 2 deletions

View File

@ -108,7 +108,7 @@ The returned array is a hash of hashes. The first level hash is the jname.
nodename - The node name that this is set to run on.
jname - Name of the VM.
vm - Name of the VM.
jid - Jail ID/process ID of the VM if running. IF '0' it is not running.
@ -158,6 +158,44 @@ This dies upon failure.
"\n"
}
=head2 nic_list
List configured NICs.
This returned data is a array of hashes.
The keys are as below.
vm - The name of the VM in question.
driver - The driver in use. As of currently either vtnet or e1000.
type - Needs documented.
parent - Either the name of the parent NIC, example 'bridge1', or set to 'auto'.
hwaddr - The MAC address for the NIC.
address - Address of the NIC. '0' if not configured.
mtu - The MTU of NIC. '0' if default.
persistent - 0/1 - If it should exist when the VM is not in use. '0' is the default.
ratelimit - Rate limit for the interface. '0' is the default, not in use.
This dies upon failure.
my @nics
eval{
@nics=vm nic_list;
} or do {
my $error = $@ || 'Unknown failure';
warn('Failed to the NIC list... '.$error);
}
print Dumper(\@nics);
=head2 pause
This pauses a VM in question. The following modes are available. If no

View File

@ -36,7 +36,7 @@ sub execute {
foreach my $line (@found_lines) {
my %VM;
# needs to be updated if display= is ever changed
( $VM{'node'}, $VM{'name'}, $VM{'pid'}, $VM{'ram'}, $VM{'curmem'},
( $VM{'node'}, $VM{'vm'}, $VM{'pid'}, $VM{'ram'}, $VM{'curmem'},
$VM{'cpus'}, $VM{'pcpu'}, $VM{'os'}, $VM{'ip4'}, $VM{'status'},
$VM{'vnc'}, $VM{'path'} ) = split(/[\ \t]+/, $line);
$VMs{$VM{'name'}}=\%VM;

View File

@ -0,0 +1,46 @@
#
# (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
#
package Rex::Virtualization::CBSD::disk_list;
use strict;
use warnings;
our $VERSION = '0.0.1'; # VERSION
use Rex::Logger;
use Rex::Helper::Run;
use Term::ANSIColor qw(colorstrip);
sub execute {
my ( $class ) = @_;
Rex::Logger::debug("Getting CBSD VM list of ");
my @nics;
# header=0 is needed to avoid including code to exclude it
# if display= is changed, the parsing order needs updated
my $found=i_run ('cbsd bhyve-nic-list display=jname,nic_driver,nic_type,nic_parent,nic_hwaddr,nic_address,nic_mtu,nic_persistent,nic_ratelimit header=0' , fail_ok => 1);
if ( $? != 0 ) {
die("Error running 'cbsd bhyve-nic-list display=jname,nic_driver,nic_type,nic_parent,nic_hwaddr,nic_address,nic_mtu,nic_persistent,nic_ratelimit header=0'");
}
# remove it here so the data can be safely used else where
$found=colorstrip($found);
my @found_lines=split(/\n/, $found);
foreach my $line (@found_lines) {
my %nic;
# needs to be updated if display= is ever changed
( $nic{'vm'}, $nic{'driver'}, $nic{'type'}, $nic{'parent'},
$nic{'hwaddr'}, $nic{'address'}, $nic{'mtu'}, $nic{'persistent'}, $nic{'ratelimit'} ) = split(/[\ \t]+/, $line);
push( @nics, \%nic );
}
return \@nics;
}
1;