NodeInfo.pm 1.13 KB
Newer Older
1
#!/usr/bin/perl
2
use SemiModern::Perl;
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

package TestBed::XMLRPC::Client::NodeInfo;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(parseNodeInfo);
use Data::Dumper;

our $ni= <<'END';
Experiment: tbres/tewkt         
State: active                                                                     

Virtual Node Info:
ID              Type         OS              Qualified Name
--------------- ------------ --------------- --------------------
node1           pc                           node1.tewkt.tbres.emulab.net
node2           pc                           node2.tewkt.tbres.emulab.net
END

sub splitlines {
  my @lines = split(/\n/, $_[0]);
  \@lines;
}

sub asplitmatch { 
  my ($pat, $array) = @_;
  my $i = 0;
  my $d = 0;
  for (@{$array}) {
    if ($_ =~ $pat) {
      $d = $i;
      last;
    }
    $i++;
  };
  my @a = @{$array};
  my @aa = @a[($d+1) .. $#a];
  \@aa;
}

sub project_nodes {
  my ($nodes) = @_;
  my @nodes;
  for (@$nodes) {
    if($_ =~ /(\S+)$/) {
      push @nodes, $1;
    }
  }
  \@nodes;
}

sub parseNodeInfo {
  my ($text) = @_;
  project_nodes(asplitmatch(qr/---------------/, splitlines($text)));
}

1;