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

Commit

Permalink
add backingstore parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Cam Cope authored and tailhook committed Apr 28, 2014
1 parent 47cf361 commit a9248cb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/vagrant-lxc/action/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def initialize(app, env)
end

def call(env)
container_name = env[:machine].provider_config.container_name
config = env[:machine].provider_config
container_name = config.container_name

case container_name
when :machine
Expand All @@ -24,6 +25,8 @@ def call(env)

env[:machine].provider.driver.create(
container_name,
config.backingstore,
config.backingstore_options,
env[:lxc_template_src],
env[:lxc_template_config],
env[:lxc_template_opts]
Expand Down
15 changes: 15 additions & 0 deletions lib/vagrant-lxc/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ class Config < Vagrant.plugin("2", :config)
# @return [Array]
attr_reader :customizations

# A string that contains the backing store type used with lxc-create -B
attr_accessor :backingstore

# Optional arguments for the backing store, such as --fssize, --fstype, ...
attr_accessor :backingstore_options

# A String that points to a file that acts as a wrapper for sudo commands.
#
# This allows us to have a single entry when whitelisting NOPASSWD commands
Expand All @@ -18,6 +24,8 @@ class Config < Vagrant.plugin("2", :config)

def initialize
@customizations = []
@backingstore = UNSET_VALUE
@backingstore_options = []
@sudo_wrapper = UNSET_VALUE
@container_name = UNSET_VALUE
end
Expand All @@ -37,9 +45,16 @@ def customize(key, value)
@customizations << [key, value]
end

# Stores options for backingstores like lvm, btrfs, etc
def backingstore_option(key, value)
@backingstore_options << [key, value]
end

def finalize!
@sudo_wrapper = nil if @sudo_wrapper == UNSET_VALUE
@container_name = nil if @container_name == UNSET_VALUE
@backingstore = "none" if @backingstore == UNSET_VALUE
@existing_container_name = nil if @existing_container_name == UNSET_VALUE
end

def validate(machine)
Expand Down
4 changes: 2 additions & 2 deletions lib/vagrant-lxc/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ def config_string
@sudo_wrapper.run('cat', base_path.join('config').to_s)
end

def create(name, template_path, config_file, template_options = {})
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, config_file, template_options
@cli.create template_name, backingstore, backingstore_options, config_file, template_options
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/vagrant-lxc/driver/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def state
end
end

def create(template, config_file, template_opts = {})
def create(template, backingstore, backingstore_options, config_file, template_opts = {})
if config_file
config_opts = ['-f', config_file]
end
Expand All @@ -54,6 +54,8 @@ def create(template, config_file, template_opts = {})
extra.unshift '--' unless extra.empty?

run :create,
'-B', backingstore,
*(backingstore_options.to_a.flatten),
'--template', template,
'--name', @name,
*(config_opts),
Expand Down

0 comments on commit a9248cb

Please sign in to comment.