Class: Libvirt::StoragePool

Inherits:
Object
  • Object
show all
Defined in:
lib/libvirt/storage_pool.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ StoragePool

Returns a new instance of StoragePool.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/libvirt/storage_pool.rb', line 12

def initialize(pointer)
  @ptr = pointer

  free = ->(obj_id) do
    dbg { "Finalize Libvirt::StoragePool 0x#{obj_id.to_s(16)} @ptr=#{@ptr}," }
    return unless @ptr

    fr_result = FFI::Storage.virStoragePoolFree(@ptr)
    warn "Couldn't free Libvirt::StoragePool (0x#{obj_id.to_s(16)}) pointer #{@ptr.address}" if fr_result.negative?
  end
  ObjectSpace.define_finalizer(self, free)
end

Class Method Details

.load_ref(pointer) ⇒ Object

Raises:



5
6
7
8
9
10
# File 'lib/libvirt/storage_pool.rb', line 5

def self.load_ref(pointer)
  result = FFI::Storage.virStoragePoolRef(pointer)
  raise Errors::LibError, "Couldn't retrieve storage pool reference" if result.negative?

  new(pointer)
end

Instance Method Details

#infoObject

Raises:



29
30
31
32
33
34
35
# File 'lib/libvirt/storage_pool.rb', line 29

def info
  info_ptr = ::FFI::MemoryPointer.new(FFI::Storage::PoolInfoStruct.by_value)
  result = FFI::Storage.virStoragePoolGetInfo(@ptr, info_ptr)
  raise Errors::LibError, "Couldn't get storage pool info" if result.negative?

  StoragePoolInfo.new(info_ptr)
end

#list_all_volumesObject

Raises:



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/libvirt/storage_pool.rb', line 52

def list_all_volumes
  size = list_all_volumes_qty
  return [] if size.zero?

  storage_volumes_ptr = ::FFI::MemoryPointer.new(:pointer, size)
  result = FFI::Storage.virStoragePoolListAllVolumes(@ptr, storage_volumes_ptr, 0)
  raise Errors::LibError, "Couldn't retrieve volumes list" if result.negative?

  ptr = storage_volumes_ptr.read_pointer
  ptr.get_array_of_pointer(0, size).map { |stv_ptr| StorageVolume.new(stv_ptr) }
end

#list_all_volumes_qtyObject

Raises:



45
46
47
48
49
50
# File 'lib/libvirt/storage_pool.rb', line 45

def list_all_volumes_qty
  result = FFI::Storage.virStoragePoolListAllVolumes(@ptr, nil, 0)
  raise Errors::LibError, "Couldn't retrieve volumes qty" if result.negative?

  result
end

#nameObject

Raises:



72
73
74
75
76
77
# File 'lib/libvirt/storage_pool.rb', line 72

def name
  result = FFI::Storage.virStoragePoolGetName(@ptr)
  raise Errors::LibError, "Couldn't retrieve storage pool name" if result.nil?

  result
end

#to_ptrObject



25
26
27
# File 'lib/libvirt/storage_pool.rb', line 25

def to_ptr
  @ptr
end

#uuidObject

Raises:



64
65
66
67
68
69
70
# File 'lib/libvirt/storage_pool.rb', line 64

def uuid
  buff = ::FFI::MemoryPointer.new(:char, Util::UUID_STRING_BUFLEN)
  result = FFI::Storage.virStoragePoolGetUUIDString(@ptr, buff)
  raise Errors::LibError, "Couldn't get storage pool uuid" if result.negative?

  buff.read_string
end

#xml_desc(options_or_flags = nil) ⇒ Object

Raises:



37
38
39
40
41
42
43
# File 'lib/libvirt/storage_pool.rb', line 37

def xml_desc(options_or_flags = nil)
  flags = Util.parse_flags options_or_flags, FFI::Storage.enum_type(:xml_flags)
  result = FFI::Storage.virStoragePoolGetXMLDesc(@ptr, flags)
  raise Errors::LibError, "Couldn't get storage pool xml desc" if result.nil?

  result
end