vagrant-linode 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,48 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Linode
|
5
|
+
module Actions
|
6
|
+
# This action reads the SSH info for the machine and puts it into the
|
7
|
+
# `:machine_ssh_info` key in the environment.
|
8
|
+
class ReadSSHInfo
|
9
|
+
def initialize(app, _env)
|
10
|
+
@env = _env
|
11
|
+
@app = app
|
12
|
+
@machine = _env[:machine]
|
13
|
+
@logger = Log4r::Logger.new('vagrant_linode::action::read_ssh_info')
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
env[:machine_ssh_info] = read_ssh_info(env[:linode_api], @machine)
|
18
|
+
|
19
|
+
@app.call(env)
|
20
|
+
end
|
21
|
+
|
22
|
+
def read_ssh_info(_linode, machine)
|
23
|
+
return nil if machine.id.nil?
|
24
|
+
server = Provider.linode(machine, refresh: true)
|
25
|
+
@env[:ui].info "Machine State ID: %s" % [machine.state.id]
|
26
|
+
|
27
|
+
#return nil if machine.state.id != :active # @todo this seems redundant to the next line. may be more correct.
|
28
|
+
if server.nil?
|
29
|
+
# The machine can't be found
|
30
|
+
@logger.info("Machine couldn't be found, assuming it got destroyed.")
|
31
|
+
machine.id = nil
|
32
|
+
return nil
|
33
|
+
end
|
34
|
+
|
35
|
+
public_network = server.network.find { |network| network['ispublic'] == 1 }
|
36
|
+
@env[:ui].info "IP Address: %s" % public_network['ipaddress']
|
37
|
+
|
38
|
+
{
|
39
|
+
host: public_network['ipaddress'],
|
40
|
+
port: '22',
|
41
|
+
username: 'root',
|
42
|
+
private_key_path: machine.config.ssh.private_key_path
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Actions
|
4
|
+
class ReadState
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@machine = env[:machine]
|
8
|
+
@logger = Log4r::Logger.new('vagrant_linode::action::read_state')
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
env[:machine_state] = read_state(env[:linode_api], @machine)
|
13
|
+
@logger.info "Machine state is '#{env[:machine_state]}'"
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
|
17
|
+
def read_state(_linode, machine)
|
18
|
+
return :not_created if machine.id.nil?
|
19
|
+
server = Provider.linode(machine)
|
20
|
+
|
21
|
+
return :not_created if server.nil?
|
22
|
+
status = server.status
|
23
|
+
return :not_created if status.nil?
|
24
|
+
states = {
|
25
|
+
'' => :not_created,
|
26
|
+
'-2' => :boot_failed,
|
27
|
+
'-1' => :being_created,
|
28
|
+
'0' => :brand_new,
|
29
|
+
'1' => :active, # running
|
30
|
+
'2' => :off, # powered off
|
31
|
+
'3' => :shutting_down
|
32
|
+
}
|
33
|
+
states[status.to_s]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,20 +1,21 @@
|
|
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 Rebuild
|
7
|
-
include Helpers::Client
|
8
8
|
include Vagrant::Util::Retryable
|
9
|
+
include Helpers::Waiter
|
9
10
|
|
10
11
|
def initialize(app, env)
|
11
12
|
@app = app
|
12
13
|
@machine = env[:machine]
|
13
|
-
@client = client
|
14
14
|
@logger = Log4r::Logger.new('vagrant::linode::rebuild')
|
15
15
|
end
|
16
16
|
|
17
17
|
def call(env)
|
18
|
+
@client = env[:linode_api]
|
18
19
|
# @todo find a convenient way to send provider_config back to the create action, reusing the diskid or configid
|
19
20
|
fail 'not implemented'
|
20
21
|
# look up image id
|
@@ -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 Reload
|
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::reload')
|
14
14
|
end
|
15
15
|
|
16
16
|
def call(env)
|
17
|
+
@client = env[:linode_api]
|
17
18
|
# submit reboot linode request
|
18
19
|
result = @client.linode.reboot(linodeid: @machine.id)
|
19
20
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Commands
|
4
|
+
class CreateImage < Vagrant.plugin('2', :command)
|
5
|
+
def execute
|
6
|
+
options = {}
|
7
|
+
opts = OptionParser.new do |o|
|
8
|
+
o.banner = 'Usage: vagrant linode images create [options]'
|
9
|
+
end
|
10
|
+
|
11
|
+
argv = parse_options(opts)
|
12
|
+
return unless argv
|
13
|
+
|
14
|
+
with_target_vms(argv, provider: :linode) do |machine|
|
15
|
+
machine.action('create_image')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Commands
|
4
|
+
class Datacenters < Vagrant.plugin('2', :command)
|
5
|
+
def execute
|
6
|
+
options = {}
|
7
|
+
opts = OptionParser.new do |o|
|
8
|
+
o.banner = 'Usage: vagrant linode datacenters [options]'
|
9
|
+
end
|
10
|
+
|
11
|
+
argv = parse_options(opts)
|
12
|
+
return unless argv
|
13
|
+
|
14
|
+
with_target_vms(argv, provider: :linode) do |machine|
|
15
|
+
machine.action('list_datacenters')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Commands
|
4
|
+
class Distributions < Vagrant.plugin('2', :command)
|
5
|
+
def execute
|
6
|
+
options = {}
|
7
|
+
opts = OptionParser.new do |o|
|
8
|
+
o.banner = 'Usage: vagrant linode distributions [options]'
|
9
|
+
end
|
10
|
+
|
11
|
+
argv = parse_options(opts)
|
12
|
+
return unless argv
|
13
|
+
|
14
|
+
with_target_vms(argv, provider: :linode) do |machine|
|
15
|
+
machine.action('list_distributions')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Commands
|
4
|
+
class Images < 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_images', __FILE__)
|
11
|
+
ListImages
|
12
|
+
end
|
13
|
+
@subcommands.register(:create) do
|
14
|
+
require File.expand_path('../create_image', __FILE__)
|
15
|
+
CreateImage
|
16
|
+
end
|
17
|
+
|
18
|
+
super(argv, env)
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute
|
22
|
+
if @main_args.include?('-h') || @main_args.include?('--help')
|
23
|
+
# Print the help for all the rackspace commands.
|
24
|
+
return help
|
25
|
+
end
|
26
|
+
|
27
|
+
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
28
|
+
return help if !command_class || !@sub_command
|
29
|
+
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
|
30
|
+
|
31
|
+
# Initialize and execute the command class
|
32
|
+
command_class.new(@sub_args, @env).execute
|
33
|
+
end
|
34
|
+
|
35
|
+
def help
|
36
|
+
opts = OptionParser.new do |opts|
|
37
|
+
opts.banner = 'Usage: vagrant linode images <subcommand> [<args>]'
|
38
|
+
opts.separator ''
|
39
|
+
opts.separator 'Available subcommands:'
|
40
|
+
|
41
|
+
# Add the available subcommands as separators in order to print them
|
42
|
+
# out as well.
|
43
|
+
keys = []
|
44
|
+
@subcommands.each { |key, _value| keys << key.to_s }
|
45
|
+
|
46
|
+
keys.sort.each do |key|
|
47
|
+
opts.separator " #{key}"
|
48
|
+
end
|
49
|
+
|
50
|
+
opts.separator ''
|
51
|
+
opts.separator 'For help on any individual subcommand run `vagrant linode images <subcommand> -h`'
|
52
|
+
end
|
53
|
+
|
54
|
+
@env.ui.info(opts.help, prefix: false)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Commands
|
4
|
+
class ListImages < Vagrant.plugin('2', :command)
|
5
|
+
def execute
|
6
|
+
options = {}
|
7
|
+
opts = OptionParser.new do |o|
|
8
|
+
o.banner = 'Usage: vagrant linode images list [options]'
|
9
|
+
end
|
10
|
+
|
11
|
+
argv = parse_options(opts)
|
12
|
+
return unless argv
|
13
|
+
|
14
|
+
with_target_vms(argv, provider: :linode) do |machine|
|
15
|
+
machine.action('list_images')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Commands
|
4
|
+
class Networks < Vagrant.plugin('2', :command)
|
5
|
+
def execute
|
6
|
+
options = {}
|
7
|
+
opts = OptionParser.new do |o|
|
8
|
+
o.banner = 'Usage: vagrant linode networks [options]'
|
9
|
+
end
|
10
|
+
|
11
|
+
argv = parse_options(opts)
|
12
|
+
return unless argv
|
13
|
+
|
14
|
+
with_target_vms(argv, provider: :linode) do |machine|
|
15
|
+
machine.action('list_networks')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Commands
|
4
|
+
class Plans < Vagrant.plugin('2', :command)
|
5
|
+
def execute
|
6
|
+
options = {}
|
7
|
+
opts = OptionParser.new do |o|
|
8
|
+
o.banner = 'Usage: vagrant linode plans [options]'
|
9
|
+
end
|
10
|
+
|
11
|
+
argv = parse_options(opts)
|
12
|
+
return unless argv
|
13
|
+
|
14
|
+
with_target_vms(argv, provider: :linode) do |machine|
|
15
|
+
machine.action('list_plans')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'vagrant-linode/actions'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Linode
|
5
|
+
module Commands
|
6
|
+
class Root < Vagrant.plugin('2', :command)
|
7
|
+
def self.synopsis
|
8
|
+
'query Linode for available images or plans'
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(argv, env)
|
12
|
+
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
13
|
+
|
14
|
+
@subcommands = Vagrant::Registry.new
|
15
|
+
@subcommands.register(:images) do
|
16
|
+
require File.expand_path('../images', __FILE__)
|
17
|
+
Images
|
18
|
+
end
|
19
|
+
@subcommands.register(:plans) do
|
20
|
+
require File.expand_path('../plans', __FILE__)
|
21
|
+
Plans
|
22
|
+
end
|
23
|
+
@subcommands.register(:distributions) do
|
24
|
+
require File.expand_path('../distributions', __FILE__)
|
25
|
+
Distributions
|
26
|
+
end
|
27
|
+
@subcommands.register(:datacenters) do
|
28
|
+
require File.expand_path('../datacenters', __FILE__)
|
29
|
+
Datacenters
|
30
|
+
end
|
31
|
+
@subcommands.register(:networks) do
|
32
|
+
require File.expand_path('../networks', __FILE__)
|
33
|
+
Networks
|
34
|
+
end
|
35
|
+
@subcommands.register(:servers) do
|
36
|
+
require File.expand_path('../servers', __FILE__)
|
37
|
+
Servers
|
38
|
+
end
|
39
|
+
|
40
|
+
super(argv, env)
|
41
|
+
end
|
42
|
+
|
43
|
+
def execute
|
44
|
+
if @main_args.include?('-h') || @main_args.include?('--help')
|
45
|
+
# Print the help for all the linode commands.
|
46
|
+
return help
|
47
|
+
end
|
48
|
+
|
49
|
+
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
50
|
+
return help if !command_class || !@sub_command
|
51
|
+
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
|
52
|
+
|
53
|
+
# Initialize and execute the command class
|
54
|
+
command_class.new(@sub_args, @env).execute
|
55
|
+
end
|
56
|
+
|
57
|
+
def help
|
58
|
+
opts = OptionParser.new do |opts|
|
59
|
+
opts.banner = 'Usage: vagrant linode <subcommand> [<args>]'
|
60
|
+
opts.separator ''
|
61
|
+
opts.separator 'Available subcommands:'
|
62
|
+
|
63
|
+
# Add the available subcommands as separators in order to print them
|
64
|
+
# out as well.
|
65
|
+
keys = []
|
66
|
+
@subcommands.each { |key, _value| keys << key.to_s }
|
67
|
+
|
68
|
+
keys.sort.each do |key|
|
69
|
+
opts.separator " #{key}"
|
70
|
+
end
|
71
|
+
|
72
|
+
opts.separator ''
|
73
|
+
opts.separator 'For help on any individual subcommand run `vagrant linode <subcommand> -h`'
|
74
|
+
end
|
75
|
+
|
76
|
+
@env.ui.info(opts.help, prefix: false)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Linode
|
3
|
+
module Commands
|
4
|
+
class Servers < Vagrant.plugin('2', :command)
|
5
|
+
def execute
|
6
|
+
options = {}
|
7
|
+
opts = OptionParser.new do |o|
|
8
|
+
o.banner = 'Usage: vagrant linode servers [options]'
|
9
|
+
end
|
10
|
+
|
11
|
+
argv = parse_options(opts)
|
12
|
+
return unless argv
|
13
|
+
|
14
|
+
with_target_vms(argv, provider: :linode) do |machine|
|
15
|
+
machine.action('list_servers')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module VagrantPlugins
|
2
2
|
module Linode
|
3
3
|
class Config < Vagrant.plugin('2', :config)
|
4
|
-
attr_accessor :token
|
4
|
+
attr_accessor :token # deprecated
|
5
|
+
attr_accessor :api_key
|
5
6
|
attr_accessor :api_url
|
6
7
|
attr_accessor :distribution
|
7
8
|
attr_accessor :datacenter
|
@@ -21,7 +22,10 @@ module VagrantPlugins
|
|
21
22
|
alias_method :setup?, :setup
|
22
23
|
|
23
24
|
def initialize
|
25
|
+
# @logger = Log4r::Logger.new('vagrant::linode::config')
|
26
|
+
|
24
27
|
@token = UNSET_VALUE
|
28
|
+
@api_key = UNSET_VALUE
|
25
29
|
@api_url = UNSET_VALUE
|
26
30
|
@distribution = UNSET_VALUE
|
27
31
|
@datacenter = UNSET_VALUE
|
@@ -40,7 +44,9 @@ module VagrantPlugins
|
|
40
44
|
end
|
41
45
|
|
42
46
|
def finalize!
|
47
|
+
@api_key = ENV['LINODE_API_KEY'] if @api_key == UNSET_VALUE
|
43
48
|
@token = ENV['LINODE_TOKEN'] if @token == UNSET_VALUE
|
49
|
+
@api_key = @token if ((@api_key == nil) and (@token != nil))
|
44
50
|
@api_url = ENV['LINODE_URL'] if @api_url == UNSET_VALUE
|
45
51
|
@distribution = 'Ubuntu 14.04 LTS' if @distribution == UNSET_VALUE
|
46
52
|
@datacenter = 'dallas' if @datacenter == UNSET_VALUE
|
@@ -59,8 +65,10 @@ module VagrantPlugins
|
|
59
65
|
|
60
66
|
def validate(machine)
|
61
67
|
errors = []
|
62
|
-
errors << I18n.t('vagrant_linode.config.
|
63
|
-
|
68
|
+
errors << I18n.t('vagrant_linode.config.api_key') unless @api_key
|
69
|
+
# Log4r::Logger.new('vagrant_linode.config.token') if @token
|
70
|
+
# env[:ui].info I18n.t('vagrant_linode.config.token') if @token
|
71
|
+
# errors << I18n.t('vagrant_linode.config.token') if @token
|
64
72
|
key = machine.config.ssh.private_key_path
|
65
73
|
key = key[0] if key.is_a?(Array)
|
66
74
|
if !key
|