Sha256: 3368a20cbd288a8f26ceca93c93c8c8f8fd1c2392272f648aa1e817d37e96a12

Contents?: true

Size: 1.42 KB

Versions: 13

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Libvirt
  class StorageVolume
    def self.load_ref(pointer)
      result = FFI::Storage.virStorageVolRef(pointer)
      raise Errors::LibError, "Couldn't retrieve storage volume reference" if result.negative?

      new(pointer)
    end

    def initialize(pointer)
      @ptr = pointer

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

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

    def to_ptr
      @ptr
    end

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

      StorageVolumeInfo.new(info_ptr)
    end

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

      result
    end

    private

    def dbg(&block)
      Util.log(:debug, 'Libvirt::Domain', &block)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
libvirt_ffi-0.8.1 lib/libvirt/storage_volume.rb
libvirt_ffi-0.8.0 lib/libvirt/storage_volume.rb
libvirt_ffi-0.7.0 lib/libvirt/storage_volume.rb
libvirt_ffi-0.6.2 lib/libvirt/storage_volume.rb
libvirt_ffi-0.6.1 lib/libvirt/storage_volume.rb
libvirt_ffi-0.6.0 lib/libvirt/storage_volume.rb
libvirt_ffi-0.5.6 lib/libvirt/storage_volume.rb
libvirt_ffi-0.5.5 lib/libvirt/storage_volume.rb
libvirt_ffi-0.5.4 lib/libvirt/storage_volume.rb
libvirt_ffi-0.5.3 lib/libvirt/storage_volume.rb
libvirt_ffi-0.5.2 lib/libvirt/storage_volume.rb
libvirt_ffi-0.5.1 lib/libvirt/storage_volume.rb
libvirt_ffi-0.5.0 lib/libvirt/storage_volume.rb