class Libvirt::StoragePool

Public Class Methods

load_ref(pointer) click to toggle source
# 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
new(pointer) click to toggle source
# 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

Public Instance Methods

info() click to toggle source
# 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_volumes() click to toggle source
# 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_qty() click to toggle source
# 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
name() click to toggle source
# 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_ptr() click to toggle source
# File lib/libvirt/storage_pool.rb, line 25
def to_ptr
  @ptr
end
uuid() click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

dbg(&block) click to toggle source
# File lib/libvirt/storage_pool.rb, line 81
def dbg(&block)
  Util.log(:debug, 'Libvirt::StoragePool', &block)
end