Class: CephRuby::Cluster
Overview
Cluster
Synopsis
A cluster object will connect to a Ceph monitor to carry out tasks or access objects from ceph
How to connect
clusterA = ::CephRuby::Cluster.new clusterB = ::CephRuby::Cluster.new(‘/path/to/config/dir’) clusterC = ::CephRuby::Cluster.new(‘/path/to/config/dir’, options) clusterD = ::CephRuby::Cluster.new(options)
Options (with defaults)
{
config_dir: '/etc/ceph'
cluster: 'ceph',
user: 'client.admin',
flags: 0
}
Instance Attribute Summary collapse
Instance Method Summary
collapse
<=>, default_options, eql?, log, setup_handle, uint?
Constructor Details
#initialize(config = {}, opts = {}) ⇒ Cluster
Returns a new instance of Cluster.
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/ceph-ruby/cluster.rb', line 27
def initialize(config = {}, opts = {})
setup(config, opts)
connect
if block_given?
begin
yield(self)
ensure
shutdown
end
end
end
|
Instance Attribute Details
#handle ⇒ Object
Returns the value of attribute handle.
25
26
27
|
# File 'lib/ceph-ruby/cluster.rb', line 25
def handle
@handle
end
|
#options ⇒ Object
Returns the value of attribute options.
24
25
26
|
# File 'lib/ceph-ruby/cluster.rb', line 24
def options
@options
end
|
Instance Method Details
#connect ⇒ Object
75
76
77
78
79
|
# File 'lib/ceph-ruby/cluster.rb', line 75
def connect
log('connect')
ret = Lib::Rados.rados_connect(handle)
raise SystemCallError.new('connect to cluster failed', -ret) if ret < 0
end
|
#fsid ⇒ Object
97
98
99
100
101
102
103
104
|
# File 'lib/ceph-ruby/cluster.rb', line 97
def fsid
log('fsid')
data_p = FFI::MemoryPointer.new(:char, 37)
ret = Lib::Rados.rados_cluster_fsid(handle, data_p, 37)
raise SystemCallError.new('cluster fsid failed',
-ret) if ret < 0
data_p.get_bytes(0, ret)
end
|
#pool(name, &block) ⇒ Object
48
49
50
|
# File 'lib/ceph-ruby/cluster.rb', line 48
def pool(name, &block)
Pool.new(self, name, &block)
end
|
#pool_id_by_name(name) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/ceph-ruby/cluster.rb', line 68
def pool_id_by_name(name)
ret = Lib::Rados.rados_pool_lookup(handle, name)
raise Errno::ENOENT if ret == -Errno::ERANGE::Errno
raise SystemCallError.new('read of pool id failed', -ret) if ret < 0
ret
end
|
#pool_name_by_id(id, size = 512) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/ceph-ruby/cluster.rb', line 56
def pool_name_by_id(id, size = 512)
data_p = FFI::MemoryPointer.new(:char, size)
ret = Lib::Rados.rados_pool_reverse_lookup(handle,
id,
name,
size)
raise Errno::ERANGE,
'buffer size too small' if ret == -Errno::ERANGE::Errno
raise SystemCallError.new('read of pool name failed', -ret) if ret < 0
data_p.get_bytes(0, ret)
end
|
#pools ⇒ Object
52
53
54
|
# File 'lib/ceph-ruby/cluster.rb', line 52
def pools
PoolEnumerator.new(self)
end
|
#setup_using_file ⇒ Object
81
82
83
84
85
86
|
# File 'lib/ceph-ruby/cluster.rb', line 81
def setup_using_file
log("setup_using_file #{options[:path]}")
ret = Lib::Rados.rados_conf_read_file(handle, options[:path])
raise SystemCallError.new('setup of cluster from config file'\
" '#{options[:path]}' failed", -ret) if ret < 0
end
|
#shutdown ⇒ Object
41
42
43
44
45
46
|
# File 'lib/ceph-ruby/cluster.rb', line 41
def shutdown
return unless handle
log('shutdown')
Lib::Rados.rados_shutdown(handle)
self.handle = nil
end
|
#status ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'lib/ceph-ruby/cluster.rb', line 88
def status
log('stat')
stat_s = Lib::Rados::MonitorStatStruct.new
ret = Lib::Rados.rados_cluster_stat(handle, stat_s)
raise SystemCallError.new('retrieve cluster status failed',
-ret) if ret < 0
stat_s.to_hash
end
|