vagrant-lxd 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f0c237e8739d6719e33f8029c849927f5650a47
4
- data.tar.gz: 3eb61ce7502ba73752e2e6eb5c86eba965dc5b42
3
+ metadata.gz: 304c1f8ee64a31435d51d95726660fd666f3febd
4
+ data.tar.gz: 46cc574e2ad04aa6604e929c8046e10accabc81c
5
5
  SHA512:
6
- metadata.gz: 6a5a7434615e6a4b6928f3601c2277987ac0e24516b18da7102723059929908b72c30695f21cb4e411877a920bb929cca70744178f5cae0921081dec9689cc49
7
- data.tar.gz: 8ebaad06c6a85d84c5da97d44196558f651a321acc26e049642785a757c0d3f66599d009a82b89ee2aaddbb11752034a45e72f07185d0ffa5d5ec286f397494c
6
+ metadata.gz: e6a49fa60209a54a54ce4de1714281bfc760ad75a80898a34d300e935b35fca7d51397f473229ffc2f037403601a7ccf8dfb583fe88aa8c6d9e32e0bbbd46b4b
7
+ data.tar.gz: ef6b64e67ecbbe673819096205b28bcba675c9162137efd550803810b8d54228fc1ccd49616cdabab705ee89092a2d0b26e91f343a0f3fc875471afe2ee71245
data/.gitlab-ci.yml CHANGED
@@ -3,7 +3,7 @@ image: "ruby:2.3"
3
3
  before_script:
4
4
  - apt-get -y update
5
5
  - apt-get -y upgrade
6
- - gem install bundler --no-ri --no-rdoc
6
+ - gem install bundler
7
7
  - bundle install -j $(nproc) --path vendor/bundle
8
8
 
9
9
  spec:
data/Gemfile.lock CHANGED
@@ -1,6 +1,6 @@
1
1
  GIT
2
2
  remote: https://github.com/mitchellh/vagrant.git
3
- revision: 7927c39da90dae3f5be79e36ad9df3b4ad834ac1
3
+ revision: c6b42a04cd1ca9f0936714ee6a44b4c7c001fdeb
4
4
  specs:
5
5
  vagrant (2.2.4.dev)
6
6
  bcrypt_pbkdf (~> 1.0.0)
@@ -27,7 +27,7 @@ GIT
27
27
  PATH
28
28
  remote: .
29
29
  specs:
30
- vagrant-lxd (0.3.2)
30
+ vagrant-lxd (0.3.3)
31
31
  hyperkit (~> 1.2.0)
32
32
 
33
33
  GEM
@@ -50,7 +50,7 @@ GEM
50
50
  unf (>= 0.0.5, < 1.0.0)
51
51
  ed25519 (1.2.4)
52
52
  erubis (2.7.0)
53
- fakefs (0.18.0)
53
+ fakefs (0.19.1)
54
54
  faraday (0.15.4)
55
55
  multipart-post (>= 1.2, < 3)
56
56
  ffi (1.10.0)
data/README.md CHANGED
@@ -90,7 +90,7 @@ Vagrant.configure('2') do |config|
90
90
  end
91
91
  ```
92
92
 
93
- ### Shared Folders
93
+ ### Synced Folders
94
94
 
95
95
  In order to use shared folders, you must first add your user ID to the
96
96
  host machine's subuid(5) and subgid(5) files:
@@ -115,6 +115,19 @@ the default with the `vagrant_uid` and `vagrant_gid` settings.
115
115
  lxd.vagrand_gid = 1000 # defaults to vagrant_uid
116
116
  end
117
117
 
118
+ #### Disk Device Configuration
119
+
120
+ Synced folders are mounted as [disk devices][disk] within the guest. You
121
+ can configure them by adding settings to folder's `config` hash, which
122
+ is passed through to LXD. The hash values should all be strings:
123
+
124
+ config.vm.synced_folder '/foo', '/bar', config: {
125
+ readonly: 'true',
126
+ recursive: 'false',
127
+ }
128
+
129
+ [disk]: https://lxd.readthedocs.io/en/latest/containers/#type-disk
130
+
118
131
  ### Shared LXD Containers
119
132
 
120
133
  It's possible to share a single LXD container between multiple Vagrant
@@ -140,9 +140,9 @@ module VagrantLXD
140
140
  c.use CheckForSyncedFolderSupport
141
141
  c.use LXD.action(:create)
142
142
  c.use Provision
143
- c.use LXD.action(:resume)
144
143
  c.use SetHostname
145
144
  c.use SyncedFolders
145
+ c.use LXD.action(:resume)
146
146
  c.use WaitForCommunicator
147
147
  when :running
148
148
  c.use Message, :info, 'Machine is already running.'
@@ -224,9 +224,9 @@ module VagrantLXD
224
224
  c.use CheckForSyncedFolderSupport
225
225
  c.use LXD.action(:configure)
226
226
  c.use Provision
227
- c.use LXD.action(:resume)
228
227
  c.use SetHostname
229
228
  c.use SyncedFolders
229
+ c.use LXD.action(:resume)
230
230
  c.use WaitForCommunicator
231
231
  else
232
232
  c.use Message, :error, "Machine cannot be resumed while #{env[:machine_state]}."
@@ -80,6 +80,14 @@ module VagrantLXD
80
80
  error_key 'lxd_duplicate_attachment_failure'
81
81
  end
82
82
 
83
+ class DiskMountFailure < Vagrant::Errors::VagrantError
84
+ error_key 'lxd_disk_mount_failure'
85
+ end
86
+
87
+ class DiskUnmountFailure < Vagrant::Errors::VagrantError
88
+ error_key 'lxd_disk_unmount_failure'
89
+ end
90
+
83
91
  class SnapshotNotFound < Vagrant::Errors::VagrantError
84
92
  error_key 'snapshot_not_found'
85
93
  end
@@ -150,9 +158,12 @@ module VagrantLXD
150
158
  def mount(name, options)
151
159
  container = @lxd.container(machine_id)
152
160
  devices = container[:devices].to_hash
153
- devices[name] = { type: 'disk', path: options[:guestpath], source: options[:hostpath] }
161
+ devices[name] = { type: 'disk', path: options[:guestpath], source: options[:hostpath] }.merge(options[:config])
154
162
  container[:devices] = devices
155
163
  @lxd.update_container(machine_id, container)
164
+ rescue Hyperkit::BadRequest => e
165
+ @machine.ui.error 'Failed to mount synced folder'
166
+ fail DiskMountFailure, machine_name: @machine.name, guestpath: options[:guestpath], reason: e.reason
156
167
  end
157
168
 
158
169
  def mounted?(name, options)
@@ -173,6 +184,9 @@ module VagrantLXD
173
184
  devices.delete(name.to_sym)
174
185
  container[:devices] = devices
175
186
  @lxd.update_container(machine_id, container)
187
+ rescue Hyperkit::BadRequest => e
188
+ @machine.ui.error 'Failed to unmount synced folder'
189
+ fail DiskUnmountFailure, machine_name: @machine.name, guestpath: options[:guestpath], reason: e.reason
176
190
  end
177
191
 
178
192
  def attach(container)
@@ -38,6 +38,8 @@ module VagrantLXD
38
38
 
39
39
  # TODO Figure out the proper way to mount folders before
40
40
  # provisioning without using `#prepare` (which is deprecated).
41
+ # TODO Umount existing devices if they go missing from the
42
+ # Vagrantfile (either via deletion or setting disabled: true).
41
43
  def prepare(machine, folders, opts)
42
44
  enable(machine, folders, opts)
43
45
  end
@@ -52,10 +54,22 @@ module VagrantLXD
52
54
  @driver.mounted?(name, folder)
53
55
  end
54
56
 
57
+ # Sanity check folder configs and bail if something's wrong.
58
+ folders.each do |name, folder|
59
+ validate_folder(folder)
60
+ end
61
+
62
+ # Ensure all folders have a config hash.
63
+ folders.each do |name, folder|
64
+ folder[:config] ||= {}
65
+ folder[:config] = Hash[folder[:config].map { |k, v| [k.to_sym, v.to_s] }]
66
+ end
67
+
55
68
  if folders.any?
56
69
  machine.ui.info 'Mounting shared folders...'
57
70
  folders.reject { |_, f| f[:disabled] }.each do |name, folder|
58
- machine.ui.detail "#{folder[:guestpath]} => #{folder[:hostpath]}"
71
+ details = config_summary(folder[:config])
72
+ machine.ui.detail "#{folder[:guestpath]} => #{folder[:hostpath]} #{details}".strip
59
73
  @driver.mount(name, folder)
60
74
  end
61
75
  end
@@ -72,5 +86,29 @@ module VagrantLXD
72
86
  end
73
87
  end
74
88
  end
89
+
90
+ protected
91
+
92
+ def validate_folder(folder)
93
+ config = folder.fetch(:config) { Hash.new }
94
+
95
+ unless config.is_a? Hash
96
+ fail Vagrant::Errors::ConfigInvalid, errors: "Invalid synced_folder `config' (value must be a hash)"
97
+ end
98
+
99
+ unless config.keys.all? { |x| x.is_a? String or x.is_a? Symbol }
100
+ fail Vagrant::Errors::ConfigInvalid, errors: "Invalid synced_folder `config' (hash keys must be strings)"
101
+ end
102
+
103
+ unless config.values.all? { |x| x.is_a? String or x == true or x == false }
104
+ fail Vagrant::Errors::ConfigInvalid, errors: "Invalid synced_folder `config' (hash values must be strings)"
105
+ end
106
+ end
107
+
108
+ def config_summary(config)
109
+ if config.is_a? Hash and config.any?
110
+ "(#{config.map { |k, v| "#{k}=#{v.inspect}" }.join(', ')})"
111
+ end
112
+ end
75
113
  end
76
114
  end
@@ -20,7 +20,7 @@
20
20
  module VagrantLXD
21
21
  module Version
22
22
  NAME = 'vagrant-lxd'
23
- VERSION = '0.3.2'
23
+ VERSION = '0.3.3'
24
24
  DESCRIPTION = 'Vagrant LXD provider'
25
25
  end
26
26
  end
@@ -110,6 +110,20 @@ en:
110
110
 
111
111
  The LXD logs may contain more information about the cause of this failure.
112
112
 
113
+ lxd_disk_mount_failure: |-
114
+ The provider was unable to mount a disk device at %{guestpath} for the '%{machine_name}' VM.
115
+
116
+ The underlying error message was: %{reason}
117
+
118
+ The LXD logs may contain more information about the cause of this failure.
119
+
120
+ lxd_disk_unmount_failure: |-
121
+ The provider was unable to unmount a disk device at %{guestpath} for the '%{machine_name}' VM.
122
+
123
+ The underlying error message was: %{reason}
124
+
125
+ The LXD logs may contain more information about the cause of this failure.
126
+
113
127
  lxd_image_creation_failure: |-
114
128
  The provider was unable to create an LXD image for the '%{machine_name}' VM.
115
129
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-lxd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Hanson