Class: Libvirt::StoragePool

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

Overview

Represents a single storage pool.

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ StoragePool

Initializes a new Libvirt::StoragePool object given a virStoragePoolPtr. Do not call this directly. Instead, use the Connection#storage_pools object to retrieve a specific Libvirt::StoragePool.



7
8
9
10
# File 'lib/libvirt/storage_pool.rb', line 7

def initialize(pointer)
  @pointer = pointer
  ObjectSpace.define_finalizer(self, method(:finalize))
end

Instance Method Details

#==(other) ⇒ Boolean

Provide a meaningful equality check for two storage pools by comparing UUID.

Returns:

  • (Boolean)


137
138
139
# File 'lib/libvirt/storage_pool.rb', line 137

def ==(other)
  other.is_a?(StoragePool) && other.uuid == uuid
end

#active?Boolean

Deterine if the storage pool is active or not.

Returns:

  • (Boolean)


45
46
47
# File 'lib/libvirt/storage_pool.rb', line 45

def active?
  FFI::Libvirt.virStoragePoolIsActive(self) == 1
end

#allocationFixnum

Returns the current allocation in bytes.

Returns:

  • (Fixnum)


115
116
117
# File 'lib/libvirt/storage_pool.rb', line 115

def allocation
  info[:allocation]
end

#availableFixnum

Returns the available free space in bytes.

Returns:

  • (Fixnum)


122
123
124
# File 'lib/libvirt/storage_pool.rb', line 122

def available
  info[:available]
end

#buildBoolean

Build the underlying storage pool.

Returns:

  • (Boolean)


59
60
61
# File 'lib/libvirt/storage_pool.rb', line 59

def build
  FFI::Libvirt.virStoragePoolBuild(self, 0) == 0
end

#capacityFixnum

Returns the capacity in bytes.

Returns:

  • (Fixnum)


108
109
110
# File 'lib/libvirt/storage_pool.rb', line 108

def capacity
  info[:capacity]
end

#connectionConnection

Returns the connection of this storage pool.

Returns:



15
16
17
# File 'lib/libvirt/storage_pool.rb', line 15

def connection
  Connection.new(FFI::Libvirt.virStoragePoolGetConnect(self))
end

#createBoolean Also known as: start

Starts an inactive storage pool.

Returns:

  • (Boolean)


66
67
68
69
# File 'lib/libvirt/storage_pool.rb', line 66

def create
  return true if active?
  FFI::Libvirt.virStoragePoolCreate(self, 0) == 0
end

#delete(type = nil) ⇒ Boolean

Delete the underlying pool resources. This is a non-recoverable operation. This won't undefine the pool.

Returns:

  • (Boolean)


76
77
78
79
# File 'lib/libvirt/storage_pool.rb', line 76

def delete(type=nil)
  type ||= :normal
  FFI::Libvirt.virStoragePoolDelete(self, type) == 0
end

#destroyBoolean Also known as: stop

Stops an active storage pool.

Returns:

  • (Boolean)


84
85
86
# File 'lib/libvirt/storage_pool.rb', line 84

def destroy
  FFI::Libvirt.virStoragePoolDestroy(self) == 0
end

#nameString

Returns the name of the network as a string.

Returns:

  • (String)


22
23
24
# File 'lib/libvirt/storage_pool.rb', line 22

def name
  FFI::Libvirt.virStoragePoolGetName(self)
end

#persistent?Boolean

Determine if the storage pool is persistent or not.

Returns:

  • (Boolean)


52
53
54
# File 'lib/libvirt/storage_pool.rb', line 52

def persistent?
  FFI::Libvirt.virStoragePoolIsPersistent(self) == 1
end

#stateSymbol

Returns the state of the storage pool as a symbol.

Returns:

  • (Symbol)


101
102
103
# File 'lib/libvirt/storage_pool.rb', line 101

def state
  info[:state]
end

#to_ptrFFI::Pointer

Returns the actual virStoragePoolPtr underlying this structure.

Returns:

  • (FFI::Pointer)


144
145
146
# File 'lib/libvirt/storage_pool.rb', line 144

def to_ptr
  @pointer
end

#undefineBoolean

Undefines the storage pool. This requires that the storage pool be inactive. This won't delete the underlying resources of the storage pool, however. Run #delete for that.

Returns:

  • (Boolean)


94
95
96
# File 'lib/libvirt/storage_pool.rb', line 94

def undefine
  FFI::Libvirt.virStoragePoolUndefine(self) == 0
end

#uuidString

Returns the UUID of the storage pool as a string.

Returns:

  • (String)


29
30
31
32
33
# File 'lib/libvirt/storage_pool.rb', line 29

def uuid
  output_ptr = FFI::MemoryPointer.new(:char, 36)
  FFI::Libvirt.virStoragePoolGetUUIDString(self, output_ptr)
  output_ptr.read_string
end

#volumesCollection::StorageVolumeCollection

Returns the volumes associated with this storage pool.



129
130
131
# File 'lib/libvirt/storage_pool.rb', line 129

def volumes
  Collection::StorageVolumeCollection.new(self)
end

#xmlString

Returns the XML description of this storage pool.

Returns:

  • (String)


38
39
40
# File 'lib/libvirt/storage_pool.rb', line 38

def xml
  FFI::Libvirt.virStoragePoolGetXMLDesc(self, 0)
end