Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilbulgarian/b922a71823e4e1ebceec56d5eaeabc3e to your computer and use it in GitHub Desktop.
Save evilbulgarian/b922a71823e4e1ebceec56d5eaeabc3e to your computer and use it in GitHub Desktop.
Bringing machine 'default' up with 'lxc' provider...
==> default: Importing base box 'vladi/xenial64-lxc'...
==> default: Setting up mount entries for shared folders...
default: /vagrant => /home/vladi/repo/salt-stack
default: /srv/salt => /home/vladi/repo/salt-stack/salt
default: /srv/pillar => /home/vladi/repo/salt-stack/pillar
default: /srv/formulas => /home/vladi/repo/salt-stack/formulas
default: /tmp/vagrant-cache => /home/vladi/.vagrant.d/cache/vladi/xenial64-lxc
==> default: Starting container...
/home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/driver/cli.rb:37:in `version': Unable to parse lxc version! (RuntimeError)
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/driver/cli.rb:148:in `support_config_command?'
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/driver.rb:38:in `containers_path'
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/driver.rb:46:in `base_path'
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/driver.rb:76:in `config_string'
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/driver.rb:235:in `prune_customizations'
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/driver.rb:106:in `start'
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/action/boot.rb:33:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/action/private_networks.rb:10:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/action/forward_ports.rb:29:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/action/warn_networks.rb:14:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builtin/set_hostname.rb:16:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/action/prepare_nfs_settings.rb:15:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builtin/synced_folders.rb:87:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builtin/synced_folder_cleanup.rb:28:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/plugins/synced_folders/nfs/action_cleanup.rb:25:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/action/prepare_nfs_valid_ids.rb:14:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb:49:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builtin/env_set.rb:19:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /home/vladi/.vagrant.d/gems/gems/vagrant-omnibus-1.4.1/lib/vagrant-omnibus/action/install_chef.rb:38:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /home/vladi/.vagrant.d/gems/gems/vagrant-cachier-1.2.1/lib/vagrant-cachier/action/install_buckets.rb:14:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builtin/provision.rb:80:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /home/vladi/.vagrant.d/gems/gems/vagrant-cachier-1.2.1/lib/vagrant-cachier/action/configure_bucket_root.rb:20:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builder.rb:116:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/runner.rb:66:in `block in run'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/util/busy.rb:19:in `busy'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/runner.rb:66:in `run'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builtin/call.rb:53:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builtin/box_check_outdated.rb:23:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/action/create.rb:33:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/action/handle_box_metadata.rb:41:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builtin/handle_box.rb:56:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:95:in `block in finalize_action'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builder.rb:116:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/runner.rb:66:in `block in run'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/util/busy.rb:19:in `busy'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/runner.rb:66:in `run'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builtin/call.rb:53:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/warden.rb:34:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/builder.rb:116:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/runner.rb:66:in `block in run'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/util/busy.rb:19:in `busy'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/action/runner.rb:66:in `run'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/machine.rb:225:in `action_raw'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/machine.rb:200:in `block in action'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/environment.rb:561:in `lock'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/machine.rb:186:in `call'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/machine.rb:186:in `action'
from /usr/lib64/ruby/gems/2.0.0/gems/vagrant-1.8.4/lib/vagrant/batch_action.rb:82:in `block (2 levels) in run'
vladi@grendel  ~/repo/salt-stack  vim /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/driver/cli.rb
vladi@grendel  ~/repo/salt-stack  lxc-config  ✓  2061  11:39:31
Usage: lxc-config -l: list all available configuration items
lxc-config item: print configuration item
vladi@grendel  ~/repo/salt-stack  lxc-config --version  1 ↵  2062  11:39:35
Unknown configuration item: --version
vladi@grendel  ~/repo/salt-stack  vim /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/driver/cli.rb
vladi@grendel  ~/repo/salt-stack  cat /home/vladi/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/lib/vagrant-lxc/driver/cli.rb
require "vagrant/util/retryable"
require "vagrant/util/subprocess"
require "vagrant-lxc/errors"
module Vagrant
module LXC
class Driver
class CLI
attr_accessor :name
class TransitionBlockNotProvided < RuntimeError; end
class TargetStateNotReached < RuntimeError
def initialize(target_state, state)
msg = "Target state '#{target_state}' not reached, currently on '#{state}'"
super(msg)
end
end
def initialize(sudo_wrapper, name = nil)
@sudo_wrapper = sudo_wrapper
@name = name
@logger = Log4r::Logger.new("vagrant::provider::lxc::container::cli")
end
def list
run(:ls).split(/\s+/).uniq
end
def version
return @version if @version
@version = support_version_command? ? run(:version) : run(:create, '--version')
if @version =~ /(.+)\s*$/
@version = $1.downcase
else
# TODO: Raise an user friendly error
raise 'Unable to parse lxc version!'
end
end
def config(param)
if support_config_command?
run(:config, param).gsub("\n", '')
else
raise Errors::CommandNotSupported, name: 'config', available_version: '> 1.x.x', version: version
end
end
def state
if @name && run(:info, '--name', @name, retryable: true) =~ /^state:[^A-Z]+([A-Z]+)$/i
$1.downcase.to_sym
elsif @name
:unknown
end
end
def create(template, backingstore, backingstore_options, config_file, template_opts = {})
if config_file
config_opts = ['-f', config_file]
end
extra = template_opts.to_a.flatten
extra.unshift '--' unless extra.empty?
run :create,
'-B', backingstore,
'--template', template,
'--name', @name,
*(backingstore_options.to_a.flatten),
*(config_opts),
*extra
rescue Errors::ExecuteError => e
if e.stderr =~ /already exists/i
raise Errors::ContainerAlreadyExists, name: @name
else
raise
end
end
def destroy
run :destroy, '--name', @name
end
def start(options = [])
run :start, '-d', '--name', @name, *Array(options)
end
def stop
attach '/sbin/halt' if supports_attach?
run :stop, '--name', @name
end
def attach(*cmd)
cmd = ['--'] + cmd
if cmd.last.is_a?(Hash)
opts = cmd.pop
namespaces = Array(opts[:namespaces]).map(&:upcase).join('|')
# HACK: The wrapper script should be able to handle this
if @sudo_wrapper.wrapper_path
namespaces = "'#{namespaces}'"
end
if namespaces
if supports_attach_with_namespaces?
extra = ['--namespaces', namespaces]
else
raise LXC::Errors::NamespacesNotSupported
end
end
end
run :attach, '--name', @name, *((extra || []) + cmd)
end
def transition_to(target_state, tries = 30, timeout = 1, &block)
raise TransitionBlockNotProvided unless block_given?
yield self
while (last_state = self.state) != target_state && tries > 0
@logger.debug "Target state '#{target_state}' not reached, currently on '#{last_state}'"
sleep timeout
tries -= 1
end
unless last_state == target_state
# TODO: Raise an user friendly message
raise TargetStateNotReached.new target_state, last_state
end
end
def supports_attach?
unless defined?(@supports_attach)
begin
@supports_attach = true
run(:attach, '--name', @name, '--', '/bin/true')
rescue LXC::Errors::ExecuteError
@supports_attach = false
end
end
return @supports_attach
end
def support_config_command?
version[0].to_i >= 1
end
def support_version_command?
@sudo_wrapper.run('which', 'lxc-version').strip.chomp != ''
rescue Vagrant::LXC::Errors::ExecuteError
return false
end
private
def run(command, *args)
@sudo_wrapper.run("lxc-#{command}", *args)
end
def supports_attach_with_namespaces?
unless defined?(@supports_attach_with_namespaces)
@supports_attach_with_namespaces = run(:attach, '-h', :show_stderr => true).values.join.include?('--namespaces')
end
return @supports_attach_with_namespaces
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment