Class: Libvirt::Collection::StoragePoolCollection

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

Overview

Represents a collection of storage pools.

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

#activeArray<StoragePool>

Returns the active storage pools.

Returns:



40
41
42
43
44
# File 'lib/libvirt/collection/storage_pool_collection.rb', line 40

def active
  read_array(:virConnectListStoragePools, :virConnectNumOfStoragePools, :string).collect do |name|
    find_by_name(name)
  end
end

#allArray<StoragePool>

Returns all storage pools.

Returns:



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

def all
  inactive + active
rescue Exception::LibvirtError
  # If inactive isn't supported, then we just return the active
  # storage pools.
  active
end

#find(value) ⇒ StoragePool

Search for a storage pool. This will first search by name and then by UUID, returning the first result returned.

Returns:



9
10
11
12
# File 'lib/libvirt/collection/storage_pool_collection.rb', line 9

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

#find_by_name(name) ⇒ StoragePool

Search for a storage pool by name.

Returns:



17
18
19
# File 'lib/libvirt/collection/storage_pool_collection.rb', line 17

def find_by_name(name)
  nil_or_object(FFI::Libvirt.virStoragePoolLookupByName(interface, name), StoragePool)
end

#find_by_uuid(uuid) ⇒ StoragePool

Search for a storage pool by UUID.

Returns:



24
25
26
# File 'lib/libvirt/collection/storage_pool_collection.rb', line 24

def find_by_uuid(uuid)
  nil_or_object(FFI::Libvirt.virStoragePoolLookupByUUIDString(interface, uuid), StoragePool)
end

#inactiveArray<StoragePool>

Returns the inactive storage pools.

Returns:



31
32
33
34
35
# File 'lib/libvirt/collection/storage_pool_collection.rb', line 31

def inactive
  read_array(:virConnectListDefinedStoragePools, :virConnectNumOfDefinedStoragePools, :string).collect do |name|
    find_by_name(name)
  end
end