Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ Or install it yourself as:
pool = cluster.pool("my-pool-xyz")
pool.open

# CephRuby::Cluster.new currently accepts up to three setings.
# conf_file - path to your ceph.conf file (default: /etc/ceph/ceph.conf)
# options hash:
# :user - cephx user to authenticate against (default: client.admin)
(would look for a keyring file at: '/etc/ceph/<cluster>.<user>.keyring')
# :cluster - ceph cluster to connect to (default: ceph)

cluster = CephRuby::Cluster.new "/etc/ceph/us-east.conf", {cluster: 'us-east', user: 'client.amazing'}

# simple example for using rados objects
object = pool.rados_object("my-object-xyz")
object.write(0, "This is a Test!")
Expand Down
14 changes: 11 additions & 3 deletions lib/ceph-ruby/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ module CephRuby
class Cluster
attr_accessor :handle

def initialize(config_path = "/etc/ceph/ceph.conf")
# Creates a connection to a given ceph Cluster
# Takes optional paramaters config_path, and an options hash
# config_path string - path to ceph configuration file
# options:
# :cluster - cluster name (default: ceph)
# :user - cephx key file and user to use (default: client.admin)
def initialize(config_path = '/etc/ceph/ceph.conf', options = {})
cluster = options.fetch(:cluster, 'ceph')
user = options.fetch(:user, 'client.admin')
log("init lib rados #{Lib::Rados.version_string}, lib rbd #{Lib::Rbd.version_string}")

handle_p = FFI::MemoryPointer.new(:pointer)
ret = Lib::Rados.rados_create(handle_p, nil)
raise SystemCallError.new("open of cluster failed", -ret) if ret < 0
ret = Lib::Rados.rados_create2(handle_p, cluster, user, 0)
raise SystemCallError.new('open of cluster failed', -ret) if ret < 0
self.handle = handle_p.get_pointer(0)

setup_using_file(config_path)
Expand Down
1 change: 1 addition & 0 deletions lib/ceph-ruby/lib/rados.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Rados
attach_function 'rados_version', [:pointer, :pointer, :pointer], :void

attach_function 'rados_create', [:pointer, :string], :int
attach_function 'rados_create2', [:pointer, :string, :string, :int], :int
attach_function 'rados_connect', [:pointer], :int
attach_function 'rados_conf_read_file', [:pointer, :string], :int
attach_function 'rados_shutdown', [:pointer], :void
Expand Down
2 changes: 1 addition & 1 deletion lib/ceph-ruby/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CephRuby
VERSION = "1.1"
VERSION = "1.2"
end