Class: QEMU::Image
- Inherits:
-
Object
- Object
- QEMU::Image
- Defined in:
- lib/qemu/image.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#format ⇒ Object
Returns the value of attribute format.
-
#options ⇒ Object
Returns the value of attribute options.
-
#size ⇒ Object
Returns the value of attribute size.
Class Method Summary collapse
Instance Method Summary collapse
- #convert(format, output_file = nil) ⇒ Object
- #create ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(file, options = {}) ⇒ Image
constructor
A new instance of Image.
- #options_arguments ⇒ Object
Constructor Details
#initialize(file, options = {}) ⇒ Image
Returns a new instance of Image.
6 7 8 9 10 |
# File 'lib/qemu/image.rb', line 6 def initialize(file, = {}) self.file = file = { :format => self.class.file_format(file) }.merge .each { |k,v| send "#{k}=", v } end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/qemu/image.rb', line 4 def file @file end |
#format ⇒ Object
Returns the value of attribute format.
4 5 6 |
# File 'lib/qemu/image.rb', line 4 def format @format end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/qemu/image.rb', line 4 def end |
#size ⇒ Object
Returns the value of attribute size.
4 5 6 |
# File 'lib/qemu/image.rb', line 4 def size @size end |
Class Method Details
.file_format(file) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/qemu/image.rb', line 12 def self.file_format(file) case `file #{file}` when /qcow/ "qcow2" when /x86 boot sector/ "raw" else QEMU.logger.info "Unknown file format : #{file}" "raw" end end |
.output_file(file, format) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/qemu/image.rb', line 39 def self.output_file(file, format) unless file.to_s.end_with? ".#{format}" "#{file}.#{format}" else file end end |
Instance Method Details
#convert(format, output_file = nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/qemu/image.rb', line 47 def convert(format, output_file = nil) output_file ||= self.class.output_file file, format unless self.format.to_s == format.to_s QEMU.sh! "qemu-img convert -O #{format} #{file} #{output_file}" end output_file end |
#create ⇒ Object
31 32 33 |
# File 'lib/qemu/image.rb', line 31 def create QEMU.sh! "qemu-img create -f #{format} #{options_arguments} #{file} #{size}" end |
#exists? ⇒ Boolean
35 36 37 |
# File 'lib/qemu/image.rb', line 35 def exists? File.exists? file end |
#options_arguments ⇒ Object
24 25 26 27 28 29 |
# File 'lib/qemu/image.rb', line 24 def if = .map { |k,v| "#{k}=#{v}" }.join(",") "-o #{options_value}" end end |