my $stat;
my $mac_to_name;
+my $instance_tap;
my $lines;
-next_argv:
+my @nodes = @ARGV;
+
+@nodes = map { chomp ; $_ } `gnt-node list -o name --no-header` unless @nodes;
+
+next_node:
my $ssh = '';
-if ( @ARGV ) {
- $hostname = shift @ARGV;
+if ( @nodes ) {
+ $hostname = shift @nodes;
$ssh = "ssh $hostname ";
+ $hostname =~ s/\..+$//; # -s
+ warn "## hostname $hostname\n";
}
# if prefixed with _ it will be hiddden from output, _args must be last!
_args);
sub ps_cols_all { map { my $t = $_; $t =~ s/^_//; $t } @ps_cols };
-sub ps_cols_visible { grep { ! /^_/ } @ps_cols };
+sub ps_cols_visible { 'node', grep { ! /^_/ } @ps_cols };
sub DD_hh_mm_ss {
my $t = shift;
return $t_sec;
}
-my $cmd = $ssh . 'ps --no-headers axwwo ' . join(',', ps_cols_all);
-warn "## $cmd\n";
-open(my $ps, '-|', $cmd);
+sub sh {
+ my $cmd = join(' ', @_);
+ $cmd = "$ssh '$cmd'";
+ warn "## $cmd\n";
+ open(my $fh, '-|', $cmd);
+ return $fh;
+}
+
+my $ps = sh 'ps --no-headers axwwo ' . join(',', ps_cols_all);
while(<$ps>) {
chomp;
s/^\s*//;
my $name = $1;
$stat->{$name}->{$_} = $h{$_} foreach ps_cols_all;
+ $stat->{$name}->{node} = $hostname;
+
while ( $h{_args} =~ m/mac=([0-9a-fA-F:]+)/g ) {
- $mac_to_name->{$1} = $name;
+ $mac_to_name->{$hostname}->{$1} = $name;
}
} else {
}
-open(my $ip, '-|', $ssh . 'ip -s -o link');
+
+my $tap = sh('grep . /var/run/ganeti/kvm-hypervisor/nic/*/*');
+while(<$tap>) {
+ chomp;
+ warn "## $tap\n";
+ my @p = split(/\//,$_);
+ push @{ $instance_tap->{$hostname}->{ $p[-2] } }, $p[-1];
+}
+
+my $ip = sh('ip -s -o link');
while(<$ip>) {
chomp;
if ( m/master\s+(\S+).+ether\s+([0-9a-fA-F:]+).+RX:\s+.+\\\s+(\d+).+TX:\s+.+\\\s+(\d+)/ ) {
}
}
-goto next_argv if @ARGV;
+# dump some useful data structures
+
+sub tab_dump {
+ my ( $name, $hash ) = @_;
+ warn "# $name\n";
+ foreach my $key ( sort keys %$hash ) {
+ warn $key, "\t$hostname\t", $hash->{$key}, "\n";
+ }
+}
+
+tab_dump 'mac_to_name', $mac_to_name;
+warn Dumper( $mac_to_name );
+tab_dump 'instance_tap', $instance_tap;
+warn Dumper( $instance_tap );
+
+goto next_node if @nodes;
+
warn "# stat ", Dumper( $stat ) if $DEBUG;
+
+
+# dump tablable ascii output
+
XXX( @ps_cols );
sub push_line {
push_line( $name, map { $stat->{$name}->{$_} } ps_cols_visible );
}
-warn '# mac_to_name ', Dumper( $mac_to_name );
-
XXX $lines;
my $fmt = join(' ', map { '%' . $_ . 's' } @{ $lines->{len} } ) . "\n";