Class: Fog::Compute::Libvirt::Volume

Inherits:
Model
  • Object
show all
Includes:
Fog::Compute::LibvirtUtil
Defined in:
lib/fog/libvirt/models/compute/volume.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Fog::Compute::LibvirtUtil

#randomized_name, #to_xml, #xml_element, #xml_elements

Constructor Details

#initialize(attributes = { }) ⇒ Volume

Can be created by passing in :xml => “<xml to create volume>” A volume always belongs to a pool, :pool_name => “<name of pool>”



25
26
27
28
29
30
31
32
# File 'lib/fog/libvirt/models/compute/volume.rb', line 25

def initialize(attributes={ })
  @xml = attributes.delete(:xml)
  super(defaults.merge(attributes))

  # We need a connection to calculate the pool_name
  # This is why we do this after super
  self.pool_name ||= default_pool_name
end

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



8
9
10
# File 'lib/fog/libvirt/models/compute/volume.rb', line 8

def xml
  @xml
end

Instance Method Details

#clone(name) ⇒ Object

Clones this volume to the name provided



54
55
56
57
58
59
60
61
# File 'lib/fog/libvirt/models/compute/volume.rb', line 54

def clone(name)
  new_volume      = self.dup
  new_volume.key  = nil
  new_volume.name = name
  new_volume.save

  new_volume.reload
end

#clone_volume(new_name) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/fog/libvirt/models/compute/volume.rb', line 63

def clone_volume(new_name)
  requires :pool_name

  new_volume      = self.dup
  new_volume.key  = nil
  new_volume.name = new_name
  new_volume.path = service.clone_volume(pool_name, new_volume.to_xml, self.name).path

  new_volume.reload
end

#destroyObject

Destroy a volume



44
45
46
# File 'lib/fog/libvirt/models/compute/volume.rb', line 44

def destroy
  service.volume_action key, :delete
end

#saveObject

Takes a pool and either :xml or other settings

Raises:

  • (Fog::Errors::Error)


35
36
37
38
39
40
41
# File 'lib/fog/libvirt/models/compute/volume.rb', line 35

def save
  requires :pool_name

  raise Fog::Errors::Error.new('Reserving an existing volume may create a duplicate') if key
  @xml ||= to_xml
  self.path = service.create_volume(pool_name, xml).path
end

#wipeObject

Wipes a volume , zeroes disk



49
50
51
# File 'lib/fog/libvirt/models/compute/volume.rb', line 49

def wipe
  service.volume_action key, :wipe
end