vagrant-lxd 0.4.3 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.gitlab-ci.yml +1 -1
- data/Gemfile +2 -1
- data/Gemfile.lock +69 -66
- data/README.md +4 -3
- data/doc/setting-up-lxd.md +42 -2
- data/lib/vagrant-lxd/action.rb +32 -0
- data/lib/vagrant-lxd/capability.rb +21 -2
- data/lib/vagrant-lxd/driver.rb +71 -16
- data/lib/vagrant-lxd/driver/certificate.rb +5 -2
- data/lib/vagrant-lxd/synced_folder.rb +1 -0
- data/lib/vagrant-lxd/version.rb +1 -1
- data/templates/locales/en.yml +7 -0
- data/vagrant-lxd.gemspec +5 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5d2a6ff5340ba242bdcc464893541745d00f1ad92dd947e87097c14335a4704
|
4
|
+
data.tar.gz: b52fc2232901b1c49c95b71d28d60b514cafa19dc0ff3698b80710ca55e16aed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a8269778bebfd757d6511668a6de1a30f19adaadffc124f0efc889bbea18eac796397857cdf67cbe72fe6cc733a6a94e4b6edbd568b5820861dba22b5466abd
|
7
|
+
data.tar.gz: 137bf5106e33b466b58a85484079efe7214116f4698c11acbc1c5c08292197e51dafd0b51fb2d63431369a4d923394b4461241afa43dc5c767dccf05ab81ec3c
|
data/.gitignore
CHANGED
data/.gitlab-ci.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
source 'https://rubygems.org/'
|
2
2
|
|
3
3
|
group :development do
|
4
|
+
require 'pp' # avoid superclass mismatch error
|
4
5
|
gem 'fakefs'
|
5
6
|
gem 'rake'
|
6
7
|
gem 'rspec'
|
7
8
|
gem 'rspec-its'
|
8
9
|
gem 'rspec-mocks'
|
9
|
-
gem 'vagrant', :
|
10
|
+
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
|
10
11
|
end
|
11
12
|
|
12
13
|
group :plugins do
|
data/Gemfile.lock
CHANGED
@@ -1,60 +1,62 @@
|
|
1
1
|
GIT
|
2
2
|
remote: https://github.com/mitchellh/vagrant.git
|
3
|
-
revision:
|
3
|
+
revision: 2063111ab5cfcce0f6b2dbcecd9d24d47b512a96
|
4
4
|
specs:
|
5
|
-
vagrant (2.2.
|
5
|
+
vagrant (2.2.10.dev)
|
6
6
|
bcrypt_pbkdf (~> 1.0.0)
|
7
|
-
childprocess (~> 0.
|
7
|
+
childprocess (~> 4.0.0)
|
8
8
|
ed25519 (~> 1.2.4)
|
9
9
|
erubis (~> 2.7.0)
|
10
10
|
hashicorp-checkpoint (~> 0.1.5)
|
11
|
-
i18n (~> 1.
|
12
|
-
listen (~> 3.1
|
11
|
+
i18n (~> 1.8)
|
12
|
+
listen (~> 3.1)
|
13
13
|
log4r (~> 1.1.9, < 1.1.11)
|
14
|
+
mime (~> 0.4.4)
|
14
15
|
net-scp (~> 1.2.0)
|
15
|
-
net-sftp (~>
|
16
|
-
net-ssh (~>
|
16
|
+
net-sftp (~> 3.0)
|
17
|
+
net-ssh (~> 6.0)
|
17
18
|
rb-kqueue (~> 0.2.0)
|
18
19
|
rest-client (>= 1.6.0, < 3.0)
|
19
20
|
ruby_dep (<= 1.3.1)
|
20
|
-
rubyzip (~>
|
21
|
-
vagrant_cloud (~> 2.0.
|
21
|
+
rubyzip (~> 2.0)
|
22
|
+
vagrant_cloud (~> 2.0.3)
|
22
23
|
wdm (~> 0.1.0)
|
23
|
-
winrm (
|
24
|
-
winrm-elevated (
|
25
|
-
winrm-fs (
|
24
|
+
winrm (>= 2.3.4, < 3.0)
|
25
|
+
winrm-elevated (>= 1.2.1, < 2.0)
|
26
|
+
winrm-fs (>= 1.3.4, < 2.0)
|
26
27
|
|
27
28
|
PATH
|
28
29
|
remote: .
|
29
30
|
specs:
|
30
|
-
vagrant-lxd (0.
|
31
|
+
vagrant-lxd (0.5.2)
|
31
32
|
activesupport (~> 5.2.3)
|
32
|
-
|
33
|
+
faraday (~> 0.17)
|
34
|
+
hyperkit (~> 1.3.0)
|
33
35
|
|
34
36
|
GEM
|
35
37
|
remote: https://rubygems.org/
|
36
38
|
specs:
|
37
|
-
activesupport (5.2.
|
39
|
+
activesupport (5.2.4.4)
|
38
40
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
39
41
|
i18n (>= 0.7, < 2)
|
40
42
|
minitest (~> 5.1)
|
41
43
|
tzinfo (~> 1.1)
|
42
|
-
addressable (2.
|
43
|
-
public_suffix (>= 2.0.2, <
|
44
|
+
addressable (2.7.0)
|
45
|
+
public_suffix (>= 2.0.2, < 5.0)
|
44
46
|
bcrypt_pbkdf (1.0.1)
|
45
|
-
builder (3.2.
|
46
|
-
childprocess (0.
|
47
|
-
|
48
|
-
|
49
|
-
diff-lcs (1.3)
|
47
|
+
builder (3.2.4)
|
48
|
+
childprocess (4.0.0)
|
49
|
+
concurrent-ruby (1.1.7)
|
50
|
+
diff-lcs (1.4.4)
|
50
51
|
domain_name (0.5.20190701)
|
51
52
|
unf (>= 0.0.5, < 1.0.0)
|
52
53
|
ed25519 (1.2.4)
|
54
|
+
erubi (1.9.0)
|
53
55
|
erubis (2.7.0)
|
54
|
-
fakefs (
|
55
|
-
faraday (0.
|
56
|
+
fakefs (1.2.2)
|
57
|
+
faraday (0.17.3)
|
56
58
|
multipart-post (>= 1.2, < 3)
|
57
|
-
ffi (1.
|
59
|
+
ffi (1.13.1)
|
58
60
|
gssapi (1.3.0)
|
59
61
|
ffi (>= 1.0.1)
|
60
62
|
gyoku (1.3.1)
|
@@ -63,37 +65,37 @@ GEM
|
|
63
65
|
http-cookie (1.0.3)
|
64
66
|
domain_name (~> 0.5)
|
65
67
|
httpclient (2.8.3)
|
66
|
-
hyperkit (1.
|
68
|
+
hyperkit (1.3.0)
|
67
69
|
activesupport (>= 4.2.6)
|
68
70
|
sawyer
|
69
|
-
i18n (1.
|
71
|
+
i18n (1.8.5)
|
70
72
|
concurrent-ruby (~> 1.0)
|
71
|
-
listen (3.1
|
72
|
-
rb-fsevent (~> 0.
|
73
|
-
rb-inotify (~> 0.9, >= 0.9.
|
74
|
-
ruby_dep (~> 1.2)
|
73
|
+
listen (3.2.1)
|
74
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
75
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
75
76
|
little-plugger (1.1.4)
|
76
77
|
log4r (1.1.10)
|
77
|
-
logging (2.
|
78
|
+
logging (2.3.0)
|
78
79
|
little-plugger (~> 1.1)
|
79
|
-
multi_json (~> 1.
|
80
|
-
mime
|
80
|
+
multi_json (~> 1.14)
|
81
|
+
mime (0.4.4)
|
82
|
+
mime-types (3.3.1)
|
81
83
|
mime-types-data (~> 3.2015)
|
82
|
-
mime-types-data (3.
|
83
|
-
minitest (5.
|
84
|
-
multi_json (1.
|
84
|
+
mime-types-data (3.2020.0512)
|
85
|
+
minitest (5.14.2)
|
86
|
+
multi_json (1.15.0)
|
85
87
|
multipart-post (2.1.1)
|
86
88
|
net-scp (1.2.1)
|
87
89
|
net-ssh (>= 2.6.5)
|
88
|
-
net-sftp (
|
89
|
-
net-ssh (>=
|
90
|
-
net-ssh (
|
90
|
+
net-sftp (3.0.0)
|
91
|
+
net-ssh (>= 5.0.0, < 7.0.0)
|
92
|
+
net-ssh (6.1.0)
|
91
93
|
netrc (0.11.0)
|
92
94
|
nori (2.6.0)
|
93
|
-
public_suffix (
|
94
|
-
rake (
|
95
|
-
rb-fsevent (0.10.
|
96
|
-
rb-inotify (0.10.
|
95
|
+
public_suffix (4.0.6)
|
96
|
+
rake (13.0.1)
|
97
|
+
rb-fsevent (0.10.4)
|
98
|
+
rb-inotify (0.10.1)
|
97
99
|
ffi (~> 1.0)
|
98
100
|
rb-kqueue (0.2.5)
|
99
101
|
ffi (>= 0.5.0)
|
@@ -101,53 +103,54 @@ GEM
|
|
101
103
|
http-cookie (>= 1.0.2, < 2.0)
|
102
104
|
mime-types (>= 1.16, < 4.0)
|
103
105
|
netrc (~> 0.8)
|
104
|
-
rspec (3.
|
105
|
-
rspec-core (~> 3.
|
106
|
-
rspec-expectations (~> 3.
|
107
|
-
rspec-mocks (~> 3.
|
108
|
-
rspec-core (3.
|
109
|
-
rspec-support (~> 3.
|
110
|
-
rspec-expectations (3.
|
106
|
+
rspec (3.9.0)
|
107
|
+
rspec-core (~> 3.9.0)
|
108
|
+
rspec-expectations (~> 3.9.0)
|
109
|
+
rspec-mocks (~> 3.9.0)
|
110
|
+
rspec-core (3.9.2)
|
111
|
+
rspec-support (~> 3.9.3)
|
112
|
+
rspec-expectations (3.9.2)
|
111
113
|
diff-lcs (>= 1.2.0, < 2.0)
|
112
|
-
rspec-support (~> 3.
|
114
|
+
rspec-support (~> 3.9.0)
|
113
115
|
rspec-its (1.3.0)
|
114
116
|
rspec-core (>= 3.0.0)
|
115
117
|
rspec-expectations (>= 3.0.0)
|
116
|
-
rspec-mocks (3.
|
118
|
+
rspec-mocks (3.9.1)
|
117
119
|
diff-lcs (>= 1.2.0, < 2.0)
|
118
|
-
rspec-support (~> 3.
|
119
|
-
rspec-support (3.
|
120
|
+
rspec-support (~> 3.9.0)
|
121
|
+
rspec-support (3.9.3)
|
120
122
|
ruby_dep (1.3.1)
|
121
123
|
rubyntlm (0.6.2)
|
122
|
-
rubyzip (
|
124
|
+
rubyzip (2.3.0)
|
123
125
|
sawyer (0.8.2)
|
124
126
|
addressable (>= 2.3.5)
|
125
127
|
faraday (> 0.8, < 2.0)
|
126
128
|
thread_safe (0.3.6)
|
127
|
-
tzinfo (1.2.
|
129
|
+
tzinfo (1.2.7)
|
128
130
|
thread_safe (~> 0.1)
|
129
131
|
unf (0.1.4)
|
130
132
|
unf_ext
|
131
|
-
unf_ext (0.0.7.
|
132
|
-
vagrant_cloud (2.0.
|
133
|
+
unf_ext (0.0.7.7)
|
134
|
+
vagrant_cloud (2.0.3)
|
133
135
|
rest-client (~> 2.0.2)
|
134
136
|
wdm (0.1.1)
|
135
|
-
winrm (2.3.
|
137
|
+
winrm (2.3.4)
|
136
138
|
builder (>= 2.1.2)
|
137
|
-
|
139
|
+
erubi (~> 1.8)
|
138
140
|
gssapi (~> 1.2)
|
139
141
|
gyoku (~> 1.0)
|
140
142
|
httpclient (~> 2.2, >= 2.2.0.2)
|
141
143
|
logging (>= 1.6.1, < 3.0)
|
142
144
|
nori (~> 2.0)
|
143
145
|
rubyntlm (~> 0.6.0, >= 0.6.1)
|
144
|
-
winrm-elevated (1.
|
146
|
+
winrm-elevated (1.2.1)
|
147
|
+
erubi (~> 1.8)
|
145
148
|
winrm (~> 2.0)
|
146
149
|
winrm-fs (~> 1.0)
|
147
|
-
winrm-fs (1.3.
|
148
|
-
|
150
|
+
winrm-fs (1.3.4)
|
151
|
+
erubi (~> 1.8)
|
149
152
|
logging (>= 1.6.1, < 3.0)
|
150
|
-
rubyzip (~>
|
153
|
+
rubyzip (~> 2.0)
|
151
154
|
winrm (~> 2.0)
|
152
155
|
|
153
156
|
PLATFORMS
|
@@ -163,4 +166,4 @@ DEPENDENCIES
|
|
163
166
|
vagrant-lxd!
|
164
167
|
|
165
168
|
BUNDLED WITH
|
166
|
-
2.
|
169
|
+
2.1.4
|
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
|
|
@@ -147,7 +148,7 @@ is passed through to LXD. The hash values should all be strings:
|
|
147
148
|
recursive: 'false',
|
148
149
|
}
|
149
150
|
|
150
|
-
[disk]: https://lxd.readthedocs.io/en/latest/
|
151
|
+
[disk]: https://lxd.readthedocs.io/en/latest/instances/#type-disk
|
151
152
|
|
152
153
|
### Shared LXD Containers
|
153
154
|
|
@@ -233,7 +234,7 @@ to run graphical applications transparently from within the guest:
|
|
233
234
|
Note that disk devices should be configured as [synced
|
234
235
|
folders](#synced-folders) rather than ad-hoc devices.
|
235
236
|
|
236
|
-
[device-config]: https://lxd.readthedocs.io/en/latest/
|
237
|
+
[device-config]: https://lxd.readthedocs.io/en/latest/instances/#devices-configuration
|
237
238
|
|
238
239
|
## Hacking
|
239
240
|
|
data/doc/setting-up-lxd.md
CHANGED
@@ -9,7 +9,46 @@ Specifically, the following settings need to be applied:
|
|
9
9
|
3. Your user must be in the "lxd" group.
|
10
10
|
4. Your user must have a client certificate registered with LXD.
|
11
11
|
|
12
|
-
##
|
12
|
+
## Ubuntu Focal and Later
|
13
|
+
|
14
|
+
On Ubuntu 20.04 and later, LXD is installed as a [Snap][]. To install
|
15
|
+
and configure it as described above, you can use the following commands:
|
16
|
+
|
17
|
+
```sh
|
18
|
+
# install lxd
|
19
|
+
sudo apt install -y lxd
|
20
|
+
|
21
|
+
# enable https api access
|
22
|
+
sudo lxd init --auto --network-address=127.0.0.1 --network-port=8443
|
23
|
+
|
24
|
+
# add your user to the lxd group
|
25
|
+
sudo usermod -a lxd -G $(whoami)
|
26
|
+
|
27
|
+
# apply the new group membership
|
28
|
+
newgrp lxd
|
29
|
+
```
|
30
|
+
|
31
|
+
Then, the first time you run Vagrant in a project that uses the LXD
|
32
|
+
provider, it will generate a client certificate for the plugin to use
|
33
|
+
and instruct you to add it to LXD with the following message:
|
34
|
+
|
35
|
+
```
|
36
|
+
You may need configure LXD to allow requests from this machine. The
|
37
|
+
easiest way to do this is to add your LXC client certificate to LXD's
|
38
|
+
list of trusted certificates. This can typically be done with the
|
39
|
+
following command:
|
40
|
+
|
41
|
+
$ lxc config trust add ~/.vagrant.d/data/lxd/client.crt
|
42
|
+
|
43
|
+
You can find more information about configuring LXD at:
|
44
|
+
|
45
|
+
https://linuxcontainers.org/lxd/getting-started-cli/#initial-configuration
|
46
|
+
```
|
47
|
+
|
48
|
+
Once you run that command as instructed, everything should be set up for
|
49
|
+
the plugin to work correctly.
|
50
|
+
|
51
|
+
## Ubuntu Xenial
|
13
52
|
|
14
53
|
To install LXD and configure it as described above on Ubuntu 16.04, you
|
15
54
|
can use the following commands:
|
@@ -37,7 +76,7 @@ automatically generate the certificate for you):
|
|
37
76
|
newgrp lxd
|
38
77
|
|
39
78
|
# create and add a client certificate
|
40
|
-
lxc config trust add
|
79
|
+
lxc config trust add ~/.config/lxc/client.crt
|
41
80
|
```
|
42
81
|
|
43
82
|
At this point everything should be set up for the plugin to work
|
@@ -53,5 +92,6 @@ If you're using the plugin on another platform, please feel free to
|
|
53
92
|
propose an addition to this document or add instructions to the
|
54
93
|
project's [wiki][] for others to follow.
|
55
94
|
|
95
|
+
[Snap]: https://snapcraft.io/
|
56
96
|
[getting-started-cli]: https://linuxcontainers.org/lxd/getting-started-cli/
|
57
97
|
[wiki]: https://gitlab.com/catalyst-it/vagrant-lxd/wikis
|
data/lib/vagrant-lxd/action.rb
CHANGED
@@ -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
|
@@ -29,14 +29,33 @@ module VagrantLXD
|
|
29
29
|
def Capability.synced_folders(env)
|
30
30
|
logger = Log4r::Logger.new('vagrant::lxd::capability')
|
31
31
|
logger.debug "Checking synced folders support for effective UID/GID #{Process.uid}/#{Process.gid}..."
|
32
|
-
|
32
|
+
%w(uid gid).all? do |type|
|
33
33
|
begin
|
34
|
-
|
34
|
+
id = Process.send(type)
|
35
|
+
id_map = File.readlines("/etc/sub#{type}")
|
36
|
+
id_in_sub_id?(id, id_map)
|
35
37
|
rescue StandardError => e
|
36
38
|
logger.warn "Cannot read subordinate permissions file: #{e.message}"
|
37
39
|
false
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
43
|
+
|
44
|
+
# Determines whether the given numerical `id` is included in the
|
45
|
+
# subordinate map `id_map`, which should be an array of lines from
|
46
|
+
# the file /etc/subuid or /etc/subgid.
|
47
|
+
#
|
48
|
+
# Invalid lines, and any lines for a user or group other than root,
|
49
|
+
# are ignored. See subuid(5) and subgid(5) for details about these
|
50
|
+
# files, and the expected format of their entries.
|
51
|
+
def Capability.id_in_sub_id?(id, id_map)
|
52
|
+
id_map.any? do |line|
|
53
|
+
if line.match(/^(root|0):(\d+):(\d+)/)
|
54
|
+
range_min = $2.to_i
|
55
|
+
range_max = range_min + $3.to_i
|
56
|
+
id.between?(range_min, range_max)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
41
60
|
end
|
42
61
|
end
|
data/lib/vagrant-lxd/driver.rb
CHANGED
@@ -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
|
@@ -115,15 +119,6 @@ module VagrantLXD
|
|
115
119
|
end
|
116
120
|
end
|
117
121
|
|
118
|
-
module Hyperkit::Client::Containers
|
119
|
-
alias extract_container_options_without_devices extract_container_options
|
120
|
-
|
121
|
-
def extract_container_options(name, options)
|
122
|
-
opts = extract_container_options_without_devices(name, options)
|
123
|
-
options.slice(:devices).merge(opts)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
122
|
NOT_CREATED = Vagrant::MachineState::NOT_CREATED_ID
|
128
123
|
|
129
124
|
attr_reader :api_endpoint
|
@@ -166,11 +161,11 @@ module VagrantLXD
|
|
166
161
|
|
167
162
|
def synced_folders_usable?
|
168
163
|
# Check whether we've registered an idmap for the current user.
|
169
|
-
raw_idmap =
|
164
|
+
raw_idmap = config[:'raw.idmap']
|
170
165
|
begin
|
171
166
|
raw_idmap and
|
172
|
-
|
173
|
-
|
167
|
+
id_in_map?(Process.uid, 'uid', raw_idmap) and
|
168
|
+
id_in_map?(Process.gid, 'gid', raw_idmap)
|
174
169
|
end
|
175
170
|
rescue Vagrant::Errors::ProviderNotUsable
|
176
171
|
false
|
@@ -343,6 +338,14 @@ module VagrantLXD
|
|
343
338
|
end
|
344
339
|
end
|
345
340
|
|
341
|
+
def package
|
342
|
+
if in_state? :stopped
|
343
|
+
create_package_directory
|
344
|
+
else
|
345
|
+
@logger.debug "Skipped packaging (#{machine_id} is not stopped)"
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
346
349
|
def configure
|
347
350
|
container = lxd.container(machine_id)
|
348
351
|
container[:config] = container[:config].to_hash.merge(config)
|
@@ -391,7 +394,7 @@ module VagrantLXD
|
|
391
394
|
end
|
392
395
|
end
|
393
396
|
|
394
|
-
|
397
|
+
private
|
395
398
|
|
396
399
|
#
|
397
400
|
# The remaining methods are just conveniences, not part of the API
|
@@ -538,11 +541,27 @@ module VagrantLXD
|
|
538
541
|
config
|
539
542
|
end
|
540
543
|
|
544
|
+
# Determines whether the numerical `id` of the specified `type` is
|
545
|
+
# included in the given idmap. These values should follow the format
|
546
|
+
# of the "raw.idmap" property specified here:
|
547
|
+
#
|
548
|
+
# https://lxd.readthedocs.io/en/latest/userns-idmap/#custom-idmaps
|
549
|
+
#
|
550
|
+
def id_in_map?(id, type, map)
|
551
|
+
range_types = ['both', type]
|
552
|
+
map.each_line.any? do |line|
|
553
|
+
range_type, range_values = line.split
|
554
|
+
range = range_values.split('-')
|
555
|
+
begin
|
556
|
+
range_types.include?(range_type) and
|
557
|
+
id.between?(range.first.to_i, range.last.to_i)
|
558
|
+
end
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
541
562
|
def locate_or_generate_client_certificate
|
542
563
|
vagrant_path = @machine.env.data_dir / 'lxd'
|
543
|
-
|
544
|
-
|
545
|
-
search_paths = [vagrant_path, default_path]
|
564
|
+
search_paths = [vagrant_path] + Certificate.default_paths
|
546
565
|
|
547
566
|
Certificate.locate(search_paths) or
|
548
567
|
Certificate.generate(vagrant_path)
|
@@ -602,6 +621,42 @@ module VagrantLXD
|
|
602
621
|
FileUtils.rm_rf(tmpdir)
|
603
622
|
end
|
604
623
|
|
624
|
+
# TODO s.a.
|
625
|
+
def create_package_directory
|
626
|
+
package_directory = Dir.mktmpdir
|
627
|
+
|
628
|
+
image = begin
|
629
|
+
lxd.create_image_from_container(machine_id, IMAGE_PROPERTIES)
|
630
|
+
rescue Hyperkit::BadRequest => e
|
631
|
+
if e.reason =~ /The image already exists: (\h{64})/
|
632
|
+
{
|
633
|
+
metadata: { fingerprint: $1 }
|
634
|
+
}
|
635
|
+
else
|
636
|
+
fail ImageExportFailure, machine_name: @machine.name, reason: e.reason
|
637
|
+
end
|
638
|
+
end
|
639
|
+
|
640
|
+
lxd.export_image(image[:metadata][:fingerprint], package_directory, filename: 'rootfs.tar.gz')
|
641
|
+
|
642
|
+
File.open(File.join(package_directory, 'metadata.json'), 'w') do |metadata|
|
643
|
+
metadata.puts JSON.pretty_generate({
|
644
|
+
'provider' => 'lxc',
|
645
|
+
'version' => '1.0.0',
|
646
|
+
'built-on' => Time.now.strftime("%a %m %d %H:%M:%S %z %Y"),
|
647
|
+
})
|
648
|
+
end
|
649
|
+
rescue Exception => e
|
650
|
+
@machine.ui.error 'Failed to export container image'
|
651
|
+
@logger.error 'Error preparing container image: ' << e.message << "\n" << e.backtrace.join("\n")
|
652
|
+
fail ImageExportFailure, machine_name: @machine.name, reason: e.message
|
653
|
+
else
|
654
|
+
package_directory
|
655
|
+
ensure
|
656
|
+
# If the image was created just for this package, remove it.
|
657
|
+
lxd.delete_image(image[:metadata][:fingerprint]) rescue nil if image.is_a? Sawyer::Resource
|
658
|
+
end
|
659
|
+
|
605
660
|
def error(klass)
|
606
661
|
klass.new(
|
607
662
|
provider: Version::NAME,
|
@@ -33,8 +33,11 @@ module VagrantLXD
|
|
33
33
|
|
34
34
|
@logger = Log4r::Logger.new('vagrant::lxd::driver::certificate')
|
35
35
|
|
36
|
-
def Certificate.
|
37
|
-
|
36
|
+
def Certificate.default_paths
|
37
|
+
[
|
38
|
+
Pathname.new('~/.config/lxc').expand_path,
|
39
|
+
Pathname.new('~/snap/lxd/current/.config/lxc').expand_path,
|
40
|
+
]
|
38
41
|
end
|
39
42
|
|
40
43
|
def Certificate.issuer_name
|
data/lib/vagrant-lxd/version.rb
CHANGED
data/templates/locales/en.yml
CHANGED
@@ -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
|
|
data/vagrant-lxd.gemspec
CHANGED
@@ -36,5 +36,9 @@ Gem::Specification.new do |spec|
|
|
36
36
|
end
|
37
37
|
|
38
38
|
spec.add_runtime_dependency 'activesupport', '~> 5.2.3'
|
39
|
-
spec.add_runtime_dependency 'hyperkit', '~> 1.
|
39
|
+
spec.add_runtime_dependency 'hyperkit', '~> 1.3.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
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Hanson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -30,14 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.3.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.3.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
|