From: Greg Price Date: Sun, 29 Jun 2008 01:54:31 +0000 (-0400) Subject: check in Quentin's remote-listvmsd X-Git-Tag: sipb-xen-remote-server/0.2~7 X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-remote.git/commitdiff_plain/efa07c159a604004bc3f8292d1991f934e21bf05 check in Quentin's remote-listvmsd svn path=/trunk/packages/sipb-xen-remote-server/; revision=656 --- diff --git a/files/usr/sbin/sipb-xen-remote-listvmsd b/files/usr/sbin/sipb-xen-remote-listvmsd new file mode 100755 index 0000000..33acef3 --- /dev/null +++ b/files/usr/sbin/sipb-xen-remote-listvmsd @@ -0,0 +1,71 @@ +#!/usr/bin/perl + +# NOTE: In development; not actually used yet. + +#Collates the results of listvms from multiple VM servers. Part of the xvm +#suite. + +use Net::Remctl (); +use JSON; + +our @servers = qw/black-mesa.mit.edu sx-blade-2.mit.edu/; + +our %connections; + +sub openConnections() { + foreach (@servers) { openConnection($_); } +} + +sub openConnection($) { + my ($server) = @_; + my $remctl = Net::Remctl->new; + $remctl->open($server) + or die "Cannot connect to $server: ", $remctl->error, "\n"; + $connections{$server} = $remctl; +} + +sub doListVMs() { + foreach my $remctl (values %connections) { + $remctl->command("remote", "web", "listvms", "--json"); + } + my %vmstate; + foreach my $server (keys %connections) { + my $remctl = $connections{$server}; + my $jsonData = ''; + do { + $output = $remctl->output; + if ($output->type eq 'output') { + if ($output->stream == 1) { + $jsonData .= $output->data; + } elsif ($output->stream == 2) { + print STDERR $output->data; + } + } elsif ($output->type eq 'error') { + warn $output->error, "\n"; + } elsif ($output->type eq 'status') { + if ($output->status != 0) { + warn "Exit status was ".$output->status; + } + } elsif ($output->type eq 'done') { + #next; + } else { + die "Unknown output token from library: ", $output->type, "\n"; + } + } while ($output->type ne 'done'); + my $vmlist = jsonToObj($jsonData); + foreach my $key (keys %$vmlist) { + $vmstate{$key} = $vmlist->{$key}; + $vmstate{$key}{"host"} = $server; + } + } + return %vmstate; +} + +openConnections(); + +use Data::Dumper; +use Benchmark; +print Dumper({doListVMs()}); +timethis(100, sub {doListVMs()}); + +# vim:et:sw=4:ts=4