Class: Fog::Libvirt::Compute::Volume
- Inherits:
-
Model
- Object
- Model
- Fog::Libvirt::Compute::Volume
- Includes:
- Util
- Defined in:
- lib/fog/libvirt/models/compute/volume.rb
Instance Attribute Summary collapse
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
-
#clone(name) ⇒ Object
Clones this volume to the name provided.
- #clone_volume(new_name) ⇒ Object
-
#destroy ⇒ Object
Destroy a volume.
-
#initialize(attributes = { }) ⇒ Volume
constructor
Can be created by passing in :xml => “<xml to create volume>” A volume always belongs to a pool, :pool_name => “<name of pool>”.
-
#save ⇒ Object
Takes a pool and either :xml or other settings.
- #to_xml ⇒ Object
- #upload_image(file_path) ⇒ Object
-
#wipe ⇒ Object
Wipes a volume , zeroes disk.
Methods included from Util
#randomized_name, #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>”
27 28 29 30 31 32 33 34 |
# File 'lib/fog/libvirt/models/compute/volume.rb', line 27 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
#xml ⇒ Object (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
57 58 59 60 61 62 63 64 |
# File 'lib/fog/libvirt/models/compute/volume.rb', line 57 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
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fog/libvirt/models/compute/volume.rb', line 66 def clone_volume(new_name) requires :pool_name new_volume = self.dup new_volume.key = nil new_volume.name = new_name new_volume.id = service.clone_volume(pool_name, new_volume.to_xml, self.name).key new_volume.reload end |
#destroy ⇒ Object
Destroy a volume
47 48 49 |
# File 'lib/fog/libvirt/models/compute/volume.rb', line 47 def destroy service.volume_action key, :delete end |
#save ⇒ Object
Takes a pool and either :xml or other settings
37 38 39 40 41 42 43 44 |
# File 'lib/fog/libvirt/models/compute/volume.rb', line 37 def save requires :pool_name raise Fog::Errors::Error.new('Reserving an existing volume may create a duplicate') if key @xml ||= to_xml self.id = service.create_volume(pool_name, xml).key reload end |
#to_xml ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/fog/libvirt/models/compute/volume.rb', line 82 def to_xml builder = Nokogiri::XML::Builder.new do |xml| xml.volume do xml.name(name) allocation_size, allocation_unit = split_size_unit(allocation) xml.allocation(allocation_size, :unit => allocation_unit) capacity_size, capacity_unit = split_size_unit(capacity) xml.capacity(capacity_size, :unit => capacity_unit) xml.target do xml.format(:type => format_type) (xml) end if backing_volume xml.backingStore do xml.path(backing_volume.path) xml.format(:type => backing_volume.format_type) (xml) end end end end builder.to_xml end |
#upload_image(file_path) ⇒ Object
77 78 79 80 |
# File 'lib/fog/libvirt/models/compute/volume.rb', line 77 def upload_image(file_path) requires :pool_name service.upload_volume(pool_name, name, file_path) end |
#wipe ⇒ Object
Wipes a volume , zeroes disk
52 53 54 |
# File 'lib/fog/libvirt/models/compute/volume.rb', line 52 def wipe service.volume_action key, :wipe end |