vagrant-linode 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rspec +4 -0
  4. data/.rubocop.yml +1 -0
  5. data/.rubocop_todo.yml +164 -0
  6. data/Gemfile +9 -6
  7. data/README.md +21 -9
  8. data/Rakefile +21 -1
  9. data/Vagrantfile.multi +18 -0
  10. data/box/linode-debian-7.5.box +0 -0
  11. data/box/linode.box +0 -0
  12. data/box/metadata-debian-7.5.json +12 -0
  13. data/box/metadata.json +2 -2
  14. data/features/provision.feature +34 -0
  15. data/features/steps/sdk_steps.rb +13 -0
  16. data/features/steps/server_steps.rb +25 -0
  17. data/features/support/env.rb +34 -0
  18. data/features/support/fog_mock.rb +16 -0
  19. data/features/vagrant-linode.feature +68 -0
  20. data/lib/vagrant-linode.rb +44 -5
  21. data/lib/vagrant-linode/actions.rb +201 -87
  22. data/lib/vagrant-linode/actions/connect_linode.rb +36 -0
  23. data/lib/vagrant-linode/actions/create.rb +9 -9
  24. data/lib/vagrant-linode/actions/create_image.rb +23 -0
  25. data/lib/vagrant-linode/actions/destroy.rb +1 -3
  26. data/lib/vagrant-linode/actions/halt.rb +29 -0
  27. data/lib/vagrant-linode/actions/is_created.rb +16 -0
  28. data/lib/vagrant-linode/actions/is_stopped.rb +17 -0
  29. data/lib/vagrant-linode/actions/list_datacenters.rb +20 -0
  30. data/lib/vagrant-linode/actions/list_distributions.rb +20 -0
  31. data/lib/vagrant-linode/actions/list_images.rb +20 -0
  32. data/lib/vagrant-linode/actions/list_plans.rb +20 -0
  33. data/lib/vagrant-linode/actions/list_servers.rb +20 -0
  34. data/lib/vagrant-linode/actions/message_already_active.rb +16 -0
  35. data/lib/vagrant-linode/actions/message_already_off.rb +16 -0
  36. data/lib/vagrant-linode/actions/message_not_created.rb +16 -0
  37. data/lib/vagrant-linode/actions/message_off.rb +16 -0
  38. data/lib/vagrant-linode/actions/power_off.rb +4 -3
  39. data/lib/vagrant-linode/actions/power_on.rb +3 -2
  40. data/lib/vagrant-linode/actions/read_ssh_info.rb +48 -0
  41. data/lib/vagrant-linode/actions/read_state.rb +38 -0
  42. data/lib/vagrant-linode/actions/rebuild.rb +3 -2
  43. data/lib/vagrant-linode/actions/reload.rb +3 -2
  44. data/lib/vagrant-linode/commands/create_image.rb +21 -0
  45. data/lib/vagrant-linode/commands/datacenters.rb +21 -0
  46. data/lib/vagrant-linode/commands/distributions.rb +21 -0
  47. data/lib/vagrant-linode/commands/images.rb +59 -0
  48. data/lib/vagrant-linode/commands/list_images.rb +21 -0
  49. data/lib/vagrant-linode/commands/networks.rb +21 -0
  50. data/lib/vagrant-linode/commands/plans.rb +21 -0
  51. data/lib/vagrant-linode/commands/root.rb +81 -0
  52. data/lib/vagrant-linode/commands/servers.rb +21 -0
  53. data/lib/vagrant-linode/config.rb +11 -3
  54. data/lib/vagrant-linode/helpers/client.rb +21 -79
  55. data/lib/vagrant-linode/helpers/waiter.rb +21 -0
  56. data/lib/vagrant-linode/plugin.rb +20 -0
  57. data/lib/vagrant-linode/provider.rb +27 -32
  58. data/lib/vagrant-linode/version.rb +1 -1
  59. data/locales/en.yml +17 -1
  60. data/spec/spec_helper.rb +20 -0
  61. data/spec/vagrant-linode/actions/list_distributions_spec.rb +47 -0
  62. data/spec/vagrant-linode/actions/list_plans_spec.rb +47 -0
  63. data/spec/vagrant-linode/config_spec.rb +189 -0
  64. data/test/Vagrantfile +4 -9
  65. data/vagrant-linode.gemspec +1 -1
  66. metadata +70 -20
  67. data/lib/vagrant-linode/actions/check_state.rb +0 -19
  68. data/lib/vagrant-linode/actions/setup_key.rb +0 -52
@@ -0,0 +1,16 @@
1
+ require 'fog'
2
+ if ENV['LINODE_MOCK'] == 'true'
3
+ Fog.mock!
4
+ Fog::Linode::MockData.configure do |c|
5
+ c[:image_name_generator] = proc { 'Ubuntu' }
6
+ c[:ipv4_generator] = proc { '10.11.12.2' }
7
+ end
8
+ connect_options = {
9
+ provider: 'linode',
10
+ linode_api_key: ENV['LINODE_API_KEY'],
11
+ }
12
+ connect_options.merge!(proxy_options) unless ENV['https_proxy'].nil?
13
+ compute = Fog::Compute.new(connect_options)
14
+ # Force creation of Ubuntu image so it will show up in compute.images.list
15
+ compute.images.get(0)
16
+ end
@@ -0,0 +1,68 @@
1
+ @announce
2
+ @vagrant-linode
3
+ Feature: vagrant-linode fog tests
4
+ As a Fog developer
5
+ I want to smoke (or "fog") test vagrant-linode.
6
+ So I am confident my upstream changes did not create downstream problems.
7
+
8
+ Background:
9
+ Given I have Rackspace credentials available
10
+ And I have a "fog_mock.rb" file
11
+
12
+ Scenario: Create a single server (region)
13
+ Given a file named "Vagrantfile" with:
14
+ """
15
+ # Testing options
16
+ require File.expand_path '../fog_mock', __FILE__
17
+
18
+ Vagrant.configure("2") do |config|
19
+ # dev/test method of loading plugin, normally would be 'vagrant plugin install vagrant-linode'
20
+ Vagrant.require_plugin "vagrant-linode"
21
+
22
+ config.vm.box = "dummy"
23
+ config.ssh.username = "vagrant" if Fog.mock?
24
+ config.ssh.private_key_path = "~/.ssh/id_rsa" unless Fog.mock?
25
+
26
+ config.vm.provider :linode do |provider|
27
+ provider.server_name = 'vagrant-single-server'
28
+ provider.api_key = ENV['LINODE_API_KEY']
29
+ linode.datacenter = ENV['LINODE_DATACENTER'].downcase.to_sym
30
+ linode.plan = /Linode 1024/
31
+ linode.distribution = /Ubuntu/
32
+ linode.public_key_path = "~/.ssh/id_rsa.pub" unless Fog.mock?
33
+ end
34
+ end
35
+ """
36
+ When I successfully run `bundle exec vagrant up --provider linode`
37
+ # I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
38
+ # And I get the server from "Instance ID:"
39
+ Then the server "vagrant-single-server" should be active
40
+
41
+ Scenario: Create a single server (linode_compute_url)
42
+ Given a file named "Vagrantfile" with:
43
+ """
44
+ # Testing options
45
+ require File.expand_path '../fog_mock', __FILE__
46
+
47
+ Vagrant.configure("2") do |config|
48
+ # dev/test method of loading plugin, normally would be 'vagrant plugin install vagrant-linode'
49
+ Vagrant.require_plugin "vagrant-linode"
50
+
51
+ config.vm.box = "dummy"
52
+ config.ssh.username = "vagrant" if Fog.mock?
53
+ config.ssh.private_key_path = "~/.ssh/id_rsa" unless Fog.mock?
54
+
55
+ config.vm.provider :linode do |provider|
56
+ provider.server_name = 'vagrant-single-server'
57
+ provider.api_key = ENV['LINODE_API_KEY']
58
+ provider.api_url = "https://api.linode.com/"
59
+ provider.plan = /Linode 1024/
60
+ provider.distribution = /Ubuntu/
61
+ provider.public_key_path = "~/.ssh/id_rsa.pub" unless Fog.mock?
62
+ end
63
+ end
64
+ """
65
+ When I successfully run `bundle exec vagrant up --provider linode`
66
+ # I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
67
+ # And I get the server from "Instance ID:"
68
+ Then the server "vagrant-single-server" should be active
@@ -1,9 +1,51 @@
1
- require 'vagrant-linode/version'
1
+ require 'pathname'
2
+
2
3
  require 'vagrant-linode/plugin'
3
- require 'vagrant-linode/errors'
4
4
 
5
5
  module VagrantPlugins
6
6
  module Linode
7
+ lib_path = Pathname.new(File.expand_path('../vagrant-linode', __FILE__))
8
+ autoload :Errors, lib_path.join('errors')
9
+
10
+ # This initializes the i18n load path so that the plugin-specific
11
+ # translations work.
12
+ def self.init_i18n
13
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
14
+ I18n.reload!
15
+ end
16
+
17
+ # This initializes the logging so that our logs are outputted at
18
+ # the same level as Vagrant core logs.
19
+ def self.init_logging
20
+ # Initialize logging
21
+ level = nil
22
+ begin
23
+ level = Log4r.const_get(ENV['VAGRANT_LOG'].upcase)
24
+ rescue NameError
25
+ # This means that the logging constant wasn't found,
26
+ # which is fine. We just keep `level` as `nil`. But
27
+ # we tell the user.
28
+ level = nil
29
+ end
30
+
31
+ # Some constants, such as "true" resolve to booleans, so the
32
+ # above error checking doesn't catch it. This will check to make
33
+ # sure that the log level is an integer, as Log4r requires.
34
+ level = nil unless level.is_a?(Integer)
35
+
36
+ # Set the logging level on all "vagrant" namespaced
37
+ # logs as long as we have a valid level.
38
+ if level
39
+ logger = Log4r::Logger.new('vagrant_linode')
40
+ logger.outputters = Log4r::Outputter.stderr
41
+ logger.level = level
42
+ logger = nil
43
+ end
44
+ end
45
+
46
+ # This returns the path to the source of this plugin.
47
+ #
48
+ # @return [Pathname]
7
49
  def self.source_root
8
50
  @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
9
51
  end
@@ -13,8 +55,5 @@ module VagrantPlugins
13
55
  rescue
14
56
  raise Errors::PublicKeyError, path: "#{private_key_path}.pub"
15
57
  end
16
-
17
- I18n.load_path << File.expand_path('locales/en.yml', source_root)
18
- I18n.reload!
19
58
  end
20
59
  end
@@ -1,32 +1,22 @@
1
- require 'vagrant-linode/actions/check_state'
2
- require 'vagrant-linode/actions/create'
3
- require 'vagrant-linode/actions/destroy'
4
- require 'vagrant-linode/actions/power_off'
5
- require 'vagrant-linode/actions/power_on'
6
- require 'vagrant-linode/actions/rebuild'
7
- require 'vagrant-linode/actions/reload'
8
- require 'vagrant-linode/actions/setup_hostname'
9
- require 'vagrant-linode/actions/setup_user'
10
- require 'vagrant-linode/actions/setup_sudo'
11
- require 'vagrant-linode/actions/setup_key'
12
- require 'vagrant-linode/actions/sync_folders'
13
- require 'vagrant-linode/actions/modify_provision_path'
1
+ require 'pathname'
2
+
3
+ require 'vagrant/action/builder'
14
4
 
15
5
  module VagrantPlugins
16
6
  module Linode
17
7
  module Actions
18
8
  include Vagrant::Action::Builtin
19
9
 
20
- def self.destroy
10
+ def self.action_destroy
21
11
  Vagrant::Action::Builder.new.tap do |builder|
22
12
  builder.use ConfigValidate
23
- builder.use Call, CheckState do |env, b|
24
- case env[:machine_state]
25
- when :not_created
26
- env[:ui].info I18n.t('vagrant_linode.info.not_created')
13
+ builder.use Call, IsCreated do |env, b|
14
+ if !env[:result]
15
+ b.use MessageNotCreated
27
16
  else
28
17
  b.use Call, DestroyConfirm do |env2, b2|
29
18
  if env2[:result]
19
+ b2.use ConnectLinode
30
20
  b2.use Destroy
31
21
  b2.use ProvisionerCleanup if defined?(ProvisionerCleanup)
32
22
  end
@@ -36,128 +26,252 @@ module VagrantPlugins
36
26
  end
37
27
  end
38
28
 
39
- def self.ssh
29
+ # This action is called to read the SSH info of the machine. The
30
+ # resulting state is expected to be put into the `:machine_ssh_info`
31
+ # key.
32
+ def self.action_read_ssh_info
33
+ Vagrant::Action::Builder.new.tap do |b|
34
+ b.use ConfigValidate
35
+ b.use ConnectLinode
36
+ b.use ReadSSHInfo
37
+ end
38
+ end
39
+
40
+ def self.action_read_state
41
+ Vagrant::Action::Builder.new.tap do |b|
42
+ b.use ConfigValidate
43
+ b.use ConnectLinode
44
+ b.use ReadState
45
+ end
46
+ end
47
+
48
+ def self.action_ssh
40
49
  Vagrant::Action::Builder.new.tap do |builder|
41
50
  builder.use ConfigValidate
42
- builder.use Call, CheckState do |env, b|
43
- case env[:machine_state]
44
- when :active
45
- b.use SSHExec
46
- when :off
47
- env[:ui].info I18n.t('vagrant_linode.info.off')
48
- when :not_created
49
- env[:ui].info I18n.t('vagrant_linode.info.not_created')
51
+ builder.use Call, IsCreated do |env, b|
52
+ if env[:result]
53
+ b.use Call, IsStopped do |env2, b2|
54
+ if env2[:result]
55
+ b2.use MessageOff
56
+ else
57
+ b2.use SSHExec
58
+ end
59
+ end
60
+ else
61
+ b.use MessageNotCreated
50
62
  end
51
63
  end
52
64
  end
53
65
  end
54
66
 
55
- def self.ssh_run
67
+ def self.action_ssh_run
56
68
  Vagrant::Action::Builder.new.tap do |builder|
57
69
  builder.use ConfigValidate
58
- builder.use Call, CheckState do |env, b|
59
- case env[:machine_state]
60
- when :active
70
+ builder.use Call, IsCreated do |env, b|
71
+ if env[:result]
61
72
  b.use SSHRun
62
- when :off
63
- env[:ui].info I18n.t('vagrant_linode.info.off')
64
- when :not_created
65
- env[:ui].info I18n.t('vagrant_linode.info.not_created')
73
+ else
74
+ b.use Call, IsStopped do |env2, b2|
75
+ if env2[:result]
76
+ b2.use MessageOff
77
+ else
78
+ b2.use MessageNotCreated
79
+ end
80
+ end
66
81
  end
67
82
  end
68
83
  end
69
84
  end
70
85
 
71
- def self.provision
86
+ def self.action_provision
72
87
  Vagrant::Action::Builder.new.tap do |builder|
73
88
  builder.use ConfigValidate
74
- builder.use Call, CheckState do |env, b|
75
- case env[:machine_state]
76
- when :active
77
- b.use Provision
78
- b.use ModifyProvisionPath
79
- b.use SyncFolders
80
- when :off
81
- env[:ui].info I18n.t('vagrant_linode.info.off')
82
- when :not_created
83
- env[:ui].info I18n.t('vagrant_linode.info.not_created')
89
+ builder.use Call, IsCreated do |env, b|
90
+ if env[:result]
91
+ b.use Call, IsStopped do |env2, b2|
92
+ if env2[:result]
93
+ b2.use MessageOff
94
+ else
95
+ b2.use Provision
96
+ b2.use ModifyProvisionPath
97
+ b2.use SyncFolders
98
+ end
99
+ end
100
+ else
101
+ b.use MessageNotCreated
84
102
  end
85
103
  end
86
104
  end
87
105
  end
88
106
 
89
- def self.up
107
+ def self.action_up
90
108
  Vagrant::Action::Builder.new.tap do |builder|
91
109
  builder.use ConfigValidate
92
- builder.use Call, CheckState do |env, b|
93
- case env[:machine_state]
94
- when :active
95
- env[:ui].info I18n.t('vagrant_linode.info.already_active')
96
- when :off
97
- b.use PowerOn
98
- b.use provision
99
- when :not_created
100
- # b.use SetupKey # no access to ssh keys in linode api
110
+ builder.use Call, IsCreated do |env, b|
111
+ if env[:result]
112
+ b.use Call, IsStopped do |env2, b2|
113
+ if env2[:result]
114
+ b2.use MessageOff
115
+ b2.use ConnectLinode
116
+ b2.use PowerOn
117
+ b2.use Provision
118
+ else
119
+ b2.use MessageAlreadyActive
120
+ end
121
+ end
122
+ else
123
+ b.use MessageNotCreated
124
+ b.use ConnectLinode
101
125
  b.use Create
102
126
  b.use SetupSudo
103
127
  b.use SetupUser
104
128
  b.use SetupHostname
105
- b.use provision
129
+ b.use Provision
106
130
  end
107
131
  end
108
132
  end
109
133
  end
110
134
 
111
- def self.halt
135
+ def self.action_halt
112
136
  Vagrant::Action::Builder.new.tap do |builder|
113
137
  builder.use ConfigValidate
114
- builder.use Call, CheckState do |env, b|
115
- case env[:machine_state]
116
- when :active
117
- b.use PowerOff
118
- when :off
119
- env[:ui].info I18n.t('vagrant_linode.info.already_off')
120
- when :not_created
121
- env[:ui].info I18n.t('vagrant_linode.info.not_created')
138
+ builder.use Call, IsCreated do |env, b1|
139
+ if env[:result]
140
+ b1.use Call, IsStopped do |env2, b2|
141
+ if env2[:result]
142
+ b2.use MessageAlreadyOff
143
+ else
144
+ b2.use ConnectLinode
145
+ b2.use PowerOff
146
+ end
147
+ end
148
+ else
149
+ b1.use MessageNotCreated
122
150
  end
123
151
  end
124
152
  end
125
153
  end
126
154
 
127
- def self.reload
155
+ def self.action_reload
128
156
  Vagrant::Action::Builder.new.tap do |builder|
129
157
  builder.use ConfigValidate
130
- builder.use Call, CheckState do |env, b|
131
- case env[:machine_state]
132
- when :active
133
- b.use Reload
134
- b.use provision
135
- when :off
136
- env[:ui].info I18n.t('vagrant_linode.info.off')
137
- when :not_created
138
- env[:ui].info I18n.t('vagrant_linode.info.not_created')
158
+ builder.use Call, IsCreated do |env, b|
159
+ if env[:result]
160
+ b.use Call, IsStopped do |env2, b2|
161
+ if env2[:result]
162
+ b2.use MessageOff
163
+ else
164
+ b2.use ConnectLinode
165
+ b2.use Reload
166
+ b2.use Provision
167
+ end
168
+ end
169
+ else
170
+ b.use MessageNotCreated
139
171
  end
140
172
  end
141
173
  end
142
174
  end
143
175
 
144
- def self.rebuild
176
+ def self.action_rebuild
145
177
  Vagrant::Action::Builder.new.tap do |builder|
146
178
  builder.use ConfigValidate
147
- builder.use Call, CheckState do |env, b|
148
- case env[:machine_state]
149
- when :active, :off
150
- b.use Rebuild
151
- b.use SetupSudo
152
- b.use SetupUser
153
- b.use SetupHostname
154
- b.use provision
155
- when :not_created
156
- env[:ui].info I18n.t('vagrant_linode.info.not_created')
179
+ builder.use Call, IsCreated do |env, b|
180
+ if env[:result]
181
+ b.use Call, IsStopped do |env2, b2|
182
+ if env2[:result]
183
+ b2.use ConnectLinode
184
+ b2.use Rebuild
185
+ b2.use SetupSudo
186
+ b2.use SetupUser
187
+ b2.use SetupHostname
188
+ b2.use Provision
189
+ end
190
+ end
191
+ else
192
+ b2.use MessageNotCreated
157
193
  end
158
194
  end
159
195
  end
160
196
  end
197
+
198
+ # Extended actions
199
+ def self.action_create_image
200
+ Vagrant::Action::Builder.new.tap do |b|
201
+ b.use ConfigValidate # is this per machine?
202
+ b.use ConnectLinode
203
+ b.use CreateImage
204
+ end
205
+ end
206
+
207
+ def self.action_list_images
208
+ Vagrant::Action::Builder.new.tap do |b|
209
+ # b.use ConfigValidate # is this per machine?
210
+ b.use ConnectLinode
211
+ b.use ListImages
212
+ end
213
+ end
214
+
215
+ def self.action_list_servers
216
+ Vagrant::Action::Builder.new.tap do |b|
217
+ # b.use ConfigValidate # is this per machine?
218
+ b.use ConnectLinode
219
+ b.use ListServers
220
+ end
221
+ end
222
+
223
+ def self.action_list_plans
224
+ Vagrant::Action::Builder.new.tap do |b|
225
+ # b.use ConfigValidate # is this per machine?
226
+ b.use ConnectLinode
227
+ b.use ListPlans
228
+ end
229
+ end
230
+
231
+ def self.action_list_datacenters
232
+ Vagrant::Action::Builder.new.tap do |b|
233
+ # b.use ConfigValidate # is this per machine?
234
+ b.use ConnectLinode
235
+ b.use ListDatacenters
236
+ end
237
+ end
238
+
239
+ def self.action_list_distributions
240
+ Vagrant::Action::Builder.new.tap do |b|
241
+ # b.use ConfigValidate # is this per machine?
242
+ b.use ConnectLinode
243
+ b.use ListDistributions
244
+ end
245
+ end
246
+
247
+ action_root = Pathname.new(File.expand_path('../actions', __FILE__))
248
+ autoload :ConnectLinode, action_root.join('connect_linode')
249
+ autoload :ReadState, action_root.join('read_state')
250
+ autoload :Create, action_root.join('create')
251
+ autoload :Destroy, action_root.join('destroy')
252
+ autoload :IsCreated, action_root.join('is_created')
253
+ autoload :IsStopped, action_root.join('is_stopped')
254
+ autoload :MessageAlreadyActive, action_root.join('message_already_active')
255
+ autoload :MessageAlreadyOff, action_root.join('message_already_off')
256
+ autoload :MessageNotCreated, action_root.join('message_not_created')
257
+ autoload :MessageOff, action_root.join('message_off')
258
+ autoload :ModifyProvisionPath, action_root.join('modify_provision_path')
259
+ autoload :PowerOff, action_root.join('power_off')
260
+ autoload :PowerOn, action_root.join('power_on')
261
+ autoload :Destroy, action_root.join('destroy')
262
+ autoload :Reload, action_root.join('reload')
263
+ autoload :Rebuild, action_root.join('rebuild')
264
+ autoload :SetupHostname, action_root.join('setup_hostname')
265
+ autoload :SetupUser, action_root.join('setup_user')
266
+ autoload :SetupSudo, action_root.join('setup_sudo')
267
+ autoload :ReadSSHInfo, action_root.join("read_ssh_info")
268
+ autoload :SyncFolders, action_root.join('sync_folders')
269
+ autoload :ListServers, action_root.join('list_servers')
270
+ autoload :CreateImage, action_root.join('create_image')
271
+ autoload :ListImages, action_root.join('list_images')
272
+ autoload :ListPlans, action_root.join('list_plans')
273
+ autoload :ListDistributions, action_root.join('list_distributions')
274
+ autoload :ListDatacenters, action_root.join('list_datacenters')
161
275
  end
162
276
  end
163
277
  end