source: trunk/packages/invirt-remote-server/files/usr/sbin/invirt-remote-listvmsd @ 1176

Last change on this file since 1176 was 1176, checked in by price, 16 years ago

sipb-xen -> invirt for remote-server

  • Property svn:executable set to *
File size: 1.7 KB
Line 
1#!/usr/bin/perl
2
3# NOTE: In development; not actually used yet.
4
5#Collates the results of listvms from multiple VM servers.  Part of the xvm
6#suite.
7
8use Net::Remctl ();
9use JSON;
10
11our @servers = qw/black-mesa.mit.edu sx-blade-2.mit.edu/;
12
13our %connections;
14
15sub openConnections() {
16    foreach (@servers) { openConnection($_); }
17}
18
19sub openConnection($) {
20    my ($server) = @_;
21    my $remctl = Net::Remctl->new;
22    $remctl->open($server)
23        or die "Cannot connect to $server: ", $remctl->error, "\n";
24    $connections{$server} = $remctl;
25}
26
27sub doListVMs() {
28    foreach my $remctl (values %connections) {
29        $remctl->command("remote", "web", "listvms", "--json");
30    }
31    my %vmstate;
32    foreach my $server (keys %connections) {
33        my $remctl = $connections{$server};
34        my $jsonData = '';
35        do {
36            $output = $remctl->output;
37            if ($output->type eq 'output') {
38                if ($output->stream == 1) {
39                    $jsonData .= $output->data;
40                } elsif ($output->stream == 2) {
41                    print STDERR $output->data;
42                }
43            } elsif ($output->type eq 'error') {
44                warn $output->error, "\n";
45            } elsif ($output->type eq 'status') {
46                if ($output->status != 0) {
47                    warn "Exit status was ".$output->status;
48                }
49            } elsif ($output->type eq 'done') {
50                #next;
51            } else {
52                die "Unknown output token from library: ", $output->type, "\n";
53            }
54        } while ($output->type ne 'done');
55        my $vmlist = jsonToObj($jsonData);
56        foreach my $key (keys %$vmlist) {
57            $vmstate{$key} = $vmlist->{$key};
58            $vmstate{$key}{"host"} = $server;
59        }
60    }
61    return %vmstate;
62}
63
64openConnections();
65
66use Data::Dumper;
67use Benchmark;
68print Dumper({doListVMs()});
69timethis(100, sub {doListVMs()});
70
71# vim:et:sw=4:ts=4
Note: See TracBrowser for help on using the repository browser.