vagrant-lxd 0.7.0 → 0.7.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
  SHA256:
3
- metadata.gz: a5c54e824e6ddcb541c28c0630b0d93bf019b3e4adc3d78c8353b80d677f29b4
4
- data.tar.gz: 95548bc78e3df80c016ed817210cc05c12b664a7fbb043a600a1c3a7420e22e1
3
+ metadata.gz: 9f0f075e1a4c96070a15ebb90aff04e8d7d4f256f7b5d8c8494390b2826ac729
4
+ data.tar.gz: 22ad9d6af3b0a06a88c331907b3ba62491c593627773491bcc82c95d7cad9138
5
5
  SHA512:
6
- metadata.gz: 8ff4335dfb7edb5bf3995b9f1c71ade7044a0277b4346978958775c99402ac0b0db74ba8cd586d1464408ae09c544a68b773761b29789dfb084402ac36534c1c
7
- data.tar.gz: 7d7ce503fb62c834911d3647b88e1b4c6cb0434532432fb1d1c055aa62ffee4ff493eb0c2561046ac243ac0949cdde57b0cb2b73c9c8bf1f85a887f0ad53808c
6
+ metadata.gz: 94ce807ed3c17ae49232dc19800a9f555251914fa3651b8d2b6f19941c52524a79f2042f3dbcbd4a73f0fbcfdadcdfd3e14449828582eac1cac38eb15175c759
7
+ data.tar.gz: 424cf1cbc62ea73dc806cafb32d8a2b758eb58d49a918823cf5f98f1819a82b97fe74de6c7b741a278710d923f5098132fa66f3eba456a14b08704d7c9586e08
data/Gemfile.lock CHANGED
@@ -33,7 +33,7 @@ GIT
33
33
  PATH
34
34
  remote: .
35
35
  specs:
36
- vagrant-lxd (0.7.0)
36
+ vagrant-lxd (0.7.1)
37
37
  activesupport (~> 5.2.3)
38
38
  faraday (~> 0.17)
39
39
  hyperkit (~> 1.3.0)
@@ -57,5 +57,10 @@ module VagrantLXD
57
57
  end
58
58
  end
59
59
  end
60
+
61
+ # TODO Install the minimal set of packages to allow for Vagrant to
62
+ # connect to a Debian-based guest.
63
+ def Capability.debian_guest(machine)
64
+ end
60
65
  end
61
66
  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 ' exec execute a command within a running container'
40
41
  o.separator ' shadow print user and group ID mapping information'
41
42
  o.separator ' version print current plugin version'
42
43
  o.separator ''
@@ -53,6 +54,8 @@ module VagrantLXD
53
54
  attach(args)
54
55
  when 'detach'
55
56
  detach(args)
57
+ when 'exec'
58
+ exec(args)
56
59
  when 'shadow'
57
60
  shadow(args)
58
61
  when 'version'
@@ -164,6 +167,45 @@ module VagrantLXD
164
167
  end
165
168
  end
166
169
 
170
+ def exec(args)
171
+ opts = OptionParser.new do |o|
172
+ o.banner = 'Usage: vagrant lxd exec [machine ...] -- <command> [args ...]'
173
+ o.separator ''
174
+ o.separator 'Executes a command on the target LXD container(s). Vagrant'
175
+ o.separator 'will wait until each command completes before printing its'
176
+ o.separator 'output and proceeding to the next machine.'
177
+ end
178
+
179
+ if args.include?('-h') or args.include?('--help')
180
+ @env.ui.info opts.help
181
+ exit 0
182
+ end
183
+
184
+ unless dashes = args.index('--')
185
+ fail Vagrant::Errors::CLIInvalidUsage, help: opts.help
186
+ end
187
+
188
+ machines = args.take(dashes)
189
+ command = args.drop(dashes + 1)
190
+ status = 0
191
+
192
+ with_target_machines(machines) do |machine|
193
+ if machine.id.nil? or machine.state.id != :running
194
+ machine.ui.warn 'Machine is not running, skipping...'
195
+ else
196
+ result = Driver.new(machine).exec(command)
197
+ stdout = result.output[:'1']
198
+ stderr = result.output[:'2']
199
+ status = status unless status.zero?
200
+ machine.ui.info "Running command `#{command.shelljoin}`..."
201
+ machine.ui.detail stdout.chomp unless stdout.empty?
202
+ machine.ui.error stderr.chomp unless stderr.empty?
203
+ end
204
+ end
205
+
206
+ exit status
207
+ end
208
+
167
209
  def shadow(args)
168
210
  opts = OptionParser.new do |o|
169
211
  o.banner = 'Usage: vagrant lxd shadow --help'
@@ -24,6 +24,7 @@ module VagrantLXD
24
24
  class Config < Vagrant.plugin('2', :config)
25
25
  attr_accessor :api_endpoint
26
26
  attr_accessor :name
27
+ attr_accessor :image
27
28
  attr_accessor :timeout
28
29
  attr_accessor :config
29
30
  attr_accessor :devices
@@ -40,6 +41,7 @@ module VagrantLXD
40
41
 
41
42
  def initialize
42
43
  @name = UNSET_VALUE
44
+ @image = UNSET_VALUE
43
45
  @timeout = UNSET_VALUE
44
46
  @config = UNSET_VALUE
45
47
  @devices = UNSET_VALUE
@@ -69,6 +71,10 @@ module VagrantLXD
69
71
  end
70
72
  end
71
73
 
74
+ unless image.nil? or image.is_a? String
75
+ errors << "Invalid `image' (value must be a string): #{image.inspect}"
76
+ end
77
+
72
78
  if not timeout.is_a? Integer
73
79
  errors << "Invalid `timeout' (value must be an integer): #{timeout.inspect}"
74
80
  elsif timeout < 1
@@ -167,6 +173,10 @@ module VagrantLXD
167
173
  @name = nil
168
174
  end
169
175
 
176
+ if image == UNSET_VALUE
177
+ @image = nil
178
+ end
179
+
170
180
  if config == UNSET_VALUE
171
181
  @config = {}
172
182
  end
@@ -164,6 +164,7 @@ module VagrantLXD
164
164
 
165
165
  def initialize(machine)
166
166
  @machine = machine
167
+ @image = machine.provider_config.image
167
168
  @timeout = machine.provider_config.timeout
168
169
  @api_endpoint = machine.provider_config.api_endpoint
169
170
  @config = machine.provider_config.config
@@ -286,34 +287,15 @@ module VagrantLXD
286
287
 
287
288
  def create
288
289
  if in_state? NOT_CREATED
289
- image, container = nil, nil
290
+ fingerprint = image_from_box
290
291
  machine_id = generate_machine_id
291
- file, fingerprint = Driver.synchronize { prepare_image_file }
292
-
293
- Driver.synchronize do
294
- begin
295
- image = lxd.image(fingerprint)
296
- @logger.debug 'Using image: ' << image.inspect
297
- rescue Hyperkit::NotFound
298
- image = lxd.create_image_from_file(file)
299
- @logger.debug 'Created image: ' << image.inspect
300
- begin
301
- lxd.update_image(fingerprint, properties: IMAGE_PROPERTIES)
302
- lxd.create_image_alias(fingerprint, machine_id, IMAGE_PROPERTIES)
303
- rescue Hyperkit::Error
304
- @logger.error 'Failed to set description for image: ' << e.reason
305
- end
306
- end
307
- end
308
-
309
292
  container = lxd.create_container(machine_id, devices: devices, ephemeral: ephemeral, fingerprint: fingerprint, config: config, profiles: profiles)
310
293
  @logger.debug 'Created container: ' << container.inspect
311
-
312
294
  @machine.id = machine_id
313
295
  end
314
296
  rescue Hyperkit::Error => e
315
297
  lxd.delete_container(machine_id) rescue nil unless container.nil?
316
- lxd.delete_image(image[:metadata][:fingerprint]) rescue nil unless image.nil?
298
+ lxd.delete_image(fingerprint) rescue nil unless fingerprint.nil?
317
299
  if e.reason =~ /Container '([^']+)' already exists/
318
300
  @machine.ui.error e.reason
319
301
  fail ContainerAlreadyExists, machine_name: @machine.name, container: $1
@@ -413,6 +395,14 @@ module VagrantLXD
413
395
  fail ContainerConfigurationFailure, machine_name: @machine.name, reason: e.reason
414
396
  end
415
397
 
398
+ def exec(command)
399
+ operation = lxd.execute_command(machine_id, command, sync: false, record_output: true)
400
+ wait_for_operation(operation).metadata.tap do |result|
401
+ result.output[:'1'] = lxd.get(result.output[:'1'])
402
+ result.output[:'2'] = lxd.get(result.output[:'2'])
403
+ end
404
+ end
405
+
416
406
  def info
417
407
  if in_state? :running, :frozen
418
408
  {
@@ -478,8 +468,9 @@ module VagrantLXD
478
468
  # is enabled or setting sync: true. TODO Upstream a better fix than
479
469
  # this, so that `wait_for_operation` really does.
480
470
  def wait_for_operation(operation)
471
+ @logger.debug 'Waiting for operation: ' << operation.inspect
481
472
  lxd.wait_for_operation(operation.id)
482
- rescue Faraday::TimeoutError
473
+ rescue Net::ReadTimeout, Faraday::TimeoutError
483
474
  retry
484
475
  end
485
476
 
@@ -607,7 +598,28 @@ module VagrantLXD
607
598
  fail CertificateGenerationFailure, reason: e.message, api_endpoint: @api_endpoint.to_s, default_path: default_path, vagrant_path: vagrant_path
608
599
  end
609
600
 
610
- # TODO Image handling should be moved into its own class.
601
+ def image_from_box
602
+ file, fingerprint = Driver.synchronize { prepare_image_file }
603
+
604
+ Driver.synchronize do
605
+ begin
606
+ image = lxd.image(fingerprint)
607
+ @logger.debug 'Using image: ' << image.inspect
608
+ rescue Hyperkit::NotFound
609
+ image = lxd.create_image_from_file(file)
610
+ @logger.debug 'Created image: ' << image.inspect
611
+ begin
612
+ lxd.update_image(fingerprint, properties: IMAGE_PROPERTIES)
613
+ lxd.create_image_alias(fingerprint, machine_id, IMAGE_PROPERTIES)
614
+ rescue Hyperkit::Error => e
615
+ @logger.error 'Failed to set description for image: ' << e.reason
616
+ end
617
+ end
618
+ end
619
+
620
+ fingerprint
621
+ end
622
+
611
623
  def prepare_image_file
612
624
  tmpdir = Dir.mktmpdir
613
625
 
@@ -664,7 +676,8 @@ module VagrantLXD
664
676
  package_directory = Dir.mktmpdir
665
677
 
666
678
  image = begin
667
- lxd.create_image_from_container(machine_id, IMAGE_PROPERTIES)
679
+ operation = lxd.create_image_from_container(machine_id, properties: IMAGE_PROPERTIES, sync: false)
680
+ wait_for_operation(operation)
668
681
  rescue Hyperkit::BadRequest => e
669
682
  if e.reason =~ /The image already exists: (\h{64})/
670
683
  {
@@ -49,6 +49,11 @@ module VagrantLXD
49
49
  Capability
50
50
  end
51
51
 
52
+ guest_capability(:debian, 'debian_guest') do
53
+ require_relative 'capability'
54
+ Capability
55
+ end
56
+
52
57
  host_capability(:linux, 'synced_folders') do
53
58
  require_relative 'capability'
54
59
  Capability
@@ -20,7 +20,7 @@
20
20
  module VagrantLXD
21
21
  module Version
22
22
  NAME = 'vagrant-lxd'
23
- VERSION = '0.7.0'
23
+ VERSION = '0.7.1'
24
24
  DESCRIPTION = 'Vagrant LXD provider'
25
25
  end
26
26
  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.7.0
4
+ version: 0.7.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: 2023-11-01 00:00:00.000000000 Z
11
+ date: 2023-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport