vagrant-lxd 0.4.3 → 0.4.4

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: 6c4e09ae9c1b8bd49ad70106106a70bd6c1b6a82eb50a002e606603ba278d120
4
- data.tar.gz: 3be761524f420eb75a04ab3a3c1043ca109a89ae4108e345bc22b5d7bd8cfbc6
3
+ metadata.gz: 81d3c5f71aaa0fb4f5fd3128722bf0d045619f7b56f2f6056f87ab396548d18f
4
+ data.tar.gz: 966e0817b7bb8fd94b7a865e2799b468a92b4522de5218a088e7502f75d218be
5
5
  SHA512:
6
- metadata.gz: 79518954226df0b863a3108c6f8fbb360549ce53b7577ad9d07c24d94c67ae5005bc8053d04fe3344de3b8d21ad0447244d253e1190757f1b8d3a8304b226cbf
7
- data.tar.gz: ddc249f6db94da9a27add204ad36549d4171d303a7c189c530df5d8163437d3807652924f77398f9c36e8814b94d64bf7f1c3951e8659d17a5a55ded84e15559
6
+ metadata.gz: f222d710cf807b6cbba3a5aae4dc0fb69df34c4a6d7112ef2df727f9218fd5296d8d3ed0a17fcecd8c68e3243bc982ea82a2fcdfedeb0932257bd7f08f940a9d
7
+ data.tar.gz: 9a0c720fd7130f77bf60663b5e1d7c2f8bc4da4bf74683214e3b4ec1e632334f704085053ae3e564d0cc967a6861d2b7597443fed20be33d8fad38cf13e49445
@@ -27,20 +27,21 @@ GIT
27
27
  PATH
28
28
  remote: .
29
29
  specs:
30
- vagrant-lxd (0.4.3)
30
+ vagrant-lxd (0.4.4)
31
31
  activesupport (~> 5.2.3)
32
+ faraday (~> 0.17)
32
33
  hyperkit (~> 1.2.0)
33
34
 
34
35
  GEM
35
36
  remote: https://rubygems.org/
36
37
  specs:
37
- activesupport (5.2.3)
38
+ activesupport (5.2.4.1)
38
39
  concurrent-ruby (~> 1.0, >= 1.0.2)
39
40
  i18n (>= 0.7, < 2)
40
41
  minitest (~> 5.1)
41
42
  tzinfo (~> 1.1)
42
- addressable (2.6.0)
43
- public_suffix (>= 2.0.2, < 4.0)
43
+ addressable (2.7.0)
44
+ public_suffix (>= 2.0.2, < 5.0)
44
45
  bcrypt_pbkdf (1.0.1)
45
46
  builder (3.2.3)
46
47
  childprocess (0.6.3)
@@ -52,7 +53,7 @@ GEM
52
53
  ed25519 (1.2.4)
53
54
  erubis (2.7.0)
54
55
  fakefs (0.20.1)
55
- faraday (0.15.4)
56
+ faraday (0.17.3)
56
57
  multipart-post (>= 1.2, < 3)
57
58
  ffi (1.11.1)
58
59
  gssapi (1.3.0)
@@ -80,7 +81,7 @@ GEM
80
81
  mime-types (3.2.2)
81
82
  mime-types-data (~> 3.2015)
82
83
  mime-types-data (3.2019.0331)
83
- minitest (5.11.3)
84
+ minitest (5.13.0)
84
85
  multi_json (1.13.1)
85
86
  multipart-post (2.1.1)
86
87
  net-scp (1.2.1)
@@ -90,7 +91,7 @@ GEM
90
91
  net-ssh (5.1.0)
91
92
  netrc (0.11.0)
92
93
  nori (2.6.0)
93
- public_suffix (3.1.1)
94
+ public_suffix (4.0.3)
94
95
  rake (12.3.3)
95
96
  rb-fsevent (0.10.3)
96
97
  rb-inotify (0.10.0)
@@ -124,7 +125,7 @@ GEM
124
125
  addressable (>= 2.3.5)
125
126
  faraday (> 0.8, < 2.0)
126
127
  thread_safe (0.3.6)
127
- tzinfo (1.2.5)
128
+ tzinfo (1.2.6)
128
129
  thread_safe (~> 0.1)
129
130
  unf (0.1.4)
130
131
  unf_ext
data/README.md CHANGED
@@ -13,7 +13,8 @@ The following features are currently supported:
13
13
  - VM management (create, suspend, destroy, etc.)
14
14
  - IPv4 networking
15
15
  - Synced folders
16
- - Snapshots
16
+ - Snapshots (via `vagrant snapshot`)
17
+ - Box Packaging (via `vagrant package`)
17
18
 
18
19
  The following features are not expected to work yet:
19
20
 
@@ -124,6 +124,20 @@ module VagrantLXD
124
124
  end
125
125
  end
126
126
 
127
+ class Package
128
+ def initialize(app, env)
129
+ @app = app
130
+ @env = env
131
+ end
132
+
133
+ def call(env)
134
+ env['package.directory'] = env[:machine_package]
135
+ @app.call(env)
136
+ ensure
137
+ FileUtils.rm_rf(env[:machine_package])
138
+ end
139
+ end
140
+
127
141
  #
128
142
  # Action definitions.
129
143
  #
@@ -335,6 +349,24 @@ module VagrantLXD
335
349
  builder { |b| b.use SSHRun }
336
350
  end
337
351
 
352
+ def package
353
+ builder do |b|
354
+ b.use Call, state do |env, c|
355
+ case env[:machine_state]
356
+ when Vagrant::MachineState::NOT_CREATED_ID
357
+ next
358
+ when :frozen, :running
359
+ c.use halt
360
+ end
361
+
362
+ c.use Message, :info, 'Packaging machine...'
363
+ c.use LXD.action(:package)
364
+ c.use Package
365
+ c.use Vagrant::Action::General::Package
366
+ end
367
+ end
368
+ end
369
+
338
370
  private
339
371
 
340
372
  def builder
@@ -71,6 +71,10 @@ module VagrantLXD
71
71
  error_key 'lxd_image_creation_failure'
72
72
  end
73
73
 
74
+ class ImageExportFailure < Vagrant::Errors::VagrantError
75
+ error_key 'lxd_image_export_failure'
76
+ end
77
+
74
78
  class ContainerNotFound < Vagrant::Errors::VagrantError
75
79
  error_key 'lxd_container_not_found'
76
80
  end
@@ -343,6 +347,14 @@ module VagrantLXD
343
347
  end
344
348
  end
345
349
 
350
+ def package
351
+ if in_state? :stopped
352
+ create_package_directory
353
+ else
354
+ @logger.debug "Skipped packaging (#{machine_id} is not stopped)"
355
+ end
356
+ end
357
+
346
358
  def configure
347
359
  container = lxd.container(machine_id)
348
360
  container[:config] = container[:config].to_hash.merge(config)
@@ -602,6 +614,42 @@ module VagrantLXD
602
614
  FileUtils.rm_rf(tmpdir)
603
615
  end
604
616
 
617
+ # TODO s.a.
618
+ def create_package_directory
619
+ package_directory = Dir.mktmpdir
620
+
621
+ image = begin
622
+ lxd.create_image_from_container(machine_id, IMAGE_PROPERTIES)
623
+ rescue Hyperkit::BadRequest => e
624
+ if e.reason =~ /The image already exists: (\h{64})/
625
+ {
626
+ metadata: { fingerprint: $1 }
627
+ }
628
+ else
629
+ fail ImageExportFailure, machine_name: @machine.name, reason: e.reason
630
+ end
631
+ end
632
+
633
+ lxd.export_image(image[:metadata][:fingerprint], package_directory, filename: 'rootfs.tar.gz')
634
+
635
+ File.open(File.join(package_directory, 'metadata.json'), 'w') do |metadata|
636
+ metadata.puts JSON.pretty_generate({
637
+ 'provider' => 'lxc',
638
+ 'version' => '1.0.0',
639
+ 'built-on' => Time.now.strftime("%a %m %d %H:%M:%S %z %Y"),
640
+ })
641
+ end
642
+ rescue Exception => e
643
+ @machine.ui.error 'Failed to export container image'
644
+ @logger.error 'Error preparing container image: ' << e.message << "\n" << e.backtrace.join("\n")
645
+ fail ImageExportFailure, machine_name: @machine.name, reason: e.message
646
+ else
647
+ package_directory
648
+ ensure
649
+ # If the image was created just for this package, remove it.
650
+ lxd.delete_image(image[:metadata][:fingerprint]) rescue nil if image.is_a? Sawyer::Resource
651
+ end
652
+
605
653
  def error(klass)
606
654
  klass.new(
607
655
  provider: Version::NAME,
@@ -20,7 +20,7 @@
20
20
  module VagrantLXD
21
21
  module Version
22
22
  NAME = 'vagrant-lxd'
23
- VERSION = '0.4.3'
23
+ VERSION = '0.4.4'
24
24
  DESCRIPTION = 'Vagrant LXD provider'
25
25
  end
26
26
  end
@@ -134,6 +134,13 @@ en:
134
134
 
135
135
  https://gitlab.com/catalyst-it/vagrant-lxd/issues
136
136
 
137
+ lxd_image_export_failure: |-
138
+ The provider was unable to export a container image for '%{machine_name}'.
139
+
140
+ The underlying error message was: %{reason}
141
+
142
+ The LXD logs may contain more information about the cause of this failure.
143
+
137
144
  lxd_duplicate_attachment_failure: |-
138
145
  A machine can only be associated with one container at a time.
139
146
 
@@ -37,4 +37,8 @@ Gem::Specification.new do |spec|
37
37
 
38
38
  spec.add_runtime_dependency 'activesupport', '~> 5.2.3'
39
39
  spec.add_runtime_dependency 'hyperkit', '~> 1.2.0'
40
+
41
+ # NOTE fixed to preserve ruby 1.x compatibility, versions after 1.0
42
+ # use the safe navigation operator and thus need ruby 2.3 or newer
43
+ spec.add_runtime_dependency 'faraday', '~> 0.17'
40
44
  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.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Hanson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-21 00:00:00.000000000 Z
11
+ date: 2020-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.17'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.17'
41
55
  description: A Vagrant plugin that allows management of containers using LXD.
42
56
  email:
43
57
  - evanh@catalyst.net.nz
@@ -85,7 +99,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
99
  - !ruby/object:Gem::Version
86
100
  version: '0'
87
101
  requirements: []
88
- rubygems_version: 3.0.3
102
+ rubyforge_project:
103
+ rubygems_version: 2.7.6
89
104
  signing_key:
90
105
  specification_version: 4
91
106
  summary: Vagrant LXD provider