Class: CephRuby::Pool

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster, name) ⇒ Pool

Returns a new instance of Pool.



5
6
7
8
9
10
11
12
# File 'lib/ceph-ruby/pool.rb', line 5

def initialize(cluster, name)
  self.cluster = cluster
  self.name = name
  if block_given?
    yield(self)
    close
  end
end

Instance Attribute Details

#clusterObject

Returns the value of attribute cluster.



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

def cluster
  @cluster
end

#handleObject

Returns the value of attribute handle.



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

def handle
  @handle
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#closeObject



31
32
33
34
35
36
# File 'lib/ceph-ruby/pool.rb', line 31

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

#ensure_openObject



54
55
56
57
# File 'lib/ceph-ruby/pool.rb', line 54

def ensure_open
  return if open?
  open
end

#exists?Boolean

Returns:

  • (Boolean)

Raises:

  • (SystemCallError)


14
15
16
17
18
19
20
# File 'lib/ceph-ruby/pool.rb', line 14

def exists?
  log("exists?")
  ret = Lib::Rados.rados_pool_lookup(cluster.handle, name)
  return true if ret >= 0
  return false if ret == -Errno::ENOENT::Errno
  raise SystemCallError.new("lookup of '#{name}' failed", -ret) if ret < 0
end

#log(message) ⇒ Object



59
60
61
# File 'lib/ceph-ruby/pool.rb', line 59

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

#openObject

Raises:

  • (SystemCallError)


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

def open
  return if open?
  log("open")
  handle_p = FFI::MemoryPointer.new(:pointer)
  ret = Lib::Rados.rados_ioctx_create(cluster.handle, name, handle_p)
  raise SystemCallError.new("creation of io context for '#{name}' failed", -ret) if ret < 0
  self.handle = handle_p.get_pointer(0)
end

#open?Boolean

helper methods below

Returns:

  • (Boolean)


50
51
52
# File 'lib/ceph-ruby/pool.rb', line 50

def open?
  !!handle
end

#rados_block_device(name, &block) ⇒ Object



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

def rados_block_device(name, &block)
  ensure_open
  RadosBlockDevice.new(self, name, &block)
end

#rados_object(name, &block) ⇒ Object



38
39
40
41
# File 'lib/ceph-ruby/pool.rb', line 38

def rados_object(name, &block)
  ensure_open
  RadosObject.new(self, name, &block)
end