Class: Libvirt::Collection::StorageVolumeCollection

Inherits:
AbstractCollection show all
Defined in:
lib/libvirt/collection/storage_volume_collection.rb

Overview

Represents a collection of storage volumes, which belongs to a storage pool.

Instance Attribute Summary

Attributes inherited from AbstractCollection

#interface

Instance Method Summary collapse

Methods inherited from AbstractCollection

#initialize

Constructor Details

This class inherits a constructor from Libvirt::Collection::AbstractCollection

Instance Method Details

#allArray

Returns all storage volumes. Its unnecessary to call this directly since the #all array is delegated for the various Array-like methods.

Returns:

  • (Array)


50
51
52
53
54
# File 'lib/libvirt/collection/storage_volume_collection.rb', line 50

def all
  read_array(:virStoragePoolListVolumes, :virStoragePoolNumOfVolumes, :string).collect do |name|
    find_by_name(name)
  end
end

#create(spec) ⇒ StorageVolume

Creates a new storage volume from an XML specification.

Returns:



41
42
43
# File 'lib/libvirt/collection/storage_volume_collection.rb', line 41

def create(spec)
  nil_or_object(FFI::Libvirt.virStorageVolCreateXML(interface, spec, 0), StorageVolume)
end

#find(value) ⇒ StorageVolume

Searches for a storage volume. This will search by name, then by key, then finally by path. If no storage volume is found, nil will be returned.

Returns:



11
12
13
14
15
# File 'lib/libvirt/collection/storage_volume_collection.rb', line 11

def find(value)
  result = find_by_name(value) rescue nil
  result ||= find_by_key(value) rescue nil
  result ||= find_by_path(value) rescue nil
end

#find_by_key(key) ⇒ StorageVolume

Searches for a storage volume by key.

Returns:



27
28
29
# File 'lib/libvirt/collection/storage_volume_collection.rb', line 27

def find_by_key(key)
  nil_or_object(FFI::Libvirt.virStorageVolLookupByKey(interface.connection, key), StorageVolume)
end

#find_by_name(name) ⇒ StorageVolume

Searches for a storage volume by name.

Returns:



20
21
22
# File 'lib/libvirt/collection/storage_volume_collection.rb', line 20

def find_by_name(name)
  nil_or_object(FFI::Libvirt.virStorageVolLookupByName(interface, name), StorageVolume)
end

#find_by_path(path) ⇒ StorageVolume

Searches for a storage volume by path.

Returns:



34
35
36
# File 'lib/libvirt/collection/storage_volume_collection.rb', line 34

def find_by_path(path)
  nil_or_object(FFI::Libvirt.virStorageVolLookupByPath(interface.connection, path), StorageVolume)
end