From 776fe9b8437a28a8d03ead8120ee63186b2b928e Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 4 Sep 2015 15:08:29 +0100 Subject: [PATCH] Cluster::initialize allows cluster name and cephx user to be specified Updated the cluster initialize function to use rados_create2 and added options hash for user and cluster details to be provided. --- README.md | 9 +++++++++ lib/ceph-ruby/cluster.rb | 14 +++++++++++--- lib/ceph-ruby/lib/rados.rb | 1 + lib/ceph-ruby/version.rb | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index afe0a70..878db13 100644 --- a/README.md +++ b/README.md @@ -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/..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!") diff --git a/lib/ceph-ruby/cluster.rb b/lib/ceph-ruby/cluster.rb index a29de01..f66f23c 100644 --- a/lib/ceph-ruby/cluster.rb +++ b/lib/ceph-ruby/cluster.rb @@ -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) diff --git a/lib/ceph-ruby/lib/rados.rb b/lib/ceph-ruby/lib/rados.rb index f68b7fe..b5656b2 100644 --- a/lib/ceph-ruby/lib/rados.rb +++ b/lib/ceph-ruby/lib/rados.rb @@ -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 diff --git a/lib/ceph-ruby/version.rb b/lib/ceph-ruby/version.rb index 4c7d9ba..0d4a3d3 100644 --- a/lib/ceph-ruby/version.rb +++ b/lib/ceph-ruby/version.rb @@ -1,3 +1,3 @@ module CephRuby - VERSION = "1.1" + VERSION = "1.2" end