# 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
# File lib/virt/volume.rb, line 30 def destroy return true if new? @vol.delete fetch_volume new? end
# File lib/virt/volume.rb, line 18 def new? @vol.nil? end
# File lib/virt/volume.rb, line 37 def path; end
# 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
# File lib/virt/volume.rb, line 46 def default_allocated_size 0 end
# File lib/virt/volume.rb, line 60 def default_pool # this is an expensive call on hosts with lots of pools @connection.host.storage_pools.first end
default image size in GB
# File lib/virt/volume.rb, line 51 def default_size 8 end
# File lib/virt/volume.rb, line 69 def default_template_path; end
abstracted methods
# File lib/virt/volume.rb, line 67 def default_type; end
# File lib/virt/volume.rb, line 54 def fetch_volume return unless @vol = pool.find_volume_by_name(name) @size = to_gb(@vol.info.capacity) @allocated_size = to_gb(@vol.info.allocation) end
# File lib/virt/volume.rb, line 41 def name= name raise "invalid name" if name.nil? @name = name end