krates-plugin-vagrant 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +2 -0
  5. data/CHANGELOG.md +22 -0
  6. data/Gemfile +8 -0
  7. data/LICENSE.txt +214 -0
  8. data/README.md +77 -0
  9. data/krates-plugin-vagrant.gemspec +26 -0
  10. data/lib/kontena/machine/vagrant.rb +12 -0
  11. data/lib/kontena/machine/vagrant/Vagrantfile.master.rb.erb +113 -0
  12. data/lib/kontena/machine/vagrant/Vagrantfile.node.rb.erb +38 -0
  13. data/lib/kontena/machine/vagrant/cloudinit.yml +92 -0
  14. data/lib/kontena/machine/vagrant/common.rb +21 -0
  15. data/lib/kontena/machine/vagrant/master_destroyer.rb +21 -0
  16. data/lib/kontena/machine/vagrant/master_provisioner.rb +96 -0
  17. data/lib/kontena/machine/vagrant/node_destroyer.rb +35 -0
  18. data/lib/kontena/machine/vagrant/node_provisioner.rb +82 -0
  19. data/lib/kontena/plugin/vagrant.rb +7 -0
  20. data/lib/kontena/plugin/vagrant/master/create_command.rb +44 -0
  21. data/lib/kontena/plugin/vagrant/master/restart_command.rb +17 -0
  22. data/lib/kontena/plugin/vagrant/master/ssh_command.rb +24 -0
  23. data/lib/kontena/plugin/vagrant/master/start_command.rb +16 -0
  24. data/lib/kontena/plugin/vagrant/master/stop_command.rb +16 -0
  25. data/lib/kontena/plugin/vagrant/master/terminate_command.rb +13 -0
  26. data/lib/kontena/plugin/vagrant/master_command.rb +19 -0
  27. data/lib/kontena/plugin/vagrant/node_command.rb +19 -0
  28. data/lib/kontena/plugin/vagrant/nodes/create_command.rb +81 -0
  29. data/lib/kontena/plugin/vagrant/nodes/restart_command.rb +22 -0
  30. data/lib/kontena/plugin/vagrant/nodes/ssh_command.rb +28 -0
  31. data/lib/kontena/plugin/vagrant/nodes/start_command.rb +22 -0
  32. data/lib/kontena/plugin/vagrant/nodes/stop_command.rb +22 -0
  33. data/lib/kontena/plugin/vagrant/nodes/terminate_command.rb +26 -0
  34. data/lib/kontena/plugin/vagrant_command.rb +11 -0
  35. data/lib/kontena_cli_plugin.rb +5 -0
  36. metadata +119 -0
@@ -0,0 +1,17 @@
1
+ module Kontena::Plugin::Vagrant::Master
2
+ class RestartCommand < Kontena::Command
3
+ include Kontena::Cli::Common
4
+
5
+ def execute
6
+ require_relative '../../../machine/vagrant'
7
+
8
+ vagrant_path = "#{Dir.home}/.kontena/vagrant_master"
9
+ abort("Cannot find Vagrant kontena-master".colorize(:red)) unless Dir.exist?(vagrant_path)
10
+ Dir.chdir(vagrant_path) do
11
+ spinner "Executing 'vagrant reload' for kontena-master"
12
+ exit $?.exitstatus unless system('vagrant reload')
13
+ spinner "Vagrant machine restarted"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ module Kontena::Plugin::Vagrant::Master
2
+ class SshCommand < Kontena::Command
3
+ include Kontena::Cli::Common
4
+
5
+ parameter "[COMMANDS] ...", "Run command on Master"
6
+
7
+ def execute
8
+ require 'shellwords'
9
+ require_relative '../../../machine/vagrant'
10
+
11
+ vagrant_path = "#{Dir.home}/.kontena/vagrant_master"
12
+ abort("Cannot find Vagrant kontena-master".colorize(:red)) unless Dir.exist?(vagrant_path)
13
+
14
+ cmd = "vagrant ssh"
15
+ if self.commands_list && !self.commands_list.empty?
16
+ cmd << " -c '#{self.commands_list.shelljoin}'"
17
+ end
18
+
19
+ Dir.chdir(vagrant_path) do
20
+ system(cmd)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module Kontena::Plugin::Vagrant::Master
2
+ class StartCommand < Kontena::Command
3
+ include Kontena::Cli::Common
4
+
5
+ def execute
6
+ require_relative '../../../machine/vagrant'
7
+
8
+ vagrant_path = "#{Dir.home}/.kontena/vagrant_master"
9
+ abort("Cannot find Vagrant node kontena-master".colorize(:red)) unless Dir.exist?(vagrant_path)
10
+ Dir.chdir(vagrant_path) do
11
+ spinner "Triggering 'vagrant up' for kontena-master"
12
+ exit $?.exitstatus unless system('vagrant up')
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Kontena::Plugin::Vagrant::Master
2
+ class StopCommand < Kontena::Command
3
+ include Kontena::Cli::Common
4
+
5
+ def execute
6
+ require_relative '../../../machine/vagrant'
7
+
8
+ vagrant_path = "#{Dir.home}/.kontena/vagrant_master"
9
+ abort("Cannot find Vagrant kontena-master".colorize(:red)) unless Dir.exist?(vagrant_path)
10
+ Dir.chdir(vagrant_path) do
11
+ spinner "Triggering 'vagrant halt' for kontena-master"
12
+ exit $?.exitstatus unless system('vagrant halt')
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Kontena::Plugin::Vagrant::Master
2
+ class TerminateCommand < Kontena::Command
3
+ include Kontena::Cli::Common
4
+
5
+ option '--force', :flag, 'Force remove', default: false, attribute_name: :forced
6
+
7
+ def execute
8
+ confirm unless forced?
9
+ require_relative '../../../machine/vagrant'
10
+ Kontena::Machine::Vagrant::MasterDestroyer.new.run!
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'master/create_command'
2
+ require_relative 'master/start_command'
3
+ require_relative 'master/stop_command'
4
+ require_relative 'master/restart_command'
5
+ require_relative 'master/ssh_command'
6
+ require_relative 'master/terminate_command'
7
+
8
+ class Kontena::Plugin::Vagrant::MasterCommand < Kontena::Command
9
+
10
+ subcommand "create", "Create a new Vagrant master", Kontena::Plugin::Vagrant::Master::CreateCommand
11
+ subcommand "ssh", "SSH into Vagrant master", Kontena::Plugin::Vagrant::Master::SshCommand
12
+ subcommand "start", "Start Vagrant master", Kontena::Plugin::Vagrant::Master::StartCommand
13
+ subcommand "stop", "Stop Vagrant master", Kontena::Plugin::Vagrant::Master::StopCommand
14
+ subcommand "restart", "Restart Vagrant master", Kontena::Plugin::Vagrant::Master::RestartCommand
15
+ subcommand "terminate", "Terminate Vagrant master", Kontena::Plugin::Vagrant::Master::TerminateCommand
16
+
17
+ def execute
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'nodes/create_command'
2
+ require_relative 'nodes/start_command'
3
+ require_relative 'nodes/stop_command'
4
+ require_relative 'nodes/restart_command'
5
+ require_relative 'nodes/ssh_command'
6
+ require_relative 'nodes/terminate_command'
7
+
8
+ class Kontena::Plugin::Vagrant::NodeCommand < Kontena::Command
9
+
10
+ subcommand "create", "Create a new node to Vagrant", Kontena::Plugin::Vagrant::Nodes::CreateCommand
11
+ subcommand "ssh", "Ssh into Vagrant node", Kontena::Plugin::Vagrant::Nodes::SshCommand
12
+ subcommand "start", "Start Vagrant node", Kontena::Plugin::Vagrant::Nodes::StartCommand
13
+ subcommand "stop", "Stop Vagrant node", Kontena::Plugin::Vagrant::Nodes::StopCommand
14
+ subcommand "restart", "Restart Vagrant node", Kontena::Plugin::Vagrant::Nodes::RestartCommand
15
+ subcommand "terminate", "Terminate Vagrant node", Kontena::Plugin::Vagrant::Nodes::TerminateCommand
16
+
17
+ def execute
18
+ end
19
+ end
@@ -0,0 +1,81 @@
1
+ module Kontena::Plugin::Vagrant::Nodes
2
+ class CreateCommand < Kontena::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "[NAME]", "Node name"
7
+ option "--instances", "AMOUNT", "How many nodes will be created"
8
+ option "--memory", "MEMORY", "How much memory node has"
9
+ option "--cpus", "CPUS", "Number of CPUs per node", default: 1
10
+ option "--network-address", "IP", "First IP address for the node(s)", default: 'dhcp'
11
+ option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
12
+ option "--coreos-channel", "CHANNEL", "CoreOS release channel", default: 'stable'
13
+
14
+ def execute
15
+ api_url = require_api_url
16
+ require_current_grid
17
+
18
+ instance_count = ask_instances
19
+ instance_memory = ask_instance_memory
20
+
21
+ require_relative '../../../machine/vagrant'
22
+
23
+ grid = fetch_grid
24
+ provisioner = provisioner(client(require_token))
25
+
26
+ require 'ipaddr'
27
+ ip_address = if network_address == "dhcp"
28
+ nil
29
+ else
30
+ IPAddr.new network_address
31
+ end
32
+
33
+ instance_count.to_i.times do |i|
34
+ provisioner.run!(
35
+ master_uri: api_url,
36
+ grid_token: grid['token'],
37
+ grid: current_grid,
38
+ name: name,
39
+ instance_number: i + 1,
40
+ network_address: ip_address ? ip_address.to_s : "dhcp",
41
+ cpus: cpus,
42
+ memory: instance_memory,
43
+ version: version,
44
+ coreos_channel: coreos_channel
45
+ )
46
+
47
+ ip_address = ip_address.succ if ip_address
48
+ end
49
+ end
50
+
51
+ def ask_instances
52
+ if self.instances.nil?
53
+ prompt.ask("How many nodes?: ", default: 1, in: '1..10')
54
+ else
55
+ self.instances
56
+ end
57
+ end
58
+
59
+ def ask_instance_memory
60
+ if self.memory.nil?
61
+ prompt.select("Choose a size ") do |menu|
62
+ %w(1024 2048 4096).each do |mem|
63
+ menu.choice "#{mem}MB", mem
64
+ end
65
+ end
66
+ else
67
+ self.memory
68
+ end
69
+ end
70
+
71
+ # @param [Kontena::Client] client
72
+ def provisioner(client)
73
+ Kontena::Machine::Vagrant::NodeProvisioner.new(client)
74
+ end
75
+
76
+ # @return [Hash]
77
+ def fetch_grid
78
+ client(require_token).get("grids/#{current_grid}")
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,22 @@
1
+ module Kontena::Plugin::Vagrant::Nodes
2
+ class RestartCommand < Kontena::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "NAME", "Node name"
7
+
8
+ def execute
9
+ require_api_url
10
+ require_current_grid
11
+
12
+ require_relative '../../../machine/vagrant'
13
+
14
+ vagrant_path = "#{Dir.home}/.kontena/#{current_grid}/#{name}"
15
+ abort("Cannot find Vagrant node #{name}".colorize(:red)) unless Dir.exist?(vagrant_path)
16
+ Dir.chdir(vagrant_path) do
17
+ spinner "Triggering 'vagrant reload' for #{name.colorize(:cyan)}"
18
+ exit $?.exitstatus unless system('vagrant reload')
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ module Kontena::Plugin::Vagrant::Nodes
2
+ class SshCommand < Kontena::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "NAME", "Node name"
7
+ parameter "[COMMANDS] ...", "Run command on node"
8
+
9
+ def execute
10
+ require_api_url
11
+ require_current_grid
12
+
13
+ require 'shellwords'
14
+ require_relative '../../../machine/vagrant'
15
+
16
+ vagrant_path = "#{Dir.home}/.kontena/#{current_grid}/#{name}"
17
+ abort("Cannot find Vagrant node #{name}".colorize(:red)) unless Dir.exist?(vagrant_path)
18
+
19
+ cmd = "vagrant ssh"
20
+ if self.commands_list && !self.commands_list.empty?
21
+ cmd << " -c '#{self.commands_list.shelljoin}'"
22
+ end
23
+ Dir.chdir(vagrant_path) do
24
+ system(cmd)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ module Kontena::Plugin::Vagrant::Nodes
2
+ class StartCommand < Kontena::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "NAME", "Node name"
7
+
8
+ def execute
9
+ require_api_url
10
+ require_current_grid
11
+
12
+ require_relative '../../../machine/vagrant'
13
+
14
+ vagrant_path = "#{Dir.home}/.kontena/#{current_grid}/#{name}"
15
+ abort("Cannot find Vagrant node #{name}".colorize(:red)) unless Dir.exist?(vagrant_path)
16
+ Dir.chdir(vagrant_path) do
17
+ spinner "Triggering 'vagrant up' for #{name.colorize(:cyan)}"
18
+ exit $?.exitstatus unless system('vagrant up')
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Kontena::Plugin::Vagrant::Nodes
2
+ class StopCommand < Clamp::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "NAME", "Node name"
7
+
8
+ def execute
9
+ require_api_url
10
+ require_current_grid
11
+
12
+ require_relative '../../../machine/vagrant'
13
+
14
+ vagrant_path = "#{Dir.home}/.kontena/#{current_grid}/#{name}"
15
+ abort("Cannot find Vagrant node #{name}".colorize(:red)) unless Dir.exist?(vagrant_path)
16
+ Dir.chdir(vagrant_path) do
17
+ spinner "Triggering 'vagrant halt' for #{name.colorize(:cyan)}"
18
+ exit $?.exitstatus unless system('vagrant halt')
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ module Kontena::Plugin::Vagrant::Nodes
2
+ class TerminateCommand < Kontena::Command
3
+ include Kontena::Cli::Common
4
+ include Kontena::Cli::GridOptions
5
+
6
+ parameter "NAME", "Node name"
7
+ option '--force', :flag, 'Force remove', default: false, attribute_name: :forced
8
+
9
+ def execute
10
+ require_api_url
11
+ require_current_grid
12
+
13
+ confirm_command("#{current_grid}/#{name}") unless forced?
14
+
15
+ require_relative '../../../machine/vagrant'
16
+
17
+ destroyer = destroyer(client(require_token))
18
+ destroyer.run!(current_grid, name)
19
+ end
20
+
21
+ # @param [Kontena::Client] client
22
+ def destroyer(client)
23
+ Kontena::Machine::Vagrant::NodeDestroyer.new(client)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'vagrant/master_command'
2
+ require_relative 'vagrant/node_command'
3
+
4
+ class Kontena::Plugin::VagrantCommand < Kontena::Command
5
+
6
+ subcommand 'master', 'Vagrant master related commands', Kontena::Plugin::Vagrant::MasterCommand
7
+ subcommand 'node', 'Vagrant node related commands', Kontena::Plugin::Vagrant::NodeCommand
8
+
9
+ def execute
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ require 'kontena_cli'
2
+ require_relative 'kontena/plugin/vagrant'
3
+ require_relative 'kontena/plugin/vagrant_command'
4
+
5
+ Kontena::MainCommand.register("vagrant", "Vagrant specific commands", Kontena::Plugin::VagrantCommand)
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: krates-plugin-vagrant
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Pavel Tsurbeleu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: krates
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Krates Vagrant plugin
56
+ email:
57
+ - info@kontena.io
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".gitmodules"
64
+ - ".rspec"
65
+ - CHANGELOG.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - krates-plugin-vagrant.gemspec
70
+ - lib/kontena/machine/vagrant.rb
71
+ - lib/kontena/machine/vagrant/Vagrantfile.master.rb.erb
72
+ - lib/kontena/machine/vagrant/Vagrantfile.node.rb.erb
73
+ - lib/kontena/machine/vagrant/cloudinit.yml
74
+ - lib/kontena/machine/vagrant/common.rb
75
+ - lib/kontena/machine/vagrant/master_destroyer.rb
76
+ - lib/kontena/machine/vagrant/master_provisioner.rb
77
+ - lib/kontena/machine/vagrant/node_destroyer.rb
78
+ - lib/kontena/machine/vagrant/node_provisioner.rb
79
+ - lib/kontena/plugin/vagrant.rb
80
+ - lib/kontena/plugin/vagrant/master/create_command.rb
81
+ - lib/kontena/plugin/vagrant/master/restart_command.rb
82
+ - lib/kontena/plugin/vagrant/master/ssh_command.rb
83
+ - lib/kontena/plugin/vagrant/master/start_command.rb
84
+ - lib/kontena/plugin/vagrant/master/stop_command.rb
85
+ - lib/kontena/plugin/vagrant/master/terminate_command.rb
86
+ - lib/kontena/plugin/vagrant/master_command.rb
87
+ - lib/kontena/plugin/vagrant/node_command.rb
88
+ - lib/kontena/plugin/vagrant/nodes/create_command.rb
89
+ - lib/kontena/plugin/vagrant/nodes/restart_command.rb
90
+ - lib/kontena/plugin/vagrant/nodes/ssh_command.rb
91
+ - lib/kontena/plugin/vagrant/nodes/start_command.rb
92
+ - lib/kontena/plugin/vagrant/nodes/stop_command.rb
93
+ - lib/kontena/plugin/vagrant/nodes/terminate_command.rb
94
+ - lib/kontena/plugin/vagrant_command.rb
95
+ - lib/kontena_cli_plugin.rb
96
+ homepage: https://krates.appsters.io
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubygems_version: 3.0.4
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Krates Vagrant plugin
119
+ test_files: []