class Virt::Volume

Attributes

allocated_size[R]
key[R]
name[R]
pool[R]
size[R]
template_path[R]
type[R]
xml_desc[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/virt/volume.rb, line 6
def initialize options = {}
  @connection     = Virt.connection
  self.name       = options[:name]           || raise("Volume requires a name")
  # If our volume already exists, we ignore the provided options and defaults
  @pool            = options[:pool].nil? ? default_pool : @connection.host.storage_pool(options[:pool])
  fetch_volume
  @type           ||= options[:type]           || default_type
  @allocated_size ||= options[:allocated_size] || default_allocated_size
  @template_path  ||= options[:template_path]  || default_template_path
  @size           ||= options[:size]           || default_size
end

Public Instance Methods

destroy() click to toggle source
# File lib/virt/volume.rb, line 30
def destroy
  return true if new?
  @vol.delete
  fetch_volume
  new?
end
new?() click to toggle source
# File lib/virt/volume.rb, line 18
def new?
  @vol.nil?
end
path() click to toggle source
# File lib/virt/volume.rb, line 37
def path; end
save() click to toggle source
# File lib/virt/volume.rb, line 22
def save
  raise "volume already exists, can't save" unless new?
  #validations
  #update?
  @vol=pool.create_vol(self)
  !new?
end

Protected Instance Methods

default_allocated_size() click to toggle source
# File lib/virt/volume.rb, line 46
def default_allocated_size
  0
end
default_pool() click to toggle source
# File lib/virt/volume.rb, line 60
def default_pool
  # this is an expensive call on hosts with lots of pools
  @connection.host.storage_pools.first
end
default_size() click to toggle source

default image size in GB

# File lib/virt/volume.rb, line 51
def default_size
  8
end
default_template_path() click to toggle source
# File lib/virt/volume.rb, line 69
def default_template_path; end
default_type() click to toggle source

abstracted methods

# File lib/virt/volume.rb, line 67
def default_type; end
fetch_volume() click to toggle source
# File lib/virt/volume.rb, line 54
def fetch_volume
  return unless @vol = pool.find_volume_by_name(name)
  @size           = to_gb(@vol.info.capacity)
  @allocated_size = to_gb(@vol.info.allocation)
end
name=(name) click to toggle source
# File lib/virt/volume.rb, line 41
def name= name
  raise "invalid name" if name.nil?
  @name = name
end