vagrant-lxd 0.6.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: daabe10181291cc4bf1459828a65236d208c210970d646f14dcfe9c707d73f06
4
- data.tar.gz: 50e5a72cd3e1e9f8e3187e7c6da8ba0c4dc97919ee250ba15bbfbe485e3fa8ba
3
+ metadata.gz: 9f0f075e1a4c96070a15ebb90aff04e8d7d4f256f7b5d8c8494390b2826ac729
4
+ data.tar.gz: 22ad9d6af3b0a06a88c331907b3ba62491c593627773491bcc82c95d7cad9138
5
5
  SHA512:
6
- metadata.gz: 97a2e2e0ebcd5c601cad8825cf2a7cb2411f2641fbcb8c79b79b1d13e001a2993bf5827060ca43473c54073b774a997f76aa394516dad193680e3cdacd9c865a
7
- data.tar.gz: 96d298c3e91599753a8f9a628b73c74fbbedd532ec6b9586e3162db73f7ca28c58fc1b3970323aaba65c3b39dc98ba967032e36a444dcee8e0ca9f98fbf26816
6
+ metadata.gz: 94ce807ed3c17ae49232dc19800a9f555251914fa3651b8d2b6f19941c52524a79f2042f3dbcbd4a73f0fbcfdadcdfd3e14449828582eac1cac38eb15175c759
7
+ data.tar.gz: 424cf1cbc62ea73dc806cafb32d8a2b758eb58d49a918823cf5f98f1819a82b97fe74de6c7b741a278710d923f5098132fa66f3eba456a14b08704d7c9586e08
data/.gitlab-ci.yml CHANGED
@@ -1,4 +1,4 @@
1
- image: ruby:2.5
1
+ image: ruby:3.0
2
2
 
3
3
  before_script:
4
4
  - apt-get -y update
data/Gemfile CHANGED
@@ -7,7 +7,8 @@ group :development do
7
7
  gem 'rspec'
8
8
  gem 'rspec-its'
9
9
  gem 'rspec-mocks'
10
- gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git', tag: 'v2.2.15'
10
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git', tag: 'v2.4.0'
11
+ gem 'webrick'
11
12
  end
12
13
 
13
14
  group :plugins do
data/Gemfile.lock CHANGED
@@ -1,33 +1,39 @@
1
1
  GIT
2
2
  remote: https://github.com/mitchellh/vagrant.git
3
- revision: 9247e07fc8ffe2fdb91c6422bbb133a25983fe15
4
- tag: v2.2.15
3
+ revision: 5a2b888c371bd0c8dcae3abe1403e89020c6d6ca
4
+ tag: v2.4.0
5
5
  specs:
6
- vagrant (2.2.15)
6
+ vagrant (2.4.0)
7
7
  bcrypt_pbkdf (~> 1.1)
8
- childprocess (~> 4.0.0)
9
- ed25519 (~> 1.2.4)
8
+ childprocess (~> 4.1.0)
9
+ ed25519 (~> 1.3.0)
10
10
  erubi
11
+ googleapis-common-protos-types (~> 1.3)
12
+ grpc (~> 1.56.0)
11
13
  hashicorp-checkpoint (~> 0.1.5)
12
- i18n (~> 1.8)
13
- listen (~> 3.4)
14
+ i18n (~> 1.12)
15
+ ipaddr (>= 1.2.4)
16
+ listen (~> 3.7)
14
17
  log4r (~> 1.1.9, < 1.1.11)
15
18
  mime-types (~> 3.3)
16
- net-scp (~> 1.2.0)
17
- net-sftp (~> 3.0)
18
- net-ssh (>= 6.1.0, < 7)
19
+ net-ftp (~> 0.2)
20
+ net-scp (~> 4.0)
21
+ net-sftp (~> 4.0)
22
+ net-ssh (~> 7.0)
19
23
  rb-kqueue (~> 0.2.0)
20
- rubyzip (~> 2.0)
21
- vagrant_cloud (~> 3.0.4)
22
- wdm (~> 0.1.0)
23
- winrm (>= 2.3.4, < 3.0)
24
- winrm-elevated (>= 1.2.1, < 2.0)
25
- winrm-fs (>= 1.3.4, < 2.0)
24
+ rexml (~> 3.2)
25
+ rgl (~> 0.5.10)
26
+ rubyzip (~> 2.3.2)
27
+ vagrant_cloud (~> 3.1.0)
28
+ wdm (~> 0.1.1)
29
+ winrm (>= 2.3.6, < 3.0)
30
+ winrm-elevated (>= 1.2.3, < 2.0)
31
+ winrm-fs (>= 1.3.5, < 2.0)
26
32
 
27
33
  PATH
28
34
  remote: .
29
35
  specs:
30
- vagrant-lxd (0.6.0)
36
+ vagrant-lxd (0.7.1)
31
37
  activesupport (~> 5.2.3)
32
38
  faraday (~> 0.17)
33
39
  hyperkit (~> 1.3.0)
@@ -35,93 +41,117 @@ PATH
35
41
  GEM
36
42
  remote: https://rubygems.org/
37
43
  specs:
38
- activesupport (5.2.8)
44
+ activesupport (5.2.8.1)
39
45
  concurrent-ruby (~> 1.0, >= 1.0.2)
40
46
  i18n (>= 0.7, < 2)
41
47
  minitest (~> 5.1)
42
48
  tzinfo (~> 1.1)
43
- addressable (2.8.0)
44
- public_suffix (>= 2.0.2, < 5.0)
49
+ addressable (2.8.5)
50
+ public_suffix (>= 2.0.2, < 6.0)
45
51
  bcrypt_pbkdf (1.1.0)
46
52
  builder (3.2.4)
47
- childprocess (4.0.0)
48
- concurrent-ruby (1.1.9)
49
- diff-lcs (1.4.4)
50
- ed25519 (1.2.4)
51
- erubi (1.10.0)
52
- excon (0.87.0)
53
- fakefs (1.4.0)
54
- faraday (0.17.5)
53
+ childprocess (4.1.0)
54
+ concurrent-ruby (1.2.2)
55
+ date (3.3.3)
56
+ diff-lcs (1.5.0)
57
+ ed25519 (1.3.0)
58
+ erubi (1.12.0)
59
+ excon (0.104.0)
60
+ fakefs (2.5.0)
61
+ faraday (0.17.6)
55
62
  multipart-post (>= 1.2, < 3)
56
- ffi (1.15.4)
63
+ ffi (1.16.3)
64
+ google-protobuf (3.24.4)
65
+ googleapis-common-protos-types (1.9.0)
66
+ google-protobuf (~> 3.18)
67
+ grpc (1.56.2)
68
+ google-protobuf (~> 3.23)
69
+ googleapis-common-protos-types (~> 1.0)
57
70
  gssapi (1.3.1)
58
71
  ffi (>= 1.0.1)
59
- gyoku (1.3.1)
72
+ gyoku (1.4.0)
60
73
  builder (>= 2.1.2)
74
+ rexml (~> 3.0)
61
75
  hashicorp-checkpoint (0.1.5)
62
76
  httpclient (2.8.3)
63
77
  hyperkit (1.3.0)
64
78
  activesupport (>= 4.2.6)
65
79
  sawyer
66
- i18n (1.8.10)
80
+ i18n (1.14.1)
67
81
  concurrent-ruby (~> 1.0)
68
- listen (3.7.0)
82
+ ipaddr (1.2.5)
83
+ listen (3.8.0)
69
84
  rb-fsevent (~> 0.10, >= 0.10.3)
70
85
  rb-inotify (~> 0.9, >= 0.9.10)
71
86
  little-plugger (1.1.4)
72
87
  log4r (1.1.10)
73
- logging (2.3.0)
88
+ logging (2.3.1)
74
89
  little-plugger (~> 1.1)
75
90
  multi_json (~> 1.14)
76
- mime-types (3.3.1)
91
+ mime-types (3.5.1)
77
92
  mime-types-data (~> 3.2015)
78
- mime-types-data (3.2021.0901)
79
- minitest (5.16.1)
93
+ mime-types-data (3.2023.1003)
94
+ minitest (5.20.0)
80
95
  multi_json (1.15.0)
81
- multipart-post (2.2.3)
82
- net-scp (1.2.1)
83
- net-ssh (>= 2.6.5)
84
- net-sftp (3.0.0)
85
- net-ssh (>= 5.0.0, < 7.0.0)
86
- net-ssh (6.1.0)
96
+ multipart-post (2.3.0)
97
+ net-ftp (0.2.0)
98
+ net-protocol
99
+ time
100
+ net-protocol (0.2.1)
101
+ timeout
102
+ net-scp (4.0.0)
103
+ net-ssh (>= 2.6.5, < 8.0.0)
104
+ net-sftp (4.0.0)
105
+ net-ssh (>= 5.0.0, < 8.0.0)
106
+ net-ssh (7.2.0)
87
107
  nori (2.6.0)
88
- public_suffix (4.0.7)
89
- rake (13.0.6)
90
- rb-fsevent (0.11.0)
108
+ pairing_heap (3.0.1)
109
+ public_suffix (5.0.3)
110
+ rake (13.1.0)
111
+ rb-fsevent (0.11.2)
91
112
  rb-inotify (0.10.1)
92
113
  ffi (~> 1.0)
93
- rb-kqueue (0.2.7)
114
+ rb-kqueue (0.2.8)
94
115
  ffi (>= 0.5.0)
95
- rexml (3.2.5)
96
- rspec (3.10.0)
97
- rspec-core (~> 3.10.0)
98
- rspec-expectations (~> 3.10.0)
99
- rspec-mocks (~> 3.10.0)
100
- rspec-core (3.10.1)
101
- rspec-support (~> 3.10.0)
102
- rspec-expectations (3.10.1)
116
+ rexml (3.2.6)
117
+ rgl (0.5.10)
118
+ pairing_heap (>= 0.3.0)
119
+ rexml (~> 3.2, >= 3.2.4)
120
+ stream (~> 0.5.3)
121
+ rspec (3.12.0)
122
+ rspec-core (~> 3.12.0)
123
+ rspec-expectations (~> 3.12.0)
124
+ rspec-mocks (~> 3.12.0)
125
+ rspec-core (3.12.2)
126
+ rspec-support (~> 3.12.0)
127
+ rspec-expectations (3.12.3)
103
128
  diff-lcs (>= 1.2.0, < 2.0)
104
- rspec-support (~> 3.10.0)
129
+ rspec-support (~> 3.12.0)
105
130
  rspec-its (1.3.0)
106
131
  rspec-core (>= 3.0.0)
107
132
  rspec-expectations (>= 3.0.0)
108
- rspec-mocks (3.10.2)
133
+ rspec-mocks (3.12.6)
109
134
  diff-lcs (>= 1.2.0, < 2.0)
110
- rspec-support (~> 3.10.0)
111
- rspec-support (3.10.2)
135
+ rspec-support (~> 3.12.0)
136
+ rspec-support (3.12.1)
112
137
  rubyntlm (0.6.3)
113
138
  rubyzip (2.3.2)
114
139
  sawyer (0.9.2)
115
140
  addressable (>= 2.3.5)
116
141
  faraday (>= 0.17.3, < 3)
142
+ stream (0.5.5)
117
143
  thread_safe (0.3.6)
118
- tzinfo (1.2.9)
144
+ time (0.2.2)
145
+ date
146
+ timeout (0.4.0)
147
+ tzinfo (1.2.11)
119
148
  thread_safe (~> 0.1)
120
- vagrant_cloud (3.0.5)
149
+ vagrant_cloud (3.1.0)
121
150
  excon (~> 0.73)
122
151
  log4r (~> 1.1.10)
123
152
  rexml (~> 3.2.5)
124
153
  wdm (0.1.1)
154
+ webrick (1.8.1)
125
155
  winrm (2.3.6)
126
156
  builder (>= 2.1.2)
127
157
  erubi (~> 1.8)
@@ -152,6 +182,7 @@ DEPENDENCIES
152
182
  rspec-mocks
153
183
  vagrant!
154
184
  vagrant-lxd!
185
+ webrick
155
186
 
156
187
  BUNDLED WITH
157
- 2.1.4
188
+ 2.3.5
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # vagrant-lxd
2
2
 
3
3
  This is a [Vagrant][] plugin that adds the ability to manage containers
4
- with [LXD][].
4
+ with [LXD][] or [Incus][].
5
5
 
6
6
  [Vagrant]: https://www.vagrantup.com/
7
- [LXD]: https://linuxcontainers.org/lxd/
7
+ [LXD]: https://documentation.ubuntu.com/lxd/
8
+ [Incus]: https://linuxcontainers.org/incus/
8
9
 
9
10
  ## Features
10
11
 
@@ -22,7 +23,18 @@ The following features are not expected to work yet:
22
23
  - Static IP addresses
23
24
  - IPv6 networking
24
25
 
25
- The plugin requires LXD 2.0 and Vagrant 1.8.7 or newer.
26
+ ## Supported Versions
27
+
28
+ The plugin requires at least the following software versions:
29
+
30
+ - Vagrant 2.2
31
+ - LXD 3.8
32
+ - Incus 0.2
33
+
34
+ Despite its name, this plugin works with Incus as well as LXD. You can
35
+ generally replace "LXD" with "Incus" (and `lxc` with `incus`) when reading
36
+ this documentation and it'll remain correct, although a few important
37
+ differences have been noted.
26
38
 
27
39
  ## Installation
28
40
 
@@ -60,7 +72,7 @@ Once LXD is set up, you can use `vagrant up --provider lxd` to create
60
72
  container-backed machines. This plugin reuses the `lxc` box format, so
61
73
  VM images from [Vagrant Cloud][cloud] should work without modification:
62
74
 
63
- $ vagrant init --minimal debian/stretch64
75
+ $ vagrant init --minimal hibox/jammy64
64
76
  $ vagrant up --provider lxd
65
77
 
66
78
  [setting-up-lxd]: doc/setting-up-lxd.md
@@ -69,13 +81,13 @@ VM images from [Vagrant Cloud][cloud] should work without modification:
69
81
  #### Configuration
70
82
 
71
83
  Below is an example Vagrantfile showing most of the provider's
72
- configurable values, along with their defaults. The `debian/stretch64`
84
+ configurable values, along with their defaults. The `hibox/jammy64`
73
85
  box is available on the Vagrant Cloud, so you should be able to copy
74
86
  this file and adjust it as you see fit.
75
87
 
76
88
  ``` ruby
77
89
  Vagrant.configure('2') do |config|
78
- config.vm.box = 'debian/stretch64'
90
+ config.vm.box = 'hibox/jammy64'
79
91
 
80
92
  config.vm.provider 'lxd' do |lxd|
81
93
  lxd.api_endpoint = 'https://127.0.0.1:8443'
@@ -100,11 +112,15 @@ By default, the plugin will first try to use files from
100
112
  `~/.config/lxc/client.crt` and `client.key`, if they exist. Otherwise,
101
113
  it will generate a new 4096-bit RSA certificate (and accompanying
102
114
  private key) in Vagrant's data directory. When using the plugin for the
103
- first time, you will need to add this certificate to LXD's trust store
115
+ first time, you will need to add this certificate to server's trust store
104
116
  by running:
105
117
 
106
118
  $ lxc config trust add ~/.vagrant.d/data/lxd/client.crt
107
119
 
120
+ If you're using Incus, the command is slightly different:
121
+
122
+ $ incus config trust add-certificate ~/.vagrant.d/data/lxd/client.crt
123
+
108
124
  If you would rather use an existing certificate, you can specify the
109
125
  files for the plugin to use with the following settings:
110
126
 
@@ -149,7 +165,7 @@ is passed through to LXD. The hash values should all be strings:
149
165
  recursive: 'false',
150
166
  }
151
167
 
152
- [disk]: https://linuxcontainers.org/lxd/docs/master/instances/#type-disk
168
+ [disk]: https://documentation.ubuntu.com/lxd/en/latest/reference/devices_disk/
153
169
 
154
170
  ### Shared LXD Containers
155
171
 
@@ -192,8 +208,8 @@ about this setting.
192
208
  In order to run Linux containers on an LXD-backed machine, it must be
193
209
  created with the `nesting` and `privileged` properties set to `true`.
194
210
  These correspond to the `security.nesting` and `security.privileged`
195
- configuration items for LXD, respectively. Refer to LXD's [container
196
- configuration documentation][containers] for details.
211
+ configuration items for LXD, respectively. Refer to LXD's [instance
212
+ options documentation][instances] for details.
197
213
 
198
214
  config.vm.provider 'lxd' do |lxd|
199
215
  lxd.nesting = true
@@ -204,7 +220,7 @@ Note that enabling these options will invalidate any user and group ID
204
220
  mappings you may have configured for synced folders, since privileged
205
221
  containers use the same UID and GID space as the host machine.
206
222
 
207
- [containers]: https://linuxcontainers.org/lxd/docs/master/instances/
223
+ [instances]: https://documentation.ubuntu.com/lxd/en/latest/reference/instance_options/
208
224
 
209
225
  ### Adding Devices
210
226
 
@@ -235,7 +251,7 @@ to run graphical applications transparently from within the guest:
235
251
  Note that disk devices should be configured as [synced
236
252
  folders](#synced-folders) rather than ad-hoc devices.
237
253
 
238
- [device-config]: https://linuxcontainers.org/lxd/docs/master/instances/#devices-configuration
254
+ [device-config]: https://documentation.ubuntu.com/lxd/en/latest/reference/devices/
239
255
 
240
256
  ### Container Configuration
241
257
 
@@ -253,11 +269,11 @@ Not all instance settings make sense in the Vagrant context, and some will or
253
269
  won't work based on your LXD host's configuration, so making sure the config is
254
270
  valid is up to you.
255
271
 
256
- [instance-config]: https://linuxcontainers.org/lxd/docs/master/instances/#key-value-configuration
272
+ [instance-config]: https://documentation.ubuntu.com/lxd/en/latest/reference/instance_options/
257
273
 
258
274
  ### LXD Projects
259
275
 
260
- Since version 3.8, LXD has supported [projects] as a way to segment an LXD
276
+ Since version 3.8, LXD has supported [projects][] as a way to segment an LXD
261
277
  server. Each project has its own set of containers, profiles, images, and so
262
278
  on.
263
279
 
@@ -286,7 +302,7 @@ correctly. The following commands should get you started with a new project:
286
302
  lxc profile device add default eth0 nic name=eth0 parent=lxdbr0 nictype=bridged
287
303
  lxc profile device add default root disk path=/ pool=default
288
304
 
289
- [projects]: https://linuxcontainers.org/lxd/docs/master/projects/
305
+ [projects]: https://documentation.ubuntu.com/lxd/en/latest/explanation/projects/
290
306
 
291
307
  ## Hacking
292
308
 
@@ -1,22 +1,28 @@
1
1
  # Setting up LXD
2
2
 
3
- LXD needs to be configured a particular way before Vagrant can use it.
3
+ LXD (or Incus) needs to be configured a particular way before Vagrant can use
4
+ it.
4
5
 
5
6
  Specifically, the following settings need to be applied:
6
7
 
7
- 1. LXD must allow HTTPS API access from your machine.
8
- 2. LXD must have a working network bridge.
9
- 3. Your user must be in the "lxd" group.
10
- 4. Your user must have a client certificate registered with LXD.
8
+ 1. The server must allow HTTPS API access from your machine.
9
+ 2. The server must have a working network bridge.
10
+ 3. Your user must be in the "lxd" (or "incus-admin") group.
11
+ 4. Your user must have a client certificate registered.
11
12
 
12
- ## Ubuntu Focal and Later
13
+ Note the following instructions apply specifically to LXD. When using Incus,
14
+ you'll need to change the commands and group names accordingly.
15
+
16
+ ## Ubuntu
17
+
18
+ ### Focal and Later
13
19
 
14
20
  On Ubuntu 20.04 and later, LXD is installed as a [Snap][]. To install
15
21
  and configure it as described above, you can use the following commands:
16
22
 
17
23
  ```sh
18
24
  # install lxd
19
- sudo apt install -y lxd
25
+ sudo snap install lxd
20
26
 
21
27
  # enable https api access
22
28
  sudo lxd init --auto --network-address=127.0.0.1 --network-port=8443
@@ -42,13 +48,13 @@ following command:
42
48
 
43
49
  You can find more information about configuring LXD at:
44
50
 
45
- https://linuxcontainers.org/lxd/getting-started-cli/#initial-configuration
51
+ https://documentation.ubuntu.com/lxd/en/latest/howto/initialize/
46
52
  ```
47
53
 
48
54
  Once you run that command as instructed, everything should be set up for
49
55
  the plugin to work correctly.
50
56
 
51
- ## Ubuntu Xenial
57
+ ### Xenial and Earlier
52
58
 
53
59
  To install LXD and configure it as described above on Ubuntu 16.04, you
54
60
  can use the following commands:
@@ -84,7 +90,7 @@ correctly.
84
90
 
85
91
  ## Other Platforms
86
92
 
87
- The Linux Containers website has a [detailed guide][getting-started-cli]
93
+ The Canonical website has a [detailed guide][getting-started-cli]
88
94
  to installing LXD on other platforms. The steps to configure LXD for
89
95
  Vagrant will be similar to those above, but some commands will differ.
90
96
 
@@ -93,5 +99,5 @@ propose an addition to this document or add instructions to the
93
99
  project's [wiki][] for others to follow.
94
100
 
95
101
  [Snap]: https://snapcraft.io/
96
- [getting-started-cli]: https://linuxcontainers.org/lxd/getting-started-cli/
102
+ [getting-started-cli]: https://documentation.ubuntu.com/lxd/en/latest/howto/initialize/
97
103
  [wiki]: https://gitlab.com/catalyst-it/vagrant-lxd/wikis
@@ -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
@@ -69,8 +69,8 @@ module VagrantLXD
69
69
  cert.sign(pkey, OpenSSL::Digest::SHA256.new)
70
70
  @logger.debug "Saving new certificate to disk under #{path}..."
71
71
  FileUtils.mkdir_p(path, mode: 0o700)
72
- File.write(path / 'client.crt', cert.to_s, 0, perm: 0o600)
73
- File.write(path / 'client.key', pkey.to_s, 0, perm: 0o600)
72
+ File.write(path / 'client.crt', cert.to_s, 0, mode: 'w', perm: 0o600)
73
+ File.write(path / 'client.key', pkey.to_s, 0, mode: 'w', perm: 0o600)
74
74
  Certificate.new(path / 'client.crt', path / 'client.key')
75
75
  rescue Exception => e
76
76
  @logger.error 'Certificate creation failed: ' << e.message
@@ -120,6 +120,15 @@ module VagrantLXD
120
120
  end
121
121
  end
122
122
 
123
+ # Use the correct endpoint for the containers API: "/containers" is
124
+ # deprecated, replaced by "/instances". See this link for a history:
125
+ # https://discuss.linuxcontainers.org/t/incus-0-1-has-been-released/18036
126
+ module Hyperkit::Client::Containers
127
+ def containers_path
128
+ '/1.0/instances'
129
+ end
130
+ end
131
+
123
132
  class Hyperkit::BadRequest
124
133
  def reason
125
134
  return unless data.is_a? Hash
@@ -155,6 +164,7 @@ module VagrantLXD
155
164
 
156
165
  def initialize(machine)
157
166
  @machine = machine
167
+ @image = machine.provider_config.image
158
168
  @timeout = machine.provider_config.timeout
159
169
  @api_endpoint = machine.provider_config.api_endpoint
160
170
  @config = machine.provider_config.config
@@ -277,34 +287,15 @@ module VagrantLXD
277
287
 
278
288
  def create
279
289
  if in_state? NOT_CREATED
280
- image, container = nil, nil
290
+ fingerprint = image_from_box
281
291
  machine_id = generate_machine_id
282
- file, fingerprint = Driver.synchronize { prepare_image_file }
283
-
284
- Driver.synchronize do
285
- begin
286
- image = lxd.image(fingerprint)
287
- @logger.debug 'Using image: ' << image.inspect
288
- rescue Hyperkit::NotFound
289
- image = lxd.create_image_from_file(file)
290
- @logger.debug 'Created image: ' << image.inspect
291
- begin
292
- lxd.update_image(fingerprint, properties: IMAGE_PROPERTIES)
293
- lxd.create_image_alias(fingerprint, machine_id, IMAGE_PROPERTIES)
294
- rescue Hyperkit::Error
295
- @logger.error 'Failed to set description for image: ' << e.reason
296
- end
297
- end
298
- end
299
-
300
292
  container = lxd.create_container(machine_id, devices: devices, ephemeral: ephemeral, fingerprint: fingerprint, config: config, profiles: profiles)
301
293
  @logger.debug 'Created container: ' << container.inspect
302
-
303
294
  @machine.id = machine_id
304
295
  end
305
296
  rescue Hyperkit::Error => e
306
297
  lxd.delete_container(machine_id) rescue nil unless container.nil?
307
- lxd.delete_image(image[:metadata][:fingerprint]) rescue nil unless image.nil?
298
+ lxd.delete_image(fingerprint) rescue nil unless fingerprint.nil?
308
299
  if e.reason =~ /Container '([^']+)' already exists/
309
300
  @machine.ui.error e.reason
310
301
  fail ContainerAlreadyExists, machine_name: @machine.name, container: $1
@@ -404,6 +395,14 @@ module VagrantLXD
404
395
  fail ContainerConfigurationFailure, machine_name: @machine.name, reason: e.reason
405
396
  end
406
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
+
407
406
  def info
408
407
  if in_state? :running, :frozen
409
408
  {
@@ -469,8 +468,9 @@ module VagrantLXD
469
468
  # is enabled or setting sync: true. TODO Upstream a better fix than
470
469
  # this, so that `wait_for_operation` really does.
471
470
  def wait_for_operation(operation)
471
+ @logger.debug 'Waiting for operation: ' << operation.inspect
472
472
  lxd.wait_for_operation(operation.id)
473
- rescue Faraday::TimeoutError
473
+ rescue Net::ReadTimeout, Faraday::TimeoutError
474
474
  retry
475
475
  end
476
476
 
@@ -598,7 +598,28 @@ module VagrantLXD
598
598
  fail CertificateGenerationFailure, reason: e.message, api_endpoint: @api_endpoint.to_s, default_path: default_path, vagrant_path: vagrant_path
599
599
  end
600
600
 
601
- # 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
+
602
623
  def prepare_image_file
603
624
  tmpdir = Dir.mktmpdir
604
625
 
@@ -655,7 +676,8 @@ module VagrantLXD
655
676
  package_directory = Dir.mktmpdir
656
677
 
657
678
  image = begin
658
- 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)
659
681
  rescue Hyperkit::BadRequest => e
660
682
  if e.reason =~ /The image already exists: (\h{64})/
661
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.6.0'
23
+ VERSION = '0.7.1'
24
24
  DESCRIPTION = 'Vagrant LXD provider'
25
25
  end
26
26
  end
@@ -48,7 +48,7 @@ en:
48
48
 
49
49
  You can find more documentation about configuring LXD at:
50
50
 
51
- https://linuxcontainers.org/lxd/getting-started-cli/#initial-configuration
51
+ https://documentation.ubuntu.com/lxd/en/latest/howto/initialize/
52
52
 
53
53
  lxd_authentication_failure: |-
54
54
  The LXD provider could not authenticate to the daemon at %{api_endpoint}.
@@ -61,8 +61,8 @@ en:
61
61
  $ lxc config trust add %{client_cert}
62
62
 
63
63
  You can find more information about configuring LXD at:
64
-
65
- https://linuxcontainers.org/lxd/getting-started-cli/#initial-configuration
64
+
65
+ https://documentation.ubuntu.com/lxd/en/latest/howto/initialize/
66
66
 
67
67
  lxd_operation_timeout: |-
68
68
  The container failed to respond within %{time_limit} seconds. Try
@@ -105,7 +105,7 @@ en:
105
105
 
106
106
  lxd_container_deletion_failure: |-
107
107
  The provider was unable to delete the container for the '%{machine_name}' VM.
108
-
108
+
109
109
  The underlying error message was: %{reason}
110
110
 
111
111
  The LXD logs may contain more information about the cause of this failure.
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.6.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: 2022-06-20 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
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
- rubygems_version: 3.0.3
102
+ rubygems_version: 3.3.5
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: Vagrant LXD provider