about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-06-29 21:00:01 +0000
committerEric Wong <normalperson@yhbt.net>2012-06-29 21:00:01 +0000
commitdb4fefb16ac04aad0ae1c42bd021c4849fc11734 (patch)
treeba55b25dc5ec2a07cd8f3c5f5c4484d82de77652
parent76ef95496eb5f38434c28b8080e08b668a8bf4f6 (diff)
downloadmogilefs-client-db4fefb16ac04aad0ae1c42bd021c4849fc11734.tar.gz
This makes things easier-to-read, and admin functions aren't
performance critical so we won't worry about it.
-rw-r--r--lib/mogilefs/admin.rb25
1 files changed, 12 insertions, 13 deletions
diff --git a/lib/mogilefs/admin.rb b/lib/mogilefs/admin.rb
index 06ba2a5..6a746ac 100644
--- a/lib/mogilefs/admin.rb
+++ b/lib/mogilefs/admin.rb
@@ -37,7 +37,7 @@ class MogileFS::Admin < MogileFS::Client
   #     "altmask"=>""}]
 
   def get_hosts(hostid = nil)
-    to_i = { "hostid" => true, "http_port" => true, "http_get_port" => true }
+    to_i = %w(hostid http_port http_get_port)
     clean('hosts', 'host',
           @backend.get_hosts(hostid ? { :hostid => hostid } : {}), true, to_i)
   end
@@ -59,11 +59,7 @@ class MogileFS::Admin < MogileFS::Client
   #     "mb_total"=>666666}]
 
   def get_devices(devid = nil)
-    to_i = {
-      "mb_asof" => true, "mb_free" => true,
-      "mb_used" => true, "mb_total" => true ,
-      "devid" => true, "weight" => true, "hostid" => true
-    }
+    to_i = %w(mb_asof mb_free mb_used mb_total devid weight hostid)
     rv = @backend.get_devices(devid ? { :devid => devid } : {})
     rv = clean('devices', 'dev', rv, true, to_i)
     rv.each do |row|
@@ -99,7 +95,7 @@ class MogileFS::Admin < MogileFS::Client
   #     "key"=>"new_new_key"}]
 
   def list_fids(from_fid, count = 100)
-    to_i = { "fid" => true, "devcount" => true, "length" => true }
+    to_i = %w(fid devcount length)
     # :to is now :count internally in mogilefsd
     clean('fid_count', 'fid_',
           @backend.list_fids(:from => from_fid, :to => count), true, to_i)
@@ -169,7 +165,7 @@ class MogileFS::Admin < MogileFS::Client
     have_replpolicy = false
 
     domains = {}
-    to_i = { "mindevcount" => true }
+    to_i = %w(mindevcount)
     (1..res['domains'].to_i).each do |i|
       domain = clean "domain#{i}classes", "domain#{i}class", res, false, to_i
 
@@ -366,18 +362,21 @@ class MogileFS::Admin < MogileFS::Client
   # Returns:
   #
   #   [{"status"=>"alive",
-  #     "http_get_port"=>"",
-  #     "http_port"=>"",
-  #     "hostid"=>"1",
-  #     "hostip"=>"",
+  #     "http_get_port"=>nil,
+  #     "http_port"=>7600,
+  #     "hostid"=>1,
+  #     "hostip"=>"192.168.1.3",
   #     "hostname"=>"rur-1",
-  #     "remoteroot"=>"/mnt/mogilefs/rur-1",
   #     "altip"=>"",
   #     "altmask"=>""}]
 
   def clean(count, prefix, res, underscore = true, to_i = [])
     empty = ""
     underscore = underscore ? '_' : empty
+
+    # convert array to hash for O(1) lookups
+    to_i = to_i.inject({}) { |m,k| m[k] = m }
+
     keys = res.keys
     (1..res[count].to_i).map do |i|
       re = /^#{prefix}#{i}#{underscore}/