vagrant-lxd 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ceae5ec31aecf1934e40466195849ad4f2152b7a
4
- data.tar.gz: 6d8ba4edabdfa6bc4007c81eb6c41a12836c2b83
3
+ metadata.gz: abc3e26c2ce8d3408a4e4469219404dc24a08d50
4
+ data.tar.gz: 720aac0252d1af7b40a0d15893fa8aeebaa08bcf
5
5
  SHA512:
6
- metadata.gz: 2bfef2ee6532fd17a6ef5a0816fb5452e128866ac66b5aeced12f4e8781d4ea1f3fae859b49fdae5552362089d645c569d7b3426a68f83f0a5536a6e4d2d583c
7
- data.tar.gz: fc765c52de52976c39215bf5fd712c258a62ba07741735b95b7eb43497809337bcf14ba80b273abc4d02bf97b8a4c76f4389406987411bf145cd320a564ff280
6
+ metadata.gz: 754310e162e9d5716514c9fa0a938b055c53355553433379c7bc5e484933025a22bbc10c3e1a95e4b6f7c2cc524e3178ede1461a20aebe05f572589a23c3d3b7
7
+ data.tar.gz: 0dd64052ec2514532ca7d73828048674f6753317d9da5f6be0b53fb89c93ba8b9abe634d176b85a36f5935210afc8d9d0611d542aa1b2d4f51a6eecee3cf4315
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  /.bundle/
2
2
  /.vagrant/
3
+ /pkg/
3
4
  /Vagrantfile
4
- /vendor
5
+ /vendor/
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'https://rubygems.org/'
2
2
 
3
3
  group :development do
4
+ gem 'fakefs'
4
5
  gem 'rake'
5
6
  gem 'rspec'
6
7
  gem 'rspec-its'
@@ -1,8 +1,8 @@
1
1
  GIT
2
2
  remote: https://github.com/mitchellh/vagrant.git
3
- revision: f31a340499a13868e60b2e4649c13a167a0bf387
3
+ revision: dbba41a7ec3d87830f9b1895266d6a807c1cd2e0
4
4
  specs:
5
- vagrant (2.0.4.dev)
5
+ vagrant (2.1.2.dev)
6
6
  childprocess (~> 0.6.0)
7
7
  erubis (~> 2.7.0)
8
8
  hashicorp-checkpoint (~> 0.1.5)
@@ -16,6 +16,8 @@ GIT
16
16
  rest-client (>= 1.6.0, < 3.0)
17
17
  ruby_dep (<= 1.3.1)
18
18
  wdm (~> 0.1.0)
19
+ win32-file (~> 0.8.1)
20
+ win32-file-security (~> 1.0.10)
19
21
  winrm (~> 2.1)
20
22
  winrm-elevated (~> 1.1)
21
23
  winrm-fs (~> 1.0)
@@ -23,30 +25,32 @@ GIT
23
25
  PATH
24
26
  remote: .
25
27
  specs:
26
- vagrant-lxd (0.2.0)
27
- hyperkit (~> 1.1)
28
+ vagrant-lxd (0.2.1)
29
+ hyperkit (~> 1.1.0)
28
30
 
29
31
  GEM
30
32
  remote: https://rubygems.org/
31
33
  specs:
32
- activesupport (5.2.0)
33
- concurrent-ruby (~> 1.0, >= 1.0.2)
34
- i18n (>= 0.7, < 2)
34
+ activesupport (4.2.10)
35
+ i18n (~> 0.7)
35
36
  minitest (~> 5.1)
37
+ thread_safe (~> 0.3, >= 0.3.4)
36
38
  tzinfo (~> 1.1)
37
39
  addressable (2.5.2)
38
40
  public_suffix (>= 2.0.2, < 4.0)
39
41
  builder (3.2.3)
40
42
  childprocess (0.6.3)
41
43
  ffi (~> 1.0, >= 1.0.11)
42
- concurrent-ruby (1.0.5)
43
44
  diff-lcs (1.3)
44
- domain_name (0.5.20170404)
45
+ domain_name (0.5.20180417)
45
46
  unf (>= 0.0.5, < 1.0.0)
46
47
  erubis (2.7.0)
47
- faraday (0.14.0)
48
+ fakefs (0.14.1)
49
+ faraday (0.15.2)
48
50
  multipart-post (>= 1.2, < 3)
49
51
  ffi (1.9.23)
52
+ ffi-win32-extensions (1.0.3)
53
+ ffi
50
54
  gssapi (1.2.0)
51
55
  ffi (>= 1.0.1)
52
56
  gyoku (1.3.1)
@@ -55,8 +59,8 @@ GEM
55
59
  http-cookie (1.0.3)
56
60
  domain_name (~> 0.5)
57
61
  httpclient (2.8.3)
58
- hyperkit (1.2.0)
59
- activesupport (>= 4.2.6)
62
+ hyperkit (1.1.0)
63
+ activesupport (~> 4.2.6)
60
64
  sawyer
61
65
  i18n (0.8.0)
62
66
  listen (3.1.5)
@@ -121,6 +125,16 @@ GEM
121
125
  unf_ext
122
126
  unf_ext (0.0.7.5)
123
127
  wdm (0.1.1)
128
+ win32-file (0.8.1)
129
+ ffi
130
+ ffi-win32-extensions
131
+ win32-file-stat (>= 1.4.0)
132
+ win32-file-security (1.0.10)
133
+ ffi
134
+ ffi-win32-extensions
135
+ win32-file-stat (1.5.5)
136
+ ffi
137
+ ffi-win32-extensions
124
138
  winrm (2.2.3)
125
139
  builder (>= 2.1.2)
126
140
  erubis (~> 2.7)
@@ -143,6 +157,7 @@ PLATFORMS
143
157
  ruby
144
158
 
145
159
  DEPENDENCIES
160
+ fakefs
146
161
  rake
147
162
  rspec
148
163
  rspec-its
data/Rakefile CHANGED
@@ -1,3 +1,22 @@
1
+ #
2
+ # Copyright (c) 2017-2018 Catalyst.net Ltd
3
+ #
4
+ # This file is part of vagrant-lxd.
5
+ #
6
+ # vagrant-lxd is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or (at
9
+ # your option) any later version.
10
+ #
11
+ # vagrant-lxd is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with vagrant-lxd. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
1
20
  require 'rubygems'
2
21
  require 'bundler/setup'
3
22
  require 'rspec/core/rake_task'
@@ -95,6 +95,35 @@ module VagrantLXD
95
95
  end
96
96
  end
97
97
 
98
+ #
99
+ # Issue a warning when the machine wants synced folders but the host
100
+ # doesn't support it (according to the relevant shadow files).
101
+ #
102
+ class CheckForSyncedFolderSupport
103
+ def initialize(app, env)
104
+ @app = app
105
+ @env = env
106
+ end
107
+
108
+ def call(env)
109
+ enabled_folders = env[:machine].config.vm.synced_folders.reject do |_, options|
110
+ next true if options[:disabled]
111
+ next true unless options[:type].nil? or options[:type] == :lxd
112
+ end
113
+
114
+ if enabled_folders.any? and not env[:host].capability(:synced_folders)
115
+ env[:ui].error 'The host machine does not support LXD synced folders.'
116
+ env[:ui].warn ''
117
+ env[:ui].warn 'To use this feature, you must first configure ID mappings for the'
118
+ env[:ui].warn 'current user in /etc/subuid and /etc/subgid. For more information,'
119
+ env[:ui].warn "refer to `#{File.basename($0)} lxd shadow --help`."
120
+ env[:ui].warn ''
121
+ end
122
+
123
+ @app.call(env)
124
+ end
125
+ end
126
+
98
127
  #
99
128
  # Action definitions.
100
129
  #
@@ -108,6 +137,7 @@ module VagrantLXD
108
137
  when Vagrant::MachineState::NOT_CREATED_ID
109
138
  c.use Message, :info, 'Machine has not been created yet, starting...'
110
139
  c.use HandleBox
140
+ c.use CheckForSyncedFolderSupport
111
141
  c.use LXD.action(:create)
112
142
  c.use LXD.action(:resume)
113
143
  c.use SetHostname
@@ -191,6 +221,7 @@ module VagrantLXD
191
221
  c.use Message, :info, 'Machine is already running.'
192
222
  when :frozen, :stopped
193
223
  c.use Message, :info, 'Resuming machine...'
224
+ c.use CheckForSyncedFolderSupport
194
225
  c.use LXD.action(:resume)
195
226
  c.use SetHostname
196
227
  c.use SyncedFolders
@@ -17,11 +17,26 @@
17
17
  # along with vagrant-lxd. If not, see <http://www.gnu.org/licenses/>.
18
18
  #
19
19
 
20
+ require 'vagrant-lxd/config'
21
+
20
22
  module VagrantLXD
21
23
  class Capability
22
24
  def Capability.snapshot_list(machine)
23
25
  env = machine.action(:snapshot_list)
24
26
  env[:machine_snapshot_list] || []
25
27
  end
28
+
29
+ def Capability.synced_folders(env)
30
+ logger = Log4r::Logger.new('vagrant::lxd::capability')
31
+ logger.debug "Checking synced folders support for effective UID/GID #{Process.uid}/#{Process.gid}..."
32
+ result = %w(uid gid).all? do |type|
33
+ begin
34
+ File.readlines("/etc/sub#{type}").grep(/^root:#{Process.send(type)}:[1-9]/).any?
35
+ rescue StandardError => e
36
+ logger.warn "Cannot read subordinate permissions file: #{e.message}"
37
+ false
38
+ end
39
+ end
40
+ end
26
41
  end
27
42
  end
@@ -37,6 +37,7 @@ module VagrantLXD
37
37
  o.separator 'Commands:'
38
38
  o.separator ' attach associate machine with a running container'
39
39
  o.separator ' detach disassociate machine from a running container'
40
+ o.separator ' shadow print user and group ID mapping information'
40
41
  o.separator ' version print current plugin version'
41
42
  o.separator ''
42
43
  o.separator 'For help on a specific command, run `vagrant lxd <command> -h`'
@@ -52,6 +53,8 @@ module VagrantLXD
52
53
  attach(args)
53
54
  when 'detach'
54
55
  detach(args)
56
+ when 'shadow'
57
+ shadow(args)
55
58
  when 'version'
56
59
  @env.ui.info 'Vagrant LXD Provider'
57
60
  @env.ui.info 'Version ' << Version::VERSION
@@ -153,5 +156,19 @@ module VagrantLXD
153
156
  yield @env.machine(name, :lxd)
154
157
  end
155
158
  end
159
+
160
+ def shadow(args)
161
+ opts = OptionParser.new do |o|
162
+ o.banner = 'Usage: vagrant lxd shadow --help'
163
+ o.separator ''
164
+ o.separator 'Displays information about user and group ID mapping.'
165
+ end
166
+
167
+ if args.include?('-h') or args.include?('--help')
168
+ @env.ui.info I18n.t('vagrant.help.shadow', uid: Process.uid, gid: Process.gid)
169
+ else
170
+ fail Vagrant::Errors::CLIInvalidUsage, help: opts.help
171
+ end
172
+ end
156
173
  end
157
174
  end
@@ -31,6 +31,8 @@ module VagrantLXD
31
31
  attr_accessor :privileged
32
32
  attr_accessor :profiles
33
33
 
34
+ VAGRANT_UID = 1000 # TODO Make this configurable.
35
+
34
36
  def initialize
35
37
  @name = UNSET_VALUE
36
38
  @timeout = UNSET_VALUE
@@ -23,12 +23,13 @@ require 'securerandom'
23
23
  require 'tempfile'
24
24
  require 'timeout'
25
25
  require 'vagrant/machine_state'
26
+ require 'vagrant-lxd/config'
26
27
 
27
28
  module VagrantLXD
28
29
  class Driver
29
30
  include Vagrant::Util
30
31
 
31
- VAGRANT_UID = 1000 # TODO Make this configurable.
32
+ USER_AGENT = "#{Version::DESCRIPTION} #{Version::VERSION} (#{Hyperkit::Default.user_agent})"
32
33
 
33
34
  class OperationTimeout < Vagrant::Errors::VagrantError
34
35
  error_key 'lxd_operation_timeout'
@@ -108,8 +109,8 @@ module VagrantLXD
108
109
  @ephemeral = machine.provider_config.ephemeral
109
110
  @profiles = machine.provider_config.profiles
110
111
  @name = machine.provider_config.name
111
- @logger = Log4r::Logger.new('vagrant::lxd')
112
- @lxd = Hyperkit::Client.new(api_endpoint: api_endpoint.to_s, verify_ssl: false)
112
+ @logger = Log4r::Logger.new('vagrant::lxd::driver')
113
+ @lxd = Hyperkit::Client.new(api_endpoint: api_endpoint.to_s, verify_ssl: false, user_agent: USER_AGENT)
113
114
  end
114
115
 
115
116
  def validate!
@@ -119,8 +120,11 @@ module VagrantLXD
119
120
 
120
121
  def synced_folders_usable?
121
122
  # Check whether we've registered an idmap for the current user.
122
- if map = container[:config][:'raw.idmap']
123
- true if map =~ /^uid #{Process.uid} #{VAGRANT_UID}$/
123
+ raw_idmap = container[:config][:'raw.idmap']
124
+ begin
125
+ raw_idmap and
126
+ raw_idmap =~ /^uid #{Process.uid} #{Config::VAGRANT_UID}$/ and
127
+ raw_idmap =~ /^gid #{Process.gid} #{Config::VAGRANT_UID}$/
124
128
  end
125
129
  rescue Vagrant::Errors::ProviderNotUsable
126
130
  false
@@ -396,19 +400,12 @@ module VagrantLXD
396
400
  # Set "raw.idmap" if the host's sub{u,g}id configuration allows it.
397
401
  # This allows sharing folders via LXD (see synced_folder.rb).
398
402
  # If the user has already specified a 'raw.idmap', leave it alone.
399
- unless config.include?(:'raw.idmap')
400
- begin
401
- # Check for root mappings in /etc/sub{uid,gid}.
402
- %w(uid gid).each do |type|
403
- id = Process.send(type)
404
- if File.readlines("/etc/sub#{type}").grep(/^root:#{id}:[1-9]/).any?
405
- config[:'raw.idmap'] ||= ''
406
- config[:'raw.idmap'] << "#{type} #{id} #{VAGRANT_UID}\n"
407
- end
408
- end
409
- rescue StandardError => e
410
- @logger.warn "Cannot read subordinate permissions file: #{e.message}"
411
- end
403
+ if config.include?(:'raw.idmap')
404
+ # Manually specified, carry on.
405
+ elsif @machine.env.host.capability(:synced_folders)
406
+ config[:'raw.idmap'] = ''
407
+ config[:'raw.idmap'] << "uid #{Process.uid} #{Config::VAGRANT_UID}\n"
408
+ config[:'raw.idmap'] << "gid #{Process.gid} #{Config::VAGRANT_UID}\n"
412
409
  end
413
410
 
414
411
  @logger.debug 'Resulting configuration: ' << config.inspect
@@ -48,5 +48,10 @@ module VagrantLXD
48
48
  require_relative 'capability'
49
49
  Capability
50
50
  end
51
+
52
+ host_capability(:linux, 'synced_folders') do
53
+ require_relative 'capability'
54
+ Capability
55
+ end
51
56
  end
52
57
  end
@@ -20,7 +20,7 @@
20
20
  module VagrantLXD
21
21
  module Version
22
22
  NAME = 'vagrant-lxd'
23
- VERSION = '0.2.0'
23
+ VERSION = '0.2.1'
24
24
  DESCRIPTION = 'Vagrant LXD provider'
25
25
  end
26
26
  end
@@ -16,6 +16,20 @@ en:
16
16
  The machine has no snapshot named '%{name}'.
17
17
  restored: |-
18
18
  The machine has been restored to snapshot '%{name}'!
19
+ help:
20
+ shadow: |-
21
+ In order to use shared folders, you must first add the effective user
22
+ and group ID (which are currently %{uid} and %{gid}) to the host machine's
23
+ subuid(5) and subgid(5) files:
24
+
25
+ $ echo root:%{uid}:1 | sudo tee -a /etc/subuid
26
+ $ echo root:%{gid}:1 | sudo tee -a /etc/subgid
27
+
28
+ For more information about these commands, and user/group ID mapping in
29
+ general, refer to this article:
30
+
31
+ https://insights.ubuntu.com/2017/06/15/custom-user-mappings-in-lxd-containers/
32
+
19
33
  errors:
20
34
  lxd_connection_failure: |-
21
35
  The provider was unable to contact the LXD daemon at %{api_endpoint}.
@@ -35,5 +35,5 @@ Gem::Specification.new do |spec|
35
35
  f.match(%r{^(test|spec|features)/})
36
36
  end
37
37
 
38
- spec.add_runtime_dependency 'hyperkit', '~> 1.1'
38
+ spec.add_runtime_dependency 'hyperkit', '~> 1.1.0'
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-lxd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Hanson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-10 00:00:00.000000000 Z
11
+ date: 2018-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hyperkit
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.1'
19
+ version: 1.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.1'
26
+ version: 1.1.0
27
27
  description: A Vagrant plugin that allows management of containers using LXD.
28
28
  email:
29
29
  - evanh@catalyst.net.nz