Class: ForemanAP::StoragePool

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

Overview

A storage pool containing disk volumes.

Instance Method Summary collapse

Constructor Details

#initialize(conn, name) ⇒ StoragePool

Create a new object.

conn

A libvirt connection handle.

name

The name of the storage pool.



23
24
25
# File 'lib/foreman_vm/storage_pool.rb', line 23

def initialize(conn, name)
  @sph = conn.lookup_storage_pool_by_name(name)
end

Instance Method Details

#create_volume(path, capacity) ⇒ Object

Create a new volume within the storage pool.

path

the full path to the volume

capacity

the disk capacity, in bytes



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/foreman_vm/storage_pool.rb', line 31

def create_volume(path,capacity)
 xml = "<volume>
          <name>#{File.basename(path)}</name>
          <key>#{path}</key>
          <source>
          </source>
          <capacity unit='bytes'>#{capacity}</capacity>
          <allocation unit='bytes'>197120</allocation>
          <target>
            <path>#{path}</path>
            <format type='raw'/>
            <permissions>
              <mode>0660</mode>
              <owner>107</owner>
              <group>107</group>
            </permissions>
          </target>
        </volume>
 "
 #TODO: @log.debug "creating volume: #{xml}"
 @sph.create_volume_xml(xml)
end

#refreshObject

Scan the pool for changes. This is useful for pools that are shared across multiple hosts in a cluster.



8
9
10
11
# File 'lib/foreman_vm/storage_pool.rb', line 8

def refresh
  @sph.refresh
  true
end

#volume(name) ⇒ Object

Lookup a volume by name, and return an object handle.



14
15
16
# File 'lib/foreman_vm/storage_pool.rb', line 14

def volume(name)
  Volume.new(@sph, name)
end