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

- (Volume) initialize(options = {})



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

- (Object) allocated_size (readonly)

Returns the value of attribute allocated_size



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

def allocated_size
  @allocated_size
end

- (Object) key (readonly)

Returns the value of attribute key



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

def key
  @key
end

- (Object) name

Returns the value of attribute name



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

def name
  @name
end

- (Object) pool (readonly)

Returns the value of attribute pool



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

def pool
  @pool
end

- (Object) size (readonly)

Returns the value of attribute size



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

def size
  @size
end

- (Object) template_path (readonly)

Returns the value of attribute template_path



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

def template_path
  @template_path
end

- (Object) type (readonly)

Returns the value of attribute type



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

def type
  @type
end

- (Object) xml_desc (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

- (Object) destroy



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

- (Boolean) new?



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

def new?
  @vol.nil?
end

- (Object) path



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

def path; end

- (Object) save



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