Class: Libvirt::StorageVolume

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ StorageVolume

Returns a new instance of StorageVolume.



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

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

Class Method Details

.load_ref(pointer) ⇒ Object

Raises:



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

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

Instance Method Details

#infoObject

Raises:



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

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

#to_ptrObject



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

def to_ptr
  @ptr
end

#xml_desc(options_or_flags = nil) ⇒ Object

Raises:



37
38
39
40
41
42
43
# File 'lib/libvirt/storage_volume.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.virStorageVolGetXMLDesc(@ptr, flags)
  raise Errors::LibError, "Couldn't get storage volume xml desc" if result.nil?

  result
end