Class: VagrantPlugins::ProviderKvm::Util::DiskInfo
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderKvm::Util::DiskInfo
- Includes:
- Errors
- Defined in:
- lib/vagrant-kvm/util/disk_info.rb
Instance Attribute Summary collapse
-
#backing ⇒ Object
readonly
Returns the value of attribute backing.
-
#capacity ⇒ Object
readonly
Returns the value of attribute capacity.
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(vol_path) ⇒ DiskInfo
constructor
A new instance of DiskInfo.
Constructor Details
#initialize(vol_path) ⇒ DiskInfo
Returns a new instance of DiskInfo.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vagrant-kvm/util/disk_info.rb', line 9 def initialize(vol_path) logger = Log4r::Logger.new("vagrant::kvm::util::disk_info") # default values @capacity = {:size => 10, :unit => 'G'} @backing = nil @cluster = nil begin diskinfo = %x[qemu-img info #{vol_path}] diskinfo.each_line do |line| case line when /^file format:/ result = line.match(%r{file format:\s+(?<format>(\w+))}) @type = result[:format] when /virtual size:/ result = line.match(%r{virtual size:\s+(?<size>\d+(\.\d+)?)(?<unit>.)\s+\((?<bytesize>\d+)\sbytes\)}) # always take the size in bytes to avoid conversion @capacity = {:size => result[:bytesize], :unit => "B"} when /^disk size:/ result = line.match(%r{disk size:\s+(?<size>\d+(\.\d+)?)(?<unit>.)}) @size = {:size => result[:size], :unit => result[:unit]} when /^backing file:/ result = line.match(%r{backing file:\s+(?<file>(\S+))}) @backing = result[:file] when /^cluster[_ ]size:/ result = line.match(%r{cluster[_ ]size:\s+(?<size>(\d+))}) @cluster = result[:size] end end rescue Errors::KvmFailedCommand => e logger.error 'Failed to find volume size. Using defaults.' logger.error e end end |
Instance Attribute Details
#backing ⇒ Object (readonly)
Returns the value of attribute backing.
7 8 9 |
# File 'lib/vagrant-kvm/util/disk_info.rb', line 7 def backing @backing end |
#capacity ⇒ Object (readonly)
Returns the value of attribute capacity.
7 8 9 |
# File 'lib/vagrant-kvm/util/disk_info.rb', line 7 def capacity @capacity end |
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
7 8 9 |
# File 'lib/vagrant-kvm/util/disk_info.rb', line 7 def cluster @cluster end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
7 8 9 |
# File 'lib/vagrant-kvm/util/disk_info.rb', line 7 def size @size end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/vagrant-kvm/util/disk_info.rb', line 7 def type @type end |