do not copy the lxc template instead use the full path
This commit is contained in:
parent
64240323f0
commit
2b91983cae
3 changed files with 4 additions and 45 deletions
|
@ -79,10 +79,8 @@ module Vagrant
|
||||||
def create(name, backingstore, backingstore_options, template_path, config_file, template_options = {})
|
def create(name, backingstore, backingstore_options, template_path, config_file, template_options = {})
|
||||||
@cli.name = @container_name = name
|
@cli.name = @container_name = name
|
||||||
|
|
||||||
import_template(template_path) do |template_name|
|
@logger.debug "Creating container..."
|
||||||
@logger.debug "Creating container..."
|
@cli.create template_path, backingstore, backingstore_options, config_file, template_options
|
||||||
@cli.create template_name, backingstore, backingstore_options, config_file, template_options
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def share_folders(folders)
|
def share_folders(folders)
|
||||||
|
@ -92,7 +90,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def share_folder(host_path, guest_path, mount_options = nil)
|
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'])
|
mount_options = Array(mount_options || ['bind', 'create=dir'])
|
||||||
host_path = host_path.to_s.gsub(' ', '\\\040')
|
host_path = host_path.to_s.gsub(' ', '\\\040')
|
||||||
@customizations << ['mount.entry', "#{host_path} #{guest_path} none #{mount_options.join(',')} 0 0"]
|
@customizations << ['mount.entry', "#{host_path} #{guest_path} none #{mount_options.join(',')} 0 0"]
|
||||||
|
@ -239,39 +237,6 @@ module Vagrant
|
||||||
@sudo_wrapper.run 'chown', 'root:root', base_path.join('config').to_s
|
@sudo_wrapper.run 'chown', 'root:root', base_path.join('config').to_s
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,7 +54,7 @@ describe Vagrant::LXC::Driver do
|
||||||
|
|
||||||
it 'creates container with the right arguments' do
|
it 'creates container with the right arguments' do
|
||||||
expect(cli).to have_received(:create).with(
|
expect(cli).to have_received(:create).with(
|
||||||
template_name,
|
template_path,
|
||||||
backingstore,
|
backingstore,
|
||||||
backingstore_opts,
|
backingstore_opts,
|
||||||
config_file,
|
config_file,
|
||||||
|
|
|
@ -80,7 +80,6 @@ end
|
||||||
|
|
||||||
base = "/var/lib/lxc"
|
base = "/var/lib/lxc"
|
||||||
base_path = %r{\A#{base}/.*\z}
|
base_path = %r{\A#{base}/.*\z}
|
||||||
templates_path = %r{\A/usr/(share|lib|lib64|local/lib)/lxc/templates/.*\z}
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Commands from provider.rb
|
# Commands from provider.rb
|
||||||
|
@ -96,11 +95,6 @@ Whitelist.add '<%= cmd_paths['mkdir'] %>', '-p', base_path
|
||||||
# - Container config customizations and pruning
|
# - Container config customizations and pruning
|
||||||
Whitelist.add '<%= cmd_paths['cp'] %>', '-f', %r{/tmp/.*}, base_path
|
Whitelist.add '<%= cmd_paths['cp'] %>', '-f', %r{/tmp/.*}, base_path
|
||||||
Whitelist.add '<%= cmd_paths['chown'] %>', 'root:root', base_path
|
Whitelist.add '<%= cmd_paths['chown'] %>', 'root:root', base_path
|
||||||
# - Template import
|
|
||||||
Whitelist.add '<%= cmd_paths['cp'] %>', %r{\A.*\z}, templates_path
|
|
||||||
Whitelist.add '<%= cmd_paths['chmod'] %>', '+x', templates_path
|
|
||||||
# - Template removal
|
|
||||||
Whitelist.add '<%= cmd_paths['rm'] %>', templates_path
|
|
||||||
# - Packaging
|
# - Packaging
|
||||||
Whitelist.add '<%= cmd_paths['tar'] %>', '--numeric-owner', '-cvzf', %r{/tmp/.*/rootfs.tar.gz}, '-C', base_path, './rootfs'
|
Whitelist.add '<%= cmd_paths['tar'] %>', '--numeric-owner', '-cvzf', %r{/tmp/.*/rootfs.tar.gz}, '-C', base_path, './rootfs'
|
||||||
Whitelist.add '<%= cmd_paths['chown'] %>', /\A\d+:\d+\z/, %r{\A/tmp/.*/rootfs\.tar\.gz\z}
|
Whitelist.add '<%= cmd_paths['chown'] %>', /\A\d+:\d+\z/, %r{\A/tmp/.*/rootfs\.tar\.gz\z}
|
||||||
|
|
Loading…
Reference in a new issue