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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rspec +4 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +164 -0
- data/Gemfile +9 -6
- data/README.md +21 -9
- data/Rakefile +21 -1
- data/Vagrantfile.multi +18 -0
- data/box/linode-debian-7.5.box +0 -0
- data/box/linode.box +0 -0
- data/box/metadata-debian-7.5.json +12 -0
- data/box/metadata.json +2 -2
- data/features/provision.feature +34 -0
- data/features/steps/sdk_steps.rb +13 -0
- data/features/steps/server_steps.rb +25 -0
- data/features/support/env.rb +34 -0
- data/features/support/fog_mock.rb +16 -0
- data/features/vagrant-linode.feature +68 -0
- data/lib/vagrant-linode.rb +44 -5
- data/lib/vagrant-linode/actions.rb +201 -87
- data/lib/vagrant-linode/actions/connect_linode.rb +36 -0
- data/lib/vagrant-linode/actions/create.rb +9 -9
- data/lib/vagrant-linode/actions/create_image.rb +23 -0
- data/lib/vagrant-linode/actions/destroy.rb +1 -3
- data/lib/vagrant-linode/actions/halt.rb +29 -0
- data/lib/vagrant-linode/actions/is_created.rb +16 -0
- data/lib/vagrant-linode/actions/is_stopped.rb +17 -0
- data/lib/vagrant-linode/actions/list_datacenters.rb +20 -0
- data/lib/vagrant-linode/actions/list_distributions.rb +20 -0
- data/lib/vagrant-linode/actions/list_images.rb +20 -0
- data/lib/vagrant-linode/actions/list_plans.rb +20 -0
- data/lib/vagrant-linode/actions/list_servers.rb +20 -0
- data/lib/vagrant-linode/actions/message_already_active.rb +16 -0
- data/lib/vagrant-linode/actions/message_already_off.rb +16 -0
- data/lib/vagrant-linode/actions/message_not_created.rb +16 -0
- data/lib/vagrant-linode/actions/message_off.rb +16 -0
- data/lib/vagrant-linode/actions/power_off.rb +4 -3
- data/lib/vagrant-linode/actions/power_on.rb +3 -2
- data/lib/vagrant-linode/actions/read_ssh_info.rb +48 -0
- data/lib/vagrant-linode/actions/read_state.rb +38 -0
- data/lib/vagrant-linode/actions/rebuild.rb +3 -2
- data/lib/vagrant-linode/actions/reload.rb +3 -2
- data/lib/vagrant-linode/commands/create_image.rb +21 -0
- data/lib/vagrant-linode/commands/datacenters.rb +21 -0
- data/lib/vagrant-linode/commands/distributions.rb +21 -0
- data/lib/vagrant-linode/commands/images.rb +59 -0
- data/lib/vagrant-linode/commands/list_images.rb +21 -0
- data/lib/vagrant-linode/commands/networks.rb +21 -0
- data/lib/vagrant-linode/commands/plans.rb +21 -0
- data/lib/vagrant-linode/commands/root.rb +81 -0
- data/lib/vagrant-linode/commands/servers.rb +21 -0
- data/lib/vagrant-linode/config.rb +11 -3
- data/lib/vagrant-linode/helpers/client.rb +21 -79
- data/lib/vagrant-linode/helpers/waiter.rb +21 -0
- data/lib/vagrant-linode/plugin.rb +20 -0
- data/lib/vagrant-linode/provider.rb +27 -32
- data/lib/vagrant-linode/version.rb +1 -1
- data/locales/en.yml +17 -1
- data/spec/spec_helper.rb +20 -0
- data/spec/vagrant-linode/actions/list_distributions_spec.rb +47 -0
- data/spec/vagrant-linode/actions/list_plans_spec.rb +47 -0
- data/spec/vagrant-linode/config_spec.rb +189 -0
- data/test/Vagrantfile +4 -9
- data/vagrant-linode.gemspec +1 -1
- metadata +70 -20
- data/lib/vagrant-linode/actions/check_state.rb +0 -19
- data/lib/vagrant-linode/actions/setup_key.rb +0 -52
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Linode
|
5
|
+
module Actions
|
6
|
+
# This action connects to Linode, verifies credentials work, and
|
7
|
+
# puts the Linode connection object into the `:linode_api` key
|
8
|
+
# in the environment.
|
9
|
+
class ConnectLinode
|
10
|
+
def initialize(app, _env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new('vagrant_linode::action::connect_linode')
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
# Get the configs
|
17
|
+
config = env[:machine].provider_config
|
18
|
+
api_key = config.api_key
|
19
|
+
api_url = config.api_url
|
20
|
+
|
21
|
+
params = {
|
22
|
+
apikey: api_key,
|
23
|
+
endpoint: api_url
|
24
|
+
}
|
25
|
+
|
26
|
+
@logger.info('Connecting to Linode api_url...')
|
27
|
+
|
28
|
+
linode = ::LinodeAPI::Raw.new params
|
29
|
+
env[:linode_api] = linode
|
30
|
+
|
31
|
+
@app.call(env)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,24 +1,24 @@
|
|
1
1
|
require 'vagrant-linode/helpers/client'
|
2
|
+
require 'vagrant-linode/helpers/waiter'
|
2
3
|
require 'vagrant-linode/errors'
|
3
4
|
|
4
5
|
module VagrantPlugins
|
5
6
|
module Linode
|
6
7
|
module Actions
|
7
8
|
class Create
|
8
|
-
include Helpers::Client
|
9
9
|
include Vagrant::Util::Retryable
|
10
|
+
include VagrantPlugins::Linode::Helpers::Waiter
|
10
11
|
|
11
12
|
def initialize(app, env)
|
12
13
|
@app = app
|
13
14
|
@machine = env[:machine]
|
14
|
-
@client = client
|
15
15
|
@logger = Log4r::Logger.new('vagrant::linode::create')
|
16
16
|
end
|
17
17
|
|
18
18
|
def call(env)
|
19
|
+
@client = env[:linode_api]
|
19
20
|
ssh_key_id = env[:machine].config.ssh.private_key_path
|
20
21
|
ssh_key_id = ssh_key_id[0] if ssh_key_id.is_a?(Array)
|
21
|
-
|
22
22
|
if ssh_key_id
|
23
23
|
pubkey = File.read(File.expand_path("#{ssh_key_id}.pub"))
|
24
24
|
end
|
@@ -32,7 +32,7 @@ module VagrantPlugins
|
|
32
32
|
if @machine.provider_config.distribution
|
33
33
|
distributions = @client.avail.distributions
|
34
34
|
distribution = distributions.find { |d| d.label.downcase.include? @machine.provider_config.distribution.downcase }
|
35
|
-
|
35
|
+
fail(Errors::DistroMatch, distro: @machine.provider_config.distribution.to_s) if distribution.nil?
|
36
36
|
distribution_id = distribution.distributionid || nil
|
37
37
|
else
|
38
38
|
distribution_id = @machine.provider_config.distributionid
|
@@ -58,8 +58,8 @@ module VagrantPlugins
|
|
58
58
|
if @machine.provider_config.plan
|
59
59
|
plans = @client.avail.linodeplans
|
60
60
|
plan = plans.find { |p| p.label.include? @machine.provider_config.plan }
|
61
|
-
|
62
|
-
plan_id = plan.planid || nil
|
61
|
+
fail Errors::PlanID, plan: @machine.provider_config.plan if plan.nil?
|
62
|
+
plan_id = plan.planid || nil
|
63
63
|
else
|
64
64
|
plan_id = @machine.provider_config.planid
|
65
65
|
end
|
@@ -69,14 +69,14 @@ module VagrantPlugins
|
|
69
69
|
|
70
70
|
# Sanity checks for disk size
|
71
71
|
if xvda_size != true
|
72
|
-
disk_sanity = false if ( xvda_size.to_i + swap_size.to_i
|
72
|
+
disk_sanity = false if ( xvda_size.to_i + swap_size.to_i) > ( plan['disk'].to_i * 1024)
|
73
73
|
end
|
74
74
|
|
75
75
|
# throw if disk sizes are too large
|
76
76
|
if xvda_size == true
|
77
|
-
xvda_size = ( ( plan['disk'].to_i * 1024
|
77
|
+
xvda_size = ( ( plan['disk'].to_i * 1024) - swap_size.to_i)
|
78
78
|
elsif disk_sanity == false
|
79
|
-
|
79
|
+
fail Errors::DiskSize, current: (xvda_size.to_i + swap_size.to_i), max: ( plan['disk'].to_i * 1024)
|
80
80
|
end
|
81
81
|
|
82
82
|
env[:ui].info I18n.t('vagrant_linode.info.creating')
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Actions
|
4
|
+
class CreateImage
|
5
|
+
def initialize(app, _env)
|
6
|
+
@app = app
|
7
|
+
@machine = _env[:machine]
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
linode_api = env[:linode_api]
|
12
|
+
env[:ui].info ('%-36s %-36s %-10s %-10s' % ['Image ID', 'Disk Label', 'Disk ID', 'Job ID'])
|
13
|
+
linode_api.linode.disk.list(:linodeid => @machine.id).each do |disk|
|
14
|
+
next if disk.type == 'swap'
|
15
|
+
img = linode_api.linode.disk.imagize :linodeid => disk.linodeid, :diskid => disk.diskid, :description => 'Imagized with Vagrant'
|
16
|
+
env[:ui].info ('%-36s %-36s %-10s %-10s' % [img.imageid, disk.label, disk.diskid, img.jobid])
|
17
|
+
end
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -4,16 +4,14 @@ module VagrantPlugins
|
|
4
4
|
module Linode
|
5
5
|
module Actions
|
6
6
|
class Destroy
|
7
|
-
include Helpers::Client
|
8
|
-
|
9
7
|
def initialize(app, env)
|
10
8
|
@app = app
|
11
9
|
@machine = env[:machine]
|
12
|
-
@client = client
|
13
10
|
@logger = Log4r::Logger.new('vagrant::linode::destroy')
|
14
11
|
end
|
15
12
|
|
16
13
|
def call(env)
|
14
|
+
@client = env[:linode_api]
|
17
15
|
# submit destroy linode request
|
18
16
|
@client.linode.delete(linodeid: @machine.id, skipchecks: true)
|
19
17
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'vagrant-linode/helpers/client'
|
2
|
+
require 'vagrant-linode/helpers/waiter'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module Linode
|
6
|
+
module Actions
|
7
|
+
|
8
|
+
class Reload
|
9
|
+
include Helpers::Waiter
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@machine = env[:machine]
|
13
|
+
@logger = Log4r::Logger.new('vagrant::linode::reload')
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
@client = env[:linode_api]
|
18
|
+
# submit reboot linode request
|
19
|
+
result = @client.linode.reboot(linodeid: @machine.id)
|
20
|
+
|
21
|
+
# wait for request to complete
|
22
|
+
env[:ui].info I18n.t('vagrant_linode.info.reloading')
|
23
|
+
wait_for_event(env, result['jobid'])
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Actions
|
4
|
+
class ListDatacenters
|
5
|
+
def initialize(app, _env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
linode_api = env[:linode_api]
|
11
|
+
env[:ui].info ('%-15s %-36s %s' % ['Datacenter ID', 'Location', 'Abbr'])
|
12
|
+
linode_api.avail.datacenters.sort_by(&:datacenterid).each do |dc|
|
13
|
+
env[:ui].info ('%-15s %-36s %s' % [dc.datacenterid, dc.location, dc.abbr])
|
14
|
+
end
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Actions
|
4
|
+
class ListDistributions
|
5
|
+
def initialize(app, _env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
linode_api = env[:linode_api]
|
11
|
+
env[:ui].info ('%-4s %-6s %s' % ['ID', 'Size', 'Distribution Name'])
|
12
|
+
linode_api.avail.distributions.sort_by(&:distributionid).each do |dist|
|
13
|
+
env[:ui].info ('%-4s %-6s %s' % [dist.distributionid, dist.minimagesize, dist.label])
|
14
|
+
end
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Actions
|
4
|
+
class ListImages
|
5
|
+
def initialize(app, _env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
linode_api = env[:linode_api]
|
11
|
+
env[:ui].info ('%-10s %-22s %-10s %s' % ['Image ID', 'Created', 'Size (MB)', 'Image Label'])
|
12
|
+
linode_api.image.list.sort_by(&:imageid).each do |img|
|
13
|
+
env[:ui].info ('%-10s %-22s %-10s %s' % [img.imageid, img.create_dt, img.minsize, img.label])
|
14
|
+
end
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Actions
|
4
|
+
class ListPlans
|
5
|
+
def initialize(app, _env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
linode_api = env[:linode_api]
|
11
|
+
env[:ui].info ('%-36s %s' % ['Plan ID', 'Plan Name'])
|
12
|
+
linode_api.avail.linodeplans.sort_by(&:planid).each do |plan|
|
13
|
+
env[:ui].info ('%-36s %s' % [plan.planid, plan.label])
|
14
|
+
end
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Actions
|
4
|
+
class ListServers
|
5
|
+
def initialize(app, _env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
linode_api = env[:linode_api]
|
11
|
+
env[:ui].info ('%-8s %-30s %-20s %-10s %-9s' % ['LinodeID', 'Label', 'DataCenter', 'Plan', 'Status'])
|
12
|
+
linode_api.linode.list.sort_by(&:imageid).each do |ln|
|
13
|
+
env[:ui].info ('%-8s %-30s %-20s %-10s %-9s' % [ln.linodeid, ln.label, ln.datacenterid, ln.planid, ln.status])
|
14
|
+
end
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Actions
|
4
|
+
class MessageAlreadyActive
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t("vagrant_linode.info.already_active", :status => :active))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Actions
|
4
|
+
class MessageAlreadyOff
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t("vagrant_linode.info.already_off", :status => :off))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Actions
|
4
|
+
class MessageNotCreated
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t("vagrant_linode.info.not_created", :status => :not_created))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Actions
|
4
|
+
class MessageOff
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t("vagrant_linode.info.off", :status => :off))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,19 +1,20 @@
|
|
1
1
|
require 'vagrant-linode/helpers/client'
|
2
|
+
require 'vagrant-linode/helpers/waiter'
|
2
3
|
# TODO: --force
|
3
4
|
module VagrantPlugins
|
4
5
|
module Linode
|
5
6
|
module Actions
|
6
|
-
class PowerOff
|
7
|
-
include Helpers::Client
|
8
7
|
|
8
|
+
class PowerOff
|
9
|
+
include Helpers::Waiter
|
9
10
|
def initialize(app, env)
|
10
11
|
@app = app
|
11
12
|
@machine = env[:machine]
|
12
|
-
@client = client
|
13
13
|
@logger = Log4r::Logger.new('vagrant::linode::power_off')
|
14
14
|
end
|
15
15
|
|
16
16
|
def call(env)
|
17
|
+
@client = env[:linode_api]
|
17
18
|
# submit power off linode request
|
18
19
|
result = @client.linode.shutdown(linodeid: @machine.id)
|
19
20
|
|
@@ -1,19 +1,20 @@
|
|
1
1
|
require 'vagrant-linode/helpers/client'
|
2
|
+
require 'vagrant-linode/helpers/waiter'
|
2
3
|
|
3
4
|
module VagrantPlugins
|
4
5
|
module Linode
|
5
6
|
module Actions
|
6
7
|
class PowerOn
|
7
|
-
include Helpers::
|
8
|
+
include Helpers::Waiter
|
8
9
|
|
9
10
|
def initialize(app, env)
|
10
11
|
@app = app
|
11
12
|
@machine = env[:machine]
|
12
|
-
@client = client
|
13
13
|
@logger = Log4r::Logger.new('vagrant::linode::power_on')
|
14
14
|
end
|
15
15
|
|
16
16
|
def call(env)
|
17
|
+
@client = env[:linode_api]
|
17
18
|
# submit power on linode request
|
18
19
|
result = @client.linode.boot(linodeid: @machine.id)
|
19
20
|
|