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
# 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?
    yield(self)
    shutdown
  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

#connectObject

helper methods below

Raises:

  • (SystemCallError)


36
37
38
39
40
# File 'lib/ceph-ruby/cluster.rb', line 36

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



48
49
50
# File 'lib/ceph-ruby/cluster.rb', line 48

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

#pool(name, &block) ⇒ Object



30
31
32
# File 'lib/ceph-ruby/cluster.rb', line 30

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

#setup_using_file(path) ⇒ Object

Raises:

  • (SystemCallError)


42
43
44
45
46
# File 'lib/ceph-ruby/cluster.rb', line 42

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

#shutdownObject



23
24
25
26
27
28
# File 'lib/ceph-ruby/cluster.rb', line 23

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