vagrant-linode 0.3.0 → 0.4.0

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: 512f23fdd3c5ee70ed9a4e3c49bb03225d751c62
4
- data.tar.gz: 6bf4e88684a6bcfb94f182dfdef854096eefc586
3
+ metadata.gz: b9188fdd2aa3e774b85bab464f1b5830e4c3ed5c
4
+ data.tar.gz: 7d13d05b7f4ba405cc0cbf561f8db36955587fa0
5
5
  SHA512:
6
- metadata.gz: 8ee6d317e49fc873b7f23c5cf47dfcc2b4a80c87556aeebfc307142bb94da6b4af86329ee116b90a08c38cbe844aee637cd8a9e90c8a7f9b360b576a1ff84788
7
- data.tar.gz: 29c025f0a4dbcf30be82293d2dacae042ad53e33b015864278cc5710179add7599be813a55bee2e69bbc371bb0578039480a818ed40a86ca7794c4aae9fb9d63
6
+ metadata.gz: 96e2e509f49563c002ff8f8a0b6c510813fea9b5be9b175fc476f8a4b8e6d4aef5f7a65aefa9ede6104618652fa26891061f63b634abc71a832d0b4f08dcf8fa
7
+ data.tar.gz: aa390a2af81709249571b00dece9663ed946415cc16218fcfdb5fc8872d6f7d1b94b59b40c4634d99adf5d8b3b9a74a1dad77595aa54bd72a2bd973c713120e9
data/.rspec CHANGED
@@ -1,7 +1,3 @@
1
- --format
2
- doc
3
- --order
4
- random
5
- --color
6
- --fail-fast
7
- --backtrace
1
+ --format doc
2
+ --require spec_helper
3
+ --order random
@@ -1,5 +1,7 @@
1
1
  Changelog
2
2
  =========
3
+ v0.4.0 added support for Linode Volumes
4
+ added `vagrant linode volumes list` command
3
5
  v0.3.0 fixes for Vagrant 2.0.1 (now requires Ruby 2.2.0+)
4
6
  xen-only kernels are no longer available (Fixes KVM Grub options)
5
7
  rebuild command warns / quits if Linode is not powered down
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source 'https://rubygems.org'
2
- ruby '~> 2.2.0'
2
+ ruby '>= 2.2.0'
3
3
 
4
4
  group :development do
5
5
  # We depend on Vagrant for development, but we don't add it as a
@@ -10,6 +10,10 @@ group :development do
10
10
  gem 'pry'
11
11
  end
12
12
 
13
+ group :test do
14
+ gem 'rspec-its'
15
+ end
16
+
13
17
  group :plugins do
14
18
  gemspec
15
19
  end
data/README.md CHANGED
@@ -176,9 +176,27 @@ curl -X POST "https://api.linode.com/?api_action=avail.kernels" \
176
176
 
177
177
  More detail: [Linode API - Kernels](https://www.linode.com/api/utility/avail.kernels)
178
178
 
179
+ ### provider.volumes - [Volume Handling](https://www.linode.com/docs/platform/how-to-use-block-storage-with-your-linode/)
180
+
181
+ The plugin can create and attach additional volumes when creating Linodes. `vagrant rebuild` calls will rebuild the VM only and reattach the volume afterwards without losing the contents.
182
+
183
+ ```rb
184
+ config.vm.provider :linode do |linode|
185
+ linode.plan = "Linode 2048"
186
+ linode.volumes = [
187
+ {label: "extra_volume", size: 1},
188
+ ]
189
+ end
190
+ ```
191
+
192
+ NOTES:
193
+ * The volume needs to be formatted and mounted inside the VM either manually or by a StackScript, etc.
194
+ * The plugin doesn't do any volume metadata management. If a volume is renamed the next `vagrant up` call will create a new one.
195
+ * Running `vagrant destroy` will **NOT** destroy the volumes.
196
+
179
197
  ### nfs.functional
180
198
 
181
- The sync provider, NFS, has been disabled to make rsync easier to use. To enable NFS,
199
+ The sync provider, NFS, has been disabled to make rsync easier to use. To enable NFS,
182
200
  run Vagrant with an environment variable `LINODE_NFS_FUNCTIONAL=1`. This will require
183
201
  a bit more configuration between the Linode and the Vagrant host.
184
202
 
@@ -193,7 +211,7 @@ command:
193
211
  This command will create a new linode, setup your SSH key for authentication,
194
212
  create a new user account, and run the provisioners you have configured.
195
213
 
196
- The environment variable `VAGRANT_DEFAULT_PROVIDER` can be set to `linode` to avoid sending `--provider=linode` on each `vagrant up`.
214
+ The environment variable `VAGRANT_DEFAULT_PROVIDER` can be set to `linode` to avoid sending `--provider=linode` on each `vagrant up`.
197
215
 
198
216
  **Supported Commands**
199
217
 
@@ -233,6 +251,18 @@ You can now make modifications. Running `vagrant` within the Bundler
233
251
  environment will ensure that plugins installed in your Vagrant
234
252
  environment are not loaded.
235
253
 
254
+ ### Building and Publishing
255
+
256
+ ```
257
+ vi lib/vagrant-linode/version.rb
258
+ vi CHANGELOG.md
259
+ git commit -m 'version 0.1.2' lib/vagrant-linode/version.rb CHANGELOG.md
260
+ git tag -s v0.1.2
261
+ git push --tags origin master
262
+ gem build vagrant-linode.gemspec
263
+ gem push vagrant-linode-0.1.2.gem
264
+ ```
265
+
236
266
  [![Join the chat at https://gitter.im/displague/vagrant-linode](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/displague/vagrant-linode?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
237
267
  [![Code Climate](https://codeclimate.com/github/displague/vagrant-linode/badges/gpa.svg)](https://codeclimate.com/github/displague/vagrant-linode)
238
268
  [![Test Coverage](https://codeclimate.com/github/displague/vagrant-linode/badges/coverage.svg)](https://codeclimate.com/github/displague/vagrant-linode)
@@ -256,6 +256,14 @@ module VagrantPlugins
256
256
  end
257
257
  end
258
258
 
259
+ def self.action_list_volumes
260
+ Vagrant::Action::Builder.new.tap do |b|
261
+ # b.use ConfigValidate # is this per machine?
262
+ b.use ConnectLinode
263
+ b.use ListVolumes
264
+ end
265
+ end
266
+
259
267
  action_root = Pathname.new(File.expand_path('../actions', __FILE__))
260
268
  autoload :ConnectLinode, action_root.join('connect_linode')
261
269
  autoload :ReadState, action_root.join('read_state')
@@ -284,6 +292,7 @@ module VagrantPlugins
284
292
  autoload :ListDistributions, action_root.join('list_distributions')
285
293
  autoload :ListKernels, action_root.join('list_kernels')
286
294
  autoload :ListDatacenters, action_root.join('list_datacenters')
295
+ autoload :ListVolumes, action_root.join('list_volumes')
287
296
  end
288
297
  end
289
298
  end
@@ -1,4 +1,5 @@
1
1
  require 'log4r'
2
+ require "vagrant-linode/client_wrapper"
2
3
 
3
4
  module VagrantPlugins
4
5
  module Linode
@@ -25,7 +26,7 @@ module VagrantPlugins
25
26
 
26
27
  @logger.info('Connecting to Linode api_url...')
27
28
 
28
- linode = ::LinodeAPI::Retryable.new params
29
+ linode = ClientWrapper.new(::LinodeAPI::Retryable.new(params), env[:ui])
29
30
  env[:linode_api] = linode
30
31
 
31
32
  @app.call(env)
@@ -1,6 +1,7 @@
1
1
  require 'vagrant-linode/helpers/client'
2
2
  require 'vagrant-linode/helpers/waiter'
3
3
  require 'vagrant-linode/errors'
4
+ require 'vagrant-linode/services/volume_manager'
4
5
 
5
6
  module VagrantPlugins
6
7
  module Linode
@@ -122,21 +123,21 @@ module VagrantPlugins
122
123
  datacenterid: datacenter_id,
123
124
  paymentterm: @machine.provider_config.paymentterm || 1
124
125
  )
125
- env[:ui].info I18n.t('vagrant_linode.info.created', linodeid: result['linodeid'], label: (@machine.provider_config.label or "linode#{result['linodeid']}"))
126
+ @machine.id = result['linodeid'].to_s
127
+ env[:ui].info I18n.t('vagrant_linode.info.created', linodeid: @machine.id, label: (@machine.provider_config.label or "linode#{@machine.id}"))
126
128
 
127
- # @client.linode.job.list(:linodeid => result['linodeid'], :pendingonly => 1)
129
+ # @client.linode.job.list(:linodeid => @machine.id, :pendingonly => 1)
128
130
  # assign the machine id for reference in other commands
129
- @machine.id = result['linodeid'].to_s
130
131
 
131
132
  disklist = []
132
133
 
133
134
  if stackscript_id
134
135
  disk = @client.linode.disk.createfromstackscript(
135
- linodeid: result['linodeid'],
136
+ linodeid: @machine.id,
136
137
  stackscriptid: stackscript_id,
137
138
  stackscriptudfresponses: JSON.dump(stackscript_udf_responses),
138
139
  distributionid: distribution_id,
139
- label: 'Vagrant Disk Distribution ' + distribution_id.to_s + ' Linode ' + result['linodeid'].to_s,
140
+ label: 'Vagrant Disk Distribution ' + distribution_id.to_s + ' Linode ' + @machine.id,
140
141
  type: 'ext4',
141
142
  size: xvda_size,
142
143
  rootsshkey: pubkey,
@@ -145,9 +146,9 @@ module VagrantPlugins
145
146
  disklist.push(disk['diskid'])
146
147
  elsif distribution_id
147
148
  disk = @client.linode.disk.createfromdistribution(
148
- linodeid: result['linodeid'],
149
+ linodeid: @machine.id,
149
150
  distributionid: distribution_id,
150
- label: 'Vagrant Disk Distribution ' + distribution_id.to_s + ' Linode ' + result['linodeid'].to_s,
151
+ label: 'Vagrant Disk Distribution ' + distribution_id.to_s + ' Linode ' + @machine.id,
151
152
  type: 'ext4',
152
153
  size: xvda_size,
153
154
  rootsshkey: pubkey,
@@ -156,9 +157,9 @@ module VagrantPlugins
156
157
  disklist.push(disk['diskid'])
157
158
  elsif image_id
158
159
  disk = @client.linode.disk.createfromimage(
159
- linodeid: result['linodeid'],
160
+ linodeid: @machine.id,
160
161
  imageid: image_id,
161
- label: 'Vagrant Disk Image (' + image_id.to_s + ') for ' + result['linodeid'].to_s,
162
+ label: 'Vagrant Disk Image (' + image_id.to_s + ') for ' + @machine.id,
162
163
  size: xvda_size,
163
164
  rootsshkey: pubkey,
164
165
  rootpass: root_pass
@@ -170,7 +171,7 @@ module VagrantPlugins
170
171
 
171
172
  if swap_size > 0
172
173
  swap = @client.linode.disk.create(
173
- linodeid: result['linodeid'],
174
+ linodeid: @machine.id,
174
175
  label: 'Vagrant swap',
175
176
  type: 'swap',
176
177
  size: swap_size
@@ -183,8 +184,8 @@ module VagrantPlugins
183
184
  if xvdc_size > 0
184
185
  xvdc_type = @machine.provider_config.xvdc_type.is_a?(Vagrant::Config::V2::DummyConfig) ? "raw" : @machine.provider_config.xvdc_type
185
186
  xvdc = @client.linode.disk.create(
186
- linodeid: result['linodeid'],
187
- label: 'Vagrant Leftover Disk Linode ' + result['linodeid'].to_s,
187
+ linodeid: @machine.id,
188
+ label: 'Vagrant Leftover Disk Linode ' + @machine.id,
188
189
  type: xvdc_type,
189
190
  size: xvdc_size,
190
191
  )
@@ -194,7 +195,7 @@ module VagrantPlugins
194
195
  end
195
196
 
196
197
  config = @client.linode.config.create(
197
- linodeid: result['linodeid'],
198
+ linodeid: @machine.id,
198
199
  label: 'Vagrant Config',
199
200
  disklist: disklist.join(','),
200
201
  kernelid: kernel_id
@@ -202,7 +203,7 @@ module VagrantPlugins
202
203
 
203
204
  # @todo: allow provisioning to set static configuration for networking
204
205
  if @machine.provider_config.private_networking
205
- private_network = @client.linode.ip.addprivate linodeid: result['linodeid']
206
+ private_network = @client.linode.ip.addprivate linodeid: @machine.id
206
207
  end
207
208
 
208
209
  label = @machine.provider_config.label
@@ -212,16 +213,18 @@ module VagrantPlugins
212
213
  group = @machine.provider_config.group
213
214
  group = "" if @machine.provider_config.group == false
214
215
 
216
+ Services::VolumeManager.new(@machine, @client.volume, env[:ui]).perform
217
+
215
218
  result = @client.linode.update(
216
- linodeid: result['linodeid'],
219
+ linodeid: @machine.id,
217
220
  label: label,
218
221
  lpm_displaygroup: group
219
222
  )
220
223
 
221
- env[:ui].info I18n.t('vagrant_linode.info.booting', linodeid: result['linodeid'])
224
+ env[:ui].info I18n.t('vagrant_linode.info.booting', linodeid: @machine.id)
222
225
 
223
- bootjob = @client.linode.boot linodeid: result['linodeid']
224
- # sleep 1 until ! @client.linode.job.list(:linodeid => result['linodeid'], :jobid => bootjob['jobid'], :pendingonly => 1).length
226
+ bootjob = @client.linode.boot linodeid: @machine.id
227
+ # sleep 1 until ! @client.linode.job.list(:linodeid => @machine.id, :jobid => bootjob['jobid'], :pendingonly => 1).length
225
228
  wait_for_event(env, bootjob['jobid'])
226
229
 
227
230
  # refresh linode state with provider and output ip address
@@ -0,0 +1,50 @@
1
+ module VagrantPlugins
2
+ module Linode
3
+ module Actions
4
+ class ListVolumes
5
+ def initialize(app, _env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ api = env[:linode_api]
11
+ logger = env[:ui]
12
+ machine = env[:machine]
13
+
14
+ remote_volumes = api.volume.list
15
+ volume_definitions = machine.provider_config.volumes
16
+
17
+ volume_definitions.each do |volume|
18
+ volume_label = "#{machine.name}_#{volume[:label]}"
19
+ remote_volume = remote_volumes.find { |v| v.label == volume_label }
20
+
21
+ if remote_volume.nil?
22
+ logger.info format_volume(volume_label, "does not exist")
23
+ next
24
+ end
25
+
26
+ logger.info format_volume(volume_label, volume_state(machine, remote_volume))
27
+ end
28
+
29
+ @app.call(env)
30
+ end
31
+
32
+ private
33
+
34
+ def volume_state(machine, volume)
35
+ if volume.linodeid.to_s == machine.id
36
+ "attached"
37
+ elsif volume.linodeid == 0
38
+ "detached"
39
+ else
40
+ "attached to other VM"
41
+ end
42
+ end
43
+
44
+ def format_volume(label, state)
45
+ "volume \"%s\": %s" % [label, state]
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,6 +1,7 @@
1
1
  require 'vagrant-linode/helpers/client'
2
2
  require 'vagrant-linode/helpers/waiter'
3
3
  require 'vagrant-linode/errors'
4
+ require 'vagrant-linode/services/volume_manager'
4
5
 
5
6
  module VagrantPlugins
6
7
  module Linode
@@ -101,7 +102,7 @@ module VagrantPlugins
101
102
  fail Errors::PlanID, plan: @machine.provider_config.planid if plan.nil?
102
103
  plan_id = @machine.provider_config.planid
103
104
  end
104
-
105
+
105
106
  ### Disk Images
106
107
  xvda_size, swap_size, disk_sanity = @machine.provider_config.xvda_size, @machine.provider_config.swap_size, true
107
108
 
@@ -143,7 +144,7 @@ module VagrantPlugins
143
144
  jobid: job
144
145
  )
145
146
 
146
- while jobStatus[0]['host_finish_dt'].nil? || jobStatus[0]['host_finish_dt'].empty? do
147
+ while jobStatus[0]['host_finish_dt'].nil? || jobStatus[0]['host_finish_dt'].empty? do
147
148
  sleep(5)
148
149
  jobStatus = @client.linode.job.list(
149
150
  linodeid: @machine.id,
@@ -238,6 +239,8 @@ module VagrantPlugins
238
239
  group = @machine.provider_config.group
239
240
  group = "" if @machine.provider_config.group == false
240
241
 
242
+ Services::VolumeManager.new(@machine, @client.volume, env[:ui]).perform
243
+
241
244
  result = @client.linode.update(
242
245
  linodeid: @machine.id,
243
246
  label: label,
@@ -276,7 +279,7 @@ module VagrantPlugins
276
279
 
277
280
  @app.call(env)
278
281
  end
279
-
282
+
280
283
  def get_server_name
281
284
  "vagrant_linode-#{rand.to_s.split('.')[1]}"
282
285
  end
@@ -0,0 +1,25 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module Linode
5
+ class ClientWrapper
6
+ def initialize(client, logger)
7
+ @client = client
8
+ @logger = logger
9
+ end
10
+
11
+ def method_missing(method, *args, &block)
12
+ result = @client.send(method, *args, &block)
13
+
14
+ if result.is_a? LinodeAPI::Retryable
15
+ self.class.new(result, @logger)
16
+ else
17
+ result
18
+ end
19
+ rescue ::LinodeAPI::APIError => e
20
+ @logger.error e.details.inspect
21
+ raise
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module Linode
3
+ module Commands
4
+ class ListVolumes < Vagrant.plugin('2', :command)
5
+ def execute
6
+ opts = OptionParser.new do |o|
7
+ o.banner = 'Usage: vagrant linode volumes list [options]'
8
+ end
9
+
10
+ argv = parse_options(opts)
11
+ return unless argv
12
+
13
+ with_target_vms(argv) do |machine|
14
+ machine.action(:list_volumes)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -40,6 +40,10 @@ module VagrantPlugins
40
40
  require File.expand_path('../servers', __FILE__)
41
41
  Servers
42
42
  end
43
+ @subcommands.register(:volumes) do
44
+ require File.expand_path('../volumes', __FILE__)
45
+ Volumes
46
+ end
43
47
 
44
48
  super(argv, env)
45
49
  end
@@ -0,0 +1,55 @@
1
+ module VagrantPlugins
2
+ module Linode
3
+ module Commands
4
+ class Volumes < Vagrant.plugin('2', :command)
5
+ def initialize(argv, env)
6
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
7
+
8
+ @subcommands = Vagrant::Registry.new
9
+ @subcommands.register(:list) do
10
+ require File.expand_path('../list_volumes', __FILE__)
11
+ ListVolumes
12
+ end
13
+
14
+ super(argv, env)
15
+ end
16
+
17
+ def execute
18
+ if @main_args.include?('-h') || @main_args.include?('--help')
19
+ # Print the help for all the rackspace commands.
20
+ return help
21
+ end
22
+
23
+ command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
24
+ return help if !command_class || !@sub_command
25
+ @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
26
+
27
+ # Initialize and execute the command class
28
+ command_class.new(@sub_args, @env).execute
29
+ end
30
+
31
+ def help
32
+ opts = OptionParser.new do |opts|
33
+ opts.banner = 'Usage: vagrant linode volumes <subcommand> [<args>]'
34
+ opts.separator ''
35
+ opts.separator 'Available subcommands:'
36
+
37
+ # Add the available subcommands as separators in order to print them
38
+ # out as well.
39
+ keys = []
40
+ @subcommands.each { |key, _value| keys << key.to_s }
41
+
42
+ keys.sort.each do |key|
43
+ opts.separator " #{key}"
44
+ end
45
+
46
+ opts.separator ''
47
+ opts.separator 'For help on any individual subcommand run `vagrant linode volumes <subcommand> -h`'
48
+ end
49
+
50
+ @env.ui.info(opts.help, prefix: false)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -26,6 +26,7 @@ module VagrantPlugins
26
26
  attr_accessor :kernel
27
27
  attr_accessor :label
28
28
  attr_accessor :group
29
+ attr_accessor :volumes
29
30
 
30
31
  alias_method :setup?, :setup
31
32
 
@@ -57,6 +58,7 @@ module VagrantPlugins
57
58
  @kernel = UNSET_VALUE
58
59
  @label = UNSET_VALUE
59
60
  @group = UNSET_VALUE
61
+ @volumes = UNSET_VALUE
60
62
  end
61
63
 
62
64
  def finalize!
@@ -90,6 +92,7 @@ module VagrantPlugins
90
92
  @kernel = 'Latest 64 bit' if @kernel.nil? and @kernelid.nil?
91
93
  @label = false if @label == UNSET_VALUE
92
94
  @group = false if @group == UNSET_VALUE
95
+ @volumes = [] if @volumes == UNSET_VALUE
93
96
  end
94
97
 
95
98
  def validate(machine)
@@ -134,6 +137,10 @@ module VagrantPlugins
134
137
  errors << I18n.t('vagrant_linode.config.distribution_or_image')
135
138
  end
136
139
 
140
+ if !@volumes.is_a? Array
141
+ errors << I18n.t("vagrant_linode.config.volumes")
142
+ end
143
+
137
144
  { 'Linode Provider' => errors }
138
145
  end
139
146
  end
@@ -20,7 +20,7 @@ module VagrantPlugins
20
20
  class DatacenterMatch < LinodeError
21
21
  error_key(:datacenter_match)
22
22
  end
23
-
23
+
24
24
  class ImageMatch < LinodeError
25
25
  error_key(:image_match)
26
26
  end
@@ -64,6 +64,14 @@ module VagrantPlugins
64
64
  class StackscriptUDFFormat < LinodeError
65
65
  error_key(:stackscript_udf_responses)
66
66
  end
67
+
68
+ class VolumeSizeMissing < LinodeError
69
+ error_key(:volume_size_missing)
70
+ end
71
+
72
+ class VolumeLabelMissing < LinodeError
73
+ error_key(:volume_label_missing)
74
+ end
67
75
  end
68
76
  end
69
77
  end
@@ -0,0 +1,59 @@
1
+ require "vagrant-linode/errors"
2
+
3
+ module VagrantPlugins
4
+ module Linode
5
+ module Services
6
+ class VolumeManager
7
+ def initialize(machine, api, logger)
8
+ @machine = machine
9
+ @volumes_api = api
10
+ @logger = logger
11
+ end
12
+
13
+ def perform
14
+ volume_definitions.each do |volume|
15
+ raise Errors::VolumeLabelMissing if volume[:label].to_s.empty?
16
+
17
+ volume_name = "#{@machine.name}_#{volume[:label]}"
18
+
19
+ remote_volume = remote_volumes.find { |v| v.label == volume_name }
20
+ if remote_volume
21
+ attach_volume(remote_volume)
22
+ else
23
+ create_and_attach_volume(volume_name, volume[:size])
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def volume_definitions
31
+ @machine.provider_config.volumes
32
+ end
33
+
34
+ def remote_volumes
35
+ @_remote_volumes ||= @volumes_api.list
36
+ end
37
+
38
+ def attach_volume(volume)
39
+ @volumes_api.update(
40
+ volumeid: volume.volumeid,
41
+ linodeid: @machine.id
42
+ )
43
+ @logger.info "volume #{volume.label} attached"
44
+ end
45
+
46
+ def create_and_attach_volume(label, size)
47
+ raise Errors::VolumeSizeMissing unless size.to_i > 0
48
+
49
+ @volumes_api.create(
50
+ label: label,
51
+ size: size,
52
+ linodeid: @machine.id
53
+ )
54
+ @logger.info "volume #{label} created and attached"
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Linode
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -52,6 +52,7 @@ en:
52
52
  kernelid_or_kernel: "Use either kernelid or kernel, not both"
53
53
  imageid_or_image: "Use either imageid or image, not both"
54
54
  distribution_or_image: "Distribution can not be specified with Image options"
55
+ volumes: "Volumes must be an array of disks"
55
56
  errors:
56
57
  public_key: |-
57
58
  There was an issue reading the public key at:
@@ -133,3 +134,5 @@ en:
133
134
  Supported distributions can be found at the following url - https://manager.linode.com/stackscripts
134
135
  stackscript_udf_responses: !-
135
136
  The stackscript UDF responses object provided is of the wrong type. It should be a Hash.
137
+ volume_size_missing: For volumes that need to be created the size has to be specified.
138
+ volume_label_missing: You must specify a volume label.
@@ -1,10 +1,10 @@
1
1
  if ENV['COVERAGE'] != 'false'
2
2
  require 'simplecov'
3
3
  require 'coveralls'
4
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
5
5
  SimpleCov::Formatter::HTMLFormatter,
6
6
  Coveralls::SimpleCov::Formatter
7
- ]
7
+ ])
8
8
  SimpleCov.start
9
9
 
10
10
  # Normally classes are lazily loaded, so any class without a test
@@ -17,4 +17,8 @@ if ENV['COVERAGE'] != 'false'
17
17
  end
18
18
  end
19
19
 
20
- require 'linode'
20
+ require 'pry'
21
+ require 'rspec/its'
22
+
23
+ I18n.load_path << 'locales/en.yml'
24
+ I18n.reload!
@@ -0,0 +1,42 @@
1
+ require "vagrant-linode/services/volume_manager"
2
+
3
+ describe VagrantPlugins::Linode::Services::VolumeManager do
4
+ subject { described_class.new(machine, client, logger) }
5
+ let(:provider_config) { double(:config, volumes: [{label: "testvolume", size: 3}]) }
6
+ let(:machine) { double(:machine, id: 123, name: "test", provider_config: provider_config) }
7
+ let(:logger) { double(:logger, info: nil) }
8
+ let(:remote_volumes) { [double(:volume, volumeid: 234, size: 3, label: "test_testvolume")] }
9
+ let(:client) { double(:api, list: remote_volumes) }
10
+
11
+ describe "#perform" do
12
+ context "when the volume label is not specified" do
13
+ let(:provider_config) { double(:config, volumes: [{size: 3}]) }
14
+ it "raises an error" do
15
+ expect { subject.perform }.to raise_error "You must specify a volume label."
16
+ end
17
+ end
18
+
19
+ context "when the remote volume does not exist" do
20
+ let(:remote_volumes) { [] }
21
+ it "creates the volume bound to the linode" do
22
+ expect(client).to receive(:create).with(label: "test_testvolume", size: 3, linodeid: 123)
23
+ subject.perform
24
+ end
25
+
26
+ context "when the size is not specified" do
27
+ let(:provider_config) { double(:config, volumes: [{label: "testvolume"}]) }
28
+ it "raises an error" do
29
+ expect { subject.perform }.to raise_error "For volumes that need to be created the size has to be specified."
30
+ end
31
+ end
32
+ end
33
+
34
+ context "when the remote volume exists" do
35
+ let(:remote_volumes) { [double(:volume, volumeid: 234, size: 3, label: "test_testvolume")] }
36
+ it "attaches the volume to the machine" do
37
+ expect(client).to receive(:update).with(volumeid: 234, linodeid: 123)
38
+ subject.perform
39
+ end
40
+ end
41
+ end
42
+ end
@@ -2,14 +2,14 @@
2
2
  # vi: set ft=ruby :
3
3
 
4
4
  Vagrant.configure('2') do |config|
5
- #config.ssh.username = 'tester'
6
- config.ssh.private_key_path = '~/.ssh/id_rsa'
5
+ config.ssh.username = 'tester'
6
+ config.ssh.private_key_path = './test_id_rsa'
7
7
 
8
- #config.vm.synced_folder '.', '/vagrant', disabled: true
9
- config.vm.network 'forwarded_port', guest: 8080, host: 80
8
+ config.vm.synced_folder '.', '/vagrant', disabled: true
10
9
 
11
10
  config.vm.provider :linode do |provider, override|
12
11
  override.vm.box = 'linode'
12
+ override.vm.box_url = 'https://github.com/displague/vagrant-linode/raw/master/box/linode.box'
13
13
  provider.api_key = ENV['LINODE_API_KEY']
14
14
  provider.ssh_key_name = 'Test Key'
15
15
  provider.distribution = 'Debian 8'
@@ -17,7 +17,6 @@ Vagrant.configure('2') do |config|
17
17
  provider.plan = '2048'
18
18
  provider.label = 'vagrant-'+Time.new.strftime("%F%T").gsub(/[^0-9]/,'')
19
19
 
20
-
21
20
  # Disk Image Sizes (Optional configuration)
22
21
 
23
22
  # Main Disk Image Size
@@ -40,18 +39,17 @@ Vagrant.configure('2') do |config|
40
39
  # provider.private_networking = true
41
40
  end
42
41
 
43
- #config.vm.provision :shell, path: 'scripts/provision.sh'
42
+ config.vm.provision :shell, path: 'scripts/provision.sh'
44
43
 
45
- #config.vm.provision :chef_solo do |chef|
46
- # chef.cookbooks_path = 'cookbooks'
47
- # chef.add_recipe 'test'
48
- #end
44
+ config.vm.provision :chef_solo do |chef|
45
+ chef.cookbooks_path = 'cookbooks'
46
+ chef.add_recipe 'test'
47
+ end
49
48
 
50
49
  # Linode Specific Configurations
51
50
  config.vm.define :ubuntu do |ubuntu|
52
51
  ubuntu.vm.provider :linode do |provider|
53
- provider.distribution = 'Ubuntu 16.04'
54
- config.vm.provision :shell, inline: 'sudo apt-get install -y apache2'
52
+ provider.distribution = 'Ubuntu 14.04 LTS'
55
53
 
56
54
  # Optional Settings
57
55
  provider.label = 'Vagrant-Ubuntu'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-linode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marques Johansson
@@ -9,62 +9,62 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-11-19 00:00:00.000000000 Z
12
+ date: 2017-12-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: linodeapi
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ~>
19
19
  - !ruby/object:Gem::Version
20
20
  version: 2.0.1
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: 2.0.1
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: log4r
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ~>
33
33
  - !ruby/object:Gem::Version
34
34
  version: '1.1'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ~>
40
40
  - !ruby/object:Gem::Version
41
41
  version: '1.1'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ~>
47
47
  - !ruby/object:Gem::Version
48
48
  version: '12.0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - ~>
54
54
  - !ruby/object:Gem::Version
55
55
  version: '12.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - "~>"
60
+ - - ~>
61
61
  - !ruby/object:Gem::Version
62
62
  version: '3.5'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - "~>"
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
69
  version: '3.5'
70
70
  description: Enables Vagrant to manage Linode linodes
@@ -75,10 +75,10 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
- - ".gitignore"
79
- - ".rspec"
80
- - ".rubocop.yml"
81
- - ".rubocop_todo.yml"
78
+ - .gitignore
79
+ - .rspec
80
+ - .rubocop.yml
81
+ - .rubocop_todo.yml
82
82
  - CHANGELOG.md
83
83
  - Gemfile
84
84
  - LICENSE.txt
@@ -104,6 +104,7 @@ files:
104
104
  - lib/vagrant-linode/actions/list_kernels.rb
105
105
  - lib/vagrant-linode/actions/list_plans.rb
106
106
  - lib/vagrant-linode/actions/list_servers.rb
107
+ - lib/vagrant-linode/actions/list_volumes.rb
107
108
  - lib/vagrant-linode/actions/message_already_active.rb
108
109
  - lib/vagrant-linode/actions/message_already_off.rb
109
110
  - lib/vagrant-linode/actions/message_not_created.rb
@@ -119,17 +120,20 @@ files:
119
120
  - lib/vagrant-linode/actions/setup_hostname.rb
120
121
  - lib/vagrant-linode/actions/setup_sudo.rb
121
122
  - lib/vagrant-linode/actions/setup_user.rb
123
+ - lib/vagrant-linode/client_wrapper.rb
122
124
  - lib/vagrant-linode/commands/create_image.rb
123
125
  - lib/vagrant-linode/commands/datacenters.rb
124
126
  - lib/vagrant-linode/commands/distributions.rb
125
127
  - lib/vagrant-linode/commands/images.rb
126
128
  - lib/vagrant-linode/commands/kernels.rb
127
129
  - lib/vagrant-linode/commands/list_images.rb
130
+ - lib/vagrant-linode/commands/list_volumes.rb
128
131
  - lib/vagrant-linode/commands/networks.rb
129
132
  - lib/vagrant-linode/commands/plans.rb
130
133
  - lib/vagrant-linode/commands/rebuild.rb
131
134
  - lib/vagrant-linode/commands/root.rb
132
135
  - lib/vagrant-linode/commands/servers.rb
136
+ - lib/vagrant-linode/commands/volumes.rb
133
137
  - lib/vagrant-linode/config.rb
134
138
  - lib/vagrant-linode/errors.rb
135
139
  - lib/vagrant-linode/helpers/client.rb
@@ -137,12 +141,14 @@ files:
137
141
  - lib/vagrant-linode/helpers/waiter.rb
138
142
  - lib/vagrant-linode/plugin.rb
139
143
  - lib/vagrant-linode/provider.rb
144
+ - lib/vagrant-linode/services/volume_manager.rb
140
145
  - lib/vagrant-linode/version.rb
141
146
  - locales/en.yml
142
147
  - spec/spec_helper.rb
143
148
  - spec/vagrant-linode/actions/list_distributions_spec.rb
144
149
  - spec/vagrant-linode/actions/list_plans_spec.rb
145
150
  - spec/vagrant-linode/config_spec.rb
151
+ - spec/vagrant-linode/services/volume_manager_spec.rb
146
152
  - test/Vagrantfile
147
153
  - test/cookbooks/test/recipes/default.rb
148
154
  - test/scripts/provision.sh
@@ -160,17 +166,17 @@ require_paths:
160
166
  - lib
161
167
  required_ruby_version: !ruby/object:Gem::Requirement
162
168
  requirements:
163
- - - ">="
169
+ - - '>='
164
170
  - !ruby/object:Gem::Version
165
171
  version: '0'
166
172
  required_rubygems_version: !ruby/object:Gem::Requirement
167
173
  requirements:
168
- - - ">="
174
+ - - '>='
169
175
  - !ruby/object:Gem::Version
170
176
  version: '0'
171
177
  requirements: []
172
178
  rubyforge_project:
173
- rubygems_version: 2.4.5.3
179
+ rubygems_version: 2.6.13
174
180
  signing_key:
175
181
  specification_version: 4
176
182
  summary: Enables Vagrant to manage Linode linodes
@@ -179,6 +185,7 @@ test_files:
179
185
  - spec/vagrant-linode/actions/list_distributions_spec.rb
180
186
  - spec/vagrant-linode/actions/list_plans_spec.rb
181
187
  - spec/vagrant-linode/config_spec.rb
188
+ - spec/vagrant-linode/services/volume_manager_spec.rb
182
189
  - test/Vagrantfile
183
190
  - test/cookbooks/test/recipes/default.rb
184
191
  - test/scripts/provision.sh