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
13
14
15
# File 'lib/ceph-ruby/pool.rb', line 5

def initialize(cluster, name)
  self.cluster = cluster
  self.name = name
  if block_given?
    begin
      yield(self)
    ensure
      close
    end
  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



34
35
36
37
38
39
# File 'lib/ceph-ruby/pool.rb', line 34

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

#ensure_openObject



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

def ensure_open
  return if open?
  open
end

#exists?Boolean

Returns:

  • (Boolean)

Raises:

  • (SystemCallError)


17
18
19
20
21
22
23
# File 'lib/ceph-ruby/pool.rb', line 17

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



62
63
64
# File 'lib/ceph-ruby/pool.rb', line 62

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

#openObject

Raises:

  • (SystemCallError)


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

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)


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

def open?
  !!handle
end

#rados_block_device(name, &block) ⇒ Object



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

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

#rados_object(name, &block) ⇒ Object



41
42
43
44
# File 'lib/ceph-ruby/pool.rb', line 41

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