vagrant-lxd 0.1.0 → 0.1.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
  SHA1:
3
- metadata.gz: 32163f21b3b3f37aee19bb36b0fbb6ada2d822eb
4
- data.tar.gz: 2b17ef463e4c1a22c9741637aa33f42fefd07e50
3
+ metadata.gz: 2ae29284d2a4a870ad54f62da227bfa06e1a879d
4
+ data.tar.gz: 1a7977adf19891632b59233f7de7bad527ed93b4
5
5
  SHA512:
6
- metadata.gz: 2bf717caad37765335e0493ba27038b4437c6cfbcf738ae3eca0b69a795088fd91451c2293847f595bc7159ea1cb6463efc59a6e67495392ce657bd647085963
7
- data.tar.gz: 5e27b6a883443794e47a9cfa7b4627dd88a26c0895e8629e5c1c621472da50c236065c73268ded9349aa961797ac3973facbbc9b7031bb96e0c036f27a655ab4
6
+ metadata.gz: 94b0882c41cd75aa6caf9f672b7f7353cfb56b9e60762f785f6b9fc23774ee8b2bb4443da86b35f957a52588cffb564a9e4130798498e3f1ab07fe037287fc0b
7
+ data.tar.gz: 9b1344147ebd312227be8186571ed421bfdc1dc4421a45c09f17bb0008759b2682b23b78c19228ed2901aa58f63f3782edaf78cb364564bf9e7982df6c9b12c1
data/Gemfile.lock CHANGED
@@ -23,7 +23,7 @@ GIT
23
23
  PATH
24
24
  remote: .
25
25
  specs:
26
- vagrant-lxd (0.1.0)
26
+ vagrant-lxd (0.1.1)
27
27
  hyperkit (~> 1.1.0)
28
28
 
29
29
  GEM
data/README.md CHANGED
@@ -25,7 +25,16 @@ The plugin requires LXD 2.0 and Vagrant 1.8.7 or newer.
25
25
 
26
26
  ## Installation
27
27
 
28
- Installing the plugin from this repository is a three-step process.
28
+ ### From Rubygems
29
+
30
+ You can install the latest version of the plugin directly from
31
+ rubygems.org with the `vagrant plugin` command:
32
+
33
+ $ vagrant plugin install vagrant-lxd
34
+
35
+ ### From Git
36
+
37
+ Installing from this repository is a three-step process.
29
38
 
30
39
  1. Use Bundler to install development dependencies:
31
40
 
@@ -43,12 +52,17 @@ Installing the plugin from this repository is a three-step process.
43
52
 
44
53
  ### Quick Start
45
54
 
46
- This plugin reuses the `lxc` box format, so VM images from [Vagrant
47
- Cloud][cloud] should work without modification:
55
+ First, make sure that you've [configured LXD correctly][setting-up-lxd]
56
+ for use with Vagrant.
57
+
58
+ Once LXD is set up, you can use `vagrant up --provider lxd` to create
59
+ container-backed machines. This plugin reuses the `lxc` box format, so
60
+ VM images from [Vagrant Cloud][cloud] should work without modification:
48
61
 
49
62
  $ vagrant init --minimal debian/stretch64
50
63
  $ vagrant up --provider lxd
51
64
 
65
+ [setting-up-lxd]: doc/setting-up-lxd.md
52
66
  [cloud]: https://app.vagrantup.com/boxes/search?provider=lxc
53
67
 
54
68
  #### Configuration
@@ -0,0 +1,57 @@
1
+ # Setting up LXD
2
+
3
+ LXD needs to be configured a particular way before Vagrant can use it.
4
+
5
+ Specifically, the following settings need to be applied:
6
+
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.
11
+
12
+ ## Xenial
13
+
14
+ To install LXD and configure it as described above on Ubuntu 16.04, you
15
+ 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
+ # set up a network bridge (press enter to accept the default values)
25
+ sudo dpkg-reconfigure -p medium lxd
26
+
27
+ # add your user to the lxd group
28
+ sudo usermod -a lxd -G $(whoami)
29
+ ```
30
+
31
+ Once LXD is configured, you should register a client certificate for
32
+ Vagrant to use when authenticating to the API (this command will
33
+ automatically generate the certificate for you):
34
+
35
+ ```sh
36
+ # apply new group membership
37
+ newgrp lxd
38
+
39
+ # create and add a client certificate
40
+ lxc config trust add /home/ubuntu/.config/lxc/client.crt
41
+ ```
42
+
43
+ At this point everything should be set up for the plugin to work
44
+ correctly.
45
+
46
+ ## Other Platforms
47
+
48
+ The Linux Containers website has a [detailed guide][getting-started-cli]
49
+ to installing LXD on other platforms. The steps to configure LXD for
50
+ Vagrant will be similar to those above, but some commands will differ.
51
+
52
+ If you're using the plugin on another platform, please feel free to
53
+ propose an addition to this document or add instructions to the
54
+ project's [wiki][] for others to follow.
55
+
56
+ [getting-started-cli]: https://linuxcontainers.org/lxd/getting-started-cli/
57
+ [wiki]: https://gitlab.com/catalyst-it/vagrant-lxd/wikis
@@ -61,8 +61,10 @@ module VagrantLXD
61
61
  end
62
62
 
63
63
  def attach(args)
64
+ options = Hash[force: false]
65
+
64
66
  opts = OptionParser.new do |o|
65
- o.banner = 'Usage: vagrant lxd attach [machine ...] <container>'
67
+ o.banner = 'Usage: vagrant lxd attach [-f] [machine ... container]'
66
68
  o.separator ''
67
69
  o.separator 'Associates a VM with a preexisting LXD container.'
68
70
  o.separator ''
@@ -70,6 +72,8 @@ module VagrantLXD
70
72
  o.separator 'preexisting LXD container. Once it has been associated with a container,'
71
73
  o.separator 'the machine can be used just like it had been created with `vagrant up`'
72
74
  o.separator 'or detached from the container again with `vagrant lxd detach`.'
75
+ o.separator ''
76
+ o.on('-f', '--force', 'Force attachment and ignore missing containers')
73
77
  end
74
78
 
75
79
  if args.include?('-h') or args.include?('--help')
@@ -77,16 +81,25 @@ module VagrantLXD
77
81
  exit 0
78
82
  end
79
83
 
80
- unless container = args.pop
81
- fail Vagrant::Errors::CLIInvalidUsage, help: opts.help
82
- end
84
+ options[:force] ||= args.delete('-f')
85
+ options[:force] ||= args.delete('--force')
86
+ options[:container_name] = args.pop
83
87
 
84
88
  with_target_machines(args) do |machine|
85
- if machine.id == container
89
+ if not container = options[:container_name] || machine.provider_config.name
90
+ machine.ui.warn 'No container name specified, skipping...'
91
+ elsif machine.id == container
86
92
  machine.ui.warn "Machine is already attached to container '#{container}', skipping..."
87
93
  elsif machine.state.id == Vagrant::MachineState::NOT_CREATED_ID
88
94
  machine.ui.info "Attaching to container '#{container}'..."
89
- Driver.new(machine).attach(container)
95
+ begin
96
+ Driver.new(machine).attach(container)
97
+ rescue Driver::ContainerNotFound
98
+ raise unless options[:force]
99
+ end
100
+ elsif options[:force]
101
+ detach([machine.name])
102
+ redo
90
103
  else
91
104
  machine.ui.error "Machine is already attached to container '#{machine.id}'"
92
105
  fail Driver::DuplicateAttachmentFailure, machine_name: machine.name, container: container
@@ -115,9 +128,8 @@ module VagrantLXD
115
128
  if machine.id.nil? or machine.state.id == Vagrant::MachineState::NOT_CREATED_ID
116
129
  machine.ui.warn "Machine is not attached to a container, skipping..."
117
130
  else
118
- driver = Driver.new(machine)
119
- machine.ui.info "Detaching from container '#{driver.machine_id}'..."
120
- driver.detach
131
+ machine.ui.info "Detaching from container '#{machine.id}'..."
132
+ Driver.new(machine).detach
121
133
  end
122
134
  end
123
135
  end
@@ -65,6 +65,10 @@ module VagrantLXD
65
65
  error_key 'lxd_duplicate_attachment_failure'
66
66
  end
67
67
 
68
+ class SnapshotNotFound < Vagrant::Errors::VagrantError
69
+ error_key 'snapshot_not_found'
70
+ end
71
+
68
72
  class Hyperkit::BadRequest
69
73
  def reason
70
74
  return unless data.is_a? Hash
@@ -150,7 +154,7 @@ module VagrantLXD
150
154
  end
151
155
  rescue Hyperkit::NotFound
152
156
  @machine.ui.error "Container doesn't exist: #{container}"
153
- fail ContainerNotFound, container: container
157
+ fail ContainerNotFound, machine_name: @machine.name, container: container
154
158
  end
155
159
 
156
160
  def detach
@@ -166,15 +170,23 @@ module VagrantLXD
166
170
  end
167
171
 
168
172
  def snapshot_save(name)
169
- @lxd.create_snapshot(machine_id, name)
173
+ snapshot_delete(name) # noops if the snapshot doesn't exist
174
+ operation = @lxd.create_snapshot(machine_id, name, sync: false)
175
+ wait_for_operation(operation)
170
176
  end
171
177
 
172
178
  def snapshot_restore(name)
173
- @lxd.restore_snapshot(machine_id, name)
179
+ operation = @lxd.restore_snapshot(machine_id, name, sync: false)
180
+ wait_for_operation(operation)
181
+ rescue Hyperkit::BadRequest
182
+ @logger.warn 'Snapshot restoration failed: ' << name
183
+ fail SnapshotNotFound, machine: @machine.name, snapshot_name: name
174
184
  end
175
185
 
176
186
  def snapshot_delete(name)
177
187
  @lxd.delete_snapshot(machine_id, name)
188
+ rescue Hyperkit::NotFound
189
+ @logger.warn 'No such snapshot: ' << name
178
190
  end
179
191
 
180
192
  def state
@@ -267,6 +279,10 @@ module VagrantLXD
267
279
 
268
280
  private
269
281
 
282
+ def machine_id
283
+ @machine.id
284
+ end
285
+
270
286
  def delete_container
271
287
  @lxd.delete_container(machine_id)
272
288
  rescue Hyperkit::NotFound
@@ -281,6 +297,15 @@ module VagrantLXD
281
297
  @logger.error "Unable to delete image for '#{machine_id}'"
282
298
  end
283
299
 
300
+ # Hyperkit doesn't handle socket read timeouts even when auto_sync
301
+ # is enabled or setting sync: true. TODO Upstream a better fix than
302
+ # this, so that `wait_for_operation` really does.
303
+ def wait_for_operation(operation)
304
+ @lxd.wait_for_operation(operation.id)
305
+ rescue Faraday::TimeoutError
306
+ retry
307
+ end
308
+
284
309
  def container
285
310
  @lxd.container(machine_id)
286
311
  end
@@ -301,10 +326,6 @@ module VagrantLXD
301
326
  true
302
327
  end
303
328
 
304
- def machine_id
305
- @machine.id
306
- end
307
-
308
329
  def generate_machine_id
309
330
  @name || begin
310
331
  id = "vagrant-#{File.basename(Dir.pwd)}-#{@machine.name}-#{SecureRandom.hex(8)}"
@@ -20,7 +20,7 @@
20
20
  module VagrantLXD
21
21
  module Version
22
22
  NAME = 'vagrant-lxd'
23
- VERSION = '0.1.0'
23
+ VERSION = '0.1.1'
24
24
  DESCRIPTION = 'Vagrant LXD provider'
25
25
  end
26
26
  end
@@ -12,6 +12,8 @@ en:
12
12
  actions:
13
13
  vm:
14
14
  snapshot:
15
+ not_found: |-
16
+ The machine has no snapshot named '%{name}'.
15
17
  restored: |-
16
18
  The machine has been restored to snapshot '%{name}'!
17
19
  errors:
@@ -96,15 +98,24 @@ en:
96
98
  A machine can only be associated with one container at a time.
97
99
 
98
100
  To attach '%{machine_name}' to '%{container}', you must first
99
- detach it from its current container using `vagrant lxd detach`.
101
+ detach it from its current container using `vagrant lxd detach`
102
+ or pass `--force` to force attachment.
100
103
 
101
104
  lxd_container_not_found: |-
102
105
  The requested container '%{container}' doesn't exist.
103
106
 
107
+ You will need to create this container first, either by using the
108
+ `lxc launch` command or by setting the VM's `lxd.name` in its LXD
109
+ provider configuration and running `vagrant up %{machine_name}`.
110
+
104
111
  You can list available containers with the `lxc list` command.
112
+
105
113
  lxd_container_already_exists: |-
106
114
  A container with the name '%{container}' already exists.
107
115
 
108
116
  You will either need to delete this container and try again, or attach
109
117
  the VM to it with `vagrant lxd attach %{machine_name} %{container}`.
110
118
 
119
+ snapshot_not_found: |-
120
+ The snapshot name `%{snapshot_name}` was not found for the
121
+ virtual machine `%{machine}`.
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.1.0
4
+ version: 0.1.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: 2017-10-01 00:00:00.000000000 Z
11
+ date: 2017-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hyperkit
@@ -37,6 +37,7 @@ files:
37
37
  - LICENSE.md
38
38
  - README.md
39
39
  - Rakefile
40
+ - doc/setting-up-lxd.md
40
41
  - lib/vagrant-lxd.rb
41
42
  - lib/vagrant-lxd/action.rb
42
43
  - lib/vagrant-lxd/capability.rb