Class: Virt::Volume

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/virt/volume.rb

Direct Known Subclasses

KVM::Volume, Virt::VMWare::Volume

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#to_gb, #xml

Constructor Details

#initialize(options = {}) ⇒ Volume

Returns a new instance of Volume.



6
7
8
9
10
11
12
13
14
15
16
# 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

Instance Attribute Details

#allocated_sizeObject (readonly)

Returns the value of attribute allocated_size.



4
5
6
# File 'lib/virt/volume.rb', line 4

def allocated_size
  @allocated_size
end

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/virt/volume.rb', line 4

def key
  @key
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/virt/volume.rb', line 4

def name
  @name
end

#poolObject (readonly)

Returns the value of attribute pool.



4
5
6
# File 'lib/virt/volume.rb', line 4

def pool
  @pool
end

#sizeObject (readonly)

Returns the value of attribute size.



4
5
6
# File 'lib/virt/volume.rb', line 4

def size
  @size
end

#template_pathObject (readonly)

Returns the value of attribute template_path.



4
5
6
# File 'lib/virt/volume.rb', line 4

def template_path
  @template_path
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/virt/volume.rb', line 4

def type
  @type
end

#xml_descObject (readonly)

Returns the value of attribute xml_desc.



4
5
6
# File 'lib/virt/volume.rb', line 4

def xml_desc
  @xml_desc
end

Instance Method Details

#destroyObject



30
31
32
33
34
35
# File 'lib/virt/volume.rb', line 30

def destroy
  return true if new?
  @vol.delete
  fetch_volume
  new?
end

#new?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/virt/volume.rb', line 18

def new?
  @vol.nil?
end

#pathObject



37
# File 'lib/virt/volume.rb', line 37

def path; end

#saveObject



22
23
24
25
26
27
28
# 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