Skip to content

Commit

Permalink
Include changes recommended by patch review for multiple disks.
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleidea committed May 6, 2014
1 parent be20425 commit 72fbeda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
18 changes: 12 additions & 6 deletions lib/vagrant-libvirt/action/create_domain.rb
Expand Up @@ -12,6 +12,14 @@ def initialize(app, env)
@app = app
end

def _disk_name(name, disk)
return "#{name}-#{disk[:device]}.#{disk[:type]}" # disk name
end

def _disks_print(disks)
return disks.collect{ |x| x[:device]+'('+x[:type]+','+x[:size]+')' }.join(', ')
end

def call(env)
# Get config.
config = env[:machine].provider_config
Expand Down Expand Up @@ -43,16 +51,14 @@ def call(env)
raise Errors::DomainVolumeExists if domain_volume == nil
@domain_volume_path = domain_volume.path

#storage_prefix = '/var/lib/libvirt/images/'
# the default storage prefix is typically: /var/lib/libvirt/images/
storage_prefix = File.dirname(@domain_volume_path)+'/' # steal

@disks.each do |disk|
dname = "#{@name}-#{disk[:device]}.#{disk[:type]}" # disk name
disk[:name] = dname
disk[:name] = _disk_name(@name, disk)
if disk[:path].nil?
disk[:path] = "#{storage_prefix}#{dname}" # automatically chosen!
disk[:path] = "#{storage_prefix}#{_disk_name(@name, disk)}" # automatically chosen!
end
#puts "Disk: #{disk[:device]}, #{disk[:type]}, #{disk[:path]}"

# make the disk. equivalent to:
# qemu-img create -f qcow2 <path> 5g
Expand Down Expand Up @@ -84,7 +90,7 @@ def call(env)
env[:ui].info(" -- Kernel: #{@kernel}")
env[:ui].info(" -- Initrd: #{@initrd}")
if @disks.length > 0
env[:ui].info(" -- Disks: #{@disks.collect{ |x| x[:device]+'('+x[:type]+','+x[:size]+')' }.join(', ')}")
env[:ui].info(" -- Disks: #{_disks_print(@disks)}")
end
@disks.each do |disk|
env[:ui].info(" -- Disk(#{disk[:device]}): #{disk[:path]}")
Expand Down
6 changes: 3 additions & 3 deletions lib/vagrant-libvirt/config.rb
Expand Up @@ -84,14 +84,14 @@ def initialize
@disks = UNSET_VALUE
end

def __get_device(disks)
def _get_device(disks)
disks = [] if disks == UNSET_VALUE
# skip existing devices and also the first one (vda)
exist = disks.collect {|x| x[:device]}+[1.vdev.to_s]
skip = 1 # we're 1 based, not 0 based...
while true do
dev = skip.vdev # get lettered device
if not exist.include?(dev)
if !exist.include?(dev)
return dev
end
skip+=1
Expand All @@ -101,7 +101,7 @@ def __get_device(disks)
# NOTE: this will run twice for each time it's needed- keep it idempotent
def storage(storage_type, options={})
options = {
:device => __get_device(@disks),
:device => _get_device(@disks),
:type => 'qcow2',
:size => '10G', # matches the fog default
:path => nil,
Expand Down

0 comments on commit 72fbeda

Please sign in to comment.