about summary refs log tree commit homepage
path: root/lib/mogilefs/admin.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-06-29 20:06:31 +0000
committerEric Wong <normalperson@yhbt.net>2012-06-29 20:19:35 +0000
commitdadf046dd86a18329140bb0c206c4a0b989825f1 (patch)
tree01df0be2ddd6b4ab74c5f7208081383e5935838e /lib/mogilefs/admin.rb
parent920408e2c94fbe84331aab5ab4b0c402024817aa (diff)
downloadmogilefs-client-dadf046dd86a18329140bb0c206c4a0b989825f1.tar.gz
The ability to create devices from the Ruby API might be
useful to somebody, especially when writing test cases.
Diffstat (limited to 'lib/mogilefs/admin.rb')
-rw-r--r--lib/mogilefs/admin.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/mogilefs/admin.rb b/lib/mogilefs/admin.rb
index 0927e47..19f6858 100644
--- a/lib/mogilefs/admin.rb
+++ b/lib/mogilefs/admin.rb
@@ -255,6 +255,26 @@ class MogileFS::Admin < MogileFS::Client
   end
 
   ##
+  # Creates device with Integer +devid+ on +host+
+  # +host+ may be an integer for hostid or String for hostname
+  def create_device(host, devid, opts = {})
+    raise MogileFS::ReadOnlyError if readonly?
+    opts = opts.dup
+
+    case host
+    when Integer
+      opts[:hostid] = host
+    when String
+      opts[:hostname] = host
+    else
+      raise ArgumentError, "host=#{host.inspect} is not a String or Integer"
+    end
+
+    opts[:devid] = devid
+    ! @backend.create_device(opts).nil?
+  end
+
+  ##
   # Changes the device status of +device+ on +host+ to +state+ which can be
   # 'alive', 'down', or 'dead'.