class Fog::Libvirt::Compute::Volume
Attributes
Public Class Methods
Source
# 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
Can be created by passing in :xml => “<xml to create volume>” A volume always belongs to a pool, :pool_name => “<name of pool>”
Calls superclass method
Public Instance Methods
Source
# 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
Clones this volume to the name provided
Source
# 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
Source
# File lib/fog/libvirt/models/compute/volume.rb, line 47 def destroy service.volume_action key, :delete end
Destroy a volume
Source
# 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
Takes a pool and either :xml or other settings
Source
# 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_permissions(xml) end if backing_volume xml.backingStore do xml.path(backing_volume.path) xml.format(:type => backing_volume.format_type) xml_permissions(xml) end end end end builder.to_xml end
Source
# 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
Source
# File lib/fog/libvirt/models/compute/volume.rb, line 52 def wipe service.volume_action key, :wipe end
Wipes a volume , zeroes disk
Private Instance Methods
Source
# File lib/fog/libvirt/models/compute/volume.rb, line 132 def default_pool_name name = "default" return name unless (service.pools.all(:name => name)).empty? # we default to the first pool we find. first_pool = service.pools.first raise Fog::Errors::Error.new('No storage pools are defined') unless first_pool first_pool.name end
Try to guess the default/first pool of no pool_name was specified
Source
# File lib/fog/libvirt/models/compute/volume.rb, line 143 def defaults { :persistent => true, :format_type => "raw", :name => randomized_name, :capacity => "10G", :allocation => "1G", :owner => nil, :group => nil, } end
Source
# File lib/fog/libvirt/models/compute/volume.rb, line 122 def image_suffix return "img" if format_type == "raw" format_type end
Source
# File lib/fog/libvirt/models/compute/volume.rb, line 127 def randominzed_name "#{super}.#{image_suffix}" end
Source
# File lib/fog/libvirt/models/compute/volume.rb, line 155 def split_size_unit(text) if (text.kind_of? String) && (matcher = text.match(/(\d+)(.+)/)) size = matcher[1] unit = matcher[2] else size = text.to_i unit = "G" end [size, unit] end
Source
# File lib/fog/libvirt/models/compute/volume.rb, line 113 def xml_permissions(xml) xml.permissions do xml.owner(owner) if owner xml.group(group) if group xml.mode('0744') xml.label('virt_image_t') end end