Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
do not copy the lxc template instead use the full path
Browse files Browse the repository at this point in the history
  • Loading branch information
globin committed Jul 16, 2015
1 parent f173bc4 commit 96b8c49
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
41 changes: 3 additions & 38 deletions lib/vagrant-lxc/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ def config_string
def create(name, backingstore, backingstore_options, template_path, config_file, template_options = {})
@cli.name = @container_name = name

import_template(template_path) do |template_name|
@logger.debug "Creating container..."
@cli.create template_name, backingstore, backingstore_options, config_file, template_options
end
@logger.debug "Creating container..."
@cli.create template_path, backingstore, backingstore_options, config_file, template_options
end

def share_folders(folders)
Expand All @@ -92,7 +90,7 @@ def share_folders(folders)
end

def share_folder(host_path, guest_path, mount_options = nil)
guest_path = guest_path.gsub(/^\//, '').gsub(' ', '\\\040')
guest_path = guest_path.gsub(/^\//, '').gsub(' ', '\\\040')
mount_options = Array(mount_options || ['bind', 'create=dir'])
host_path = host_path.to_s.gsub(' ', '\\\040')
@customizations << ['mount.entry', "#{host_path} #{guest_path} none #{mount_options.join(',')} 0 0"]
Expand Down Expand Up @@ -239,39 +237,6 @@ def write_config(contents)
@sudo_wrapper.run 'chown', 'root:root', base_path.join('config').to_s
end
end

def import_template(path)
template_name = "vagrant-tmp-#{@container_name}"
tmp_template_path = templates_path.join("lxc-#{template_name}").to_s

@logger.info 'Copying LXC template into place'
@sudo_wrapper.run('cp', path, tmp_template_path)
@sudo_wrapper.run('chmod', '+x', tmp_template_path)

yield template_name
ensure
@logger.info 'Removing LXC template'
if tmp_template_path
@sudo_wrapper.run('rm', tmp_template_path)
end
end

TEMPLATES_PATH_LOOKUP = %w(
/usr/share/lxc/templates
/usr/lib/lxc/templates
/usr/lib64/lxc/templates
/usr/local/lib/lxc/templates
)
def templates_path
return @templates_path if @templates_path

path = TEMPLATES_PATH_LOOKUP.find { |candidate| File.directory?(candidate) }
if !path
raise Errors::TemplatesDirMissing.new paths: TEMPLATES_PATH_LOOKUP.inspect
end

@templates_path = Pathname(path)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/unit/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

it 'creates container with the right arguments' do
expect(cli).to have_received(:create).with(
template_name,
template_path,
backingstore,
backingstore_opts,
config_file,
Expand Down

0 comments on commit 96b8c49

Please sign in to comment.