Author: eelco
Date: Tue May 10 14:36:10 2011
New Revision: 27215
URL: https://svn.nixos.org/websvn/nix/?rev=27215&sc=1

Log:
* Added an operation ‘--check’ to checks whether every machine is
  reachable via SSH.

Modified:
   cloud/trunk/src/nixos-deploy-network.pl

Modified: cloud/trunk/src/nixos-deploy-network.pl
==============================================================================
--- cloud/trunk/src/nixos-deploy-network.pl     Tue May 10 13:52:10 2011        
(r27214)
+++ cloud/trunk/src/nixos-deploy-network.pl     Tue May 10 14:36:10 2011        
(r27215)
@@ -85,6 +85,26 @@
 }
 
 
+# ‘--check’ checks whether every machine is reachable via SSH.  It
+# also prints the load on every machine.
+sub opCheck {
+    readState();
+    
+    foreach my $name (sort (keys %{$state->{machines}})) {
+        my $machine = $state->{machines}->{$name};
+        print STDERR "$name... ";
+
+        my $load = `ssh -o StrictHostKeyChecking=no root\@$machine->{sshName} 
cat /proc/loadavg 2>/dev/null`;
+        if ($? == 0) {
+            my @load = split / /, $load;
+            print STDERR "ok [$load[0] $load[1] $load[2]]\n";
+        } else {
+            print STDERR "fail\n";
+        }
+    }
+}
+
+
 sub opDeploy {
     # Evaluate the user's network specification to determine machine
     # names and the desired deployment characteristics.
@@ -128,6 +148,7 @@
     exit 1 unless GetOptions(
         "state=s" => \$stateFile,
         "info" => sub { $op = \&opInfo; },
+        "check" => sub { $op = \&opCheck; },
         "destroy" => sub { $op = \&opDestroy; },
         "kill-obsolete!" => \$killObsolete,
         );
@@ -290,7 +311,7 @@
     }
     
     # Figure out how we're gonna SSH to each machine.  Prefer IPv6
-    # addresses over hostnames.while
+    # addresses over hostnames.
     while (my ($name, $machine) = each %{$state->{machines}}) {
         $machine->{sshName} = $machine->{ipv6} || $machine->{targetHost} || 
die "don't know how to reach ‘$name’";
     }
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits

Reply via email to