Class: CephRuby::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/ceph-ruby/cluster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path = "/etc/ceph/ceph.conf") ⇒ Cluster

Returns a new instance of Cluster.

Raises:

  • (SystemCallError)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ceph-ruby/cluster.rb', line 5

def initialize(config_path = "/etc/ceph/ceph.conf")
  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
  self.handle = handle_p.get_pointer(0)

  setup_using_file(config_path)

  connect

  if block_given?
    begin
      yield(self)
    ensure
      close
    end
  end
end

Instance Attribute Details

#handleObject

Returns the value of attribute handle.



3
4
5
# File 'lib/ceph-ruby/cluster.rb', line 3

def handle
  @handle
end

Instance Method Details

#closeObject



26
27
28
29
30
31
# File 'lib/ceph-ruby/cluster.rb', line 26

def close
  return unless handle
  log("close")
  Lib::Rados.rados_shutdown(handle)
  self.handle = nil
end

#connectObject

helper methods below

Raises:

  • (SystemCallError)


39
40
41
42
43
# File 'lib/ceph-ruby/cluster.rb', line 39

def connect
  log("connect")
  ret = Lib::Rados.rados_connect(handle)
  raise SystemCallError.new("connect to cluster failed", -ret) if ret < 0
end

#log(message) ⇒ Object



51
52
53
# File 'lib/ceph-ruby/cluster.rb', line 51

def log(message)
  CephRuby.log("cluster #{message}")
end

#pool(name, &block) ⇒ Object



33
34
35
# File 'lib/ceph-ruby/cluster.rb', line 33

def pool(name, &block)
  Pool.new(self, name, &block)
end

#setup_using_file(path) ⇒ Object

Raises:

  • (SystemCallError)


45
46
47
48
49
# File 'lib/ceph-ruby/cluster.rb', line 45

def setup_using_file(path)
  log("setup_using_file #{path}")
  ret = Lib::Rados.rados_conf_read_file(handle, path)
  raise SystemCallError.new("setup of cluster from config file '#{path}' failed", -ret) if ret < 0
end