vagrant-nodemaster 0.0.1

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 (36) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +1 -0
  4. data/lib/vagrant-nodemaster.rb +26 -0
  5. data/lib/vagrant-nodemaster/apidesc.rb +220 -0
  6. data/lib/vagrant-nodemaster/node/nodeadd.rb +33 -0
  7. data/lib/vagrant-nodemaster/node/nodedbmanager.rb +176 -0
  8. data/lib/vagrant-nodemaster/node/nodelist.rb +34 -0
  9. data/lib/vagrant-nodemaster/node/noderemove.rb +43 -0
  10. data/lib/vagrant-nodemaster/node/nodestatus.rb +73 -0
  11. data/lib/vagrant-nodemaster/node/nodeupdate.rb +43 -0
  12. data/lib/vagrant-nodemaster/nodecommand.rb +102 -0
  13. data/lib/vagrant-nodemaster/remote/remotebackupcommand.rb +90 -0
  14. data/lib/vagrant-nodemaster/remote/remotebackuplog.rb +62 -0
  15. data/lib/vagrant-nodemaster/remote/remotebackuptake.rb +50 -0
  16. data/lib/vagrant-nodemaster/remote/remoteboxadd.rb +35 -0
  17. data/lib/vagrant-nodemaster/remote/remoteboxcommand.rb +98 -0
  18. data/lib/vagrant-nodemaster/remote/remoteboxdelete.rb +40 -0
  19. data/lib/vagrant-nodemaster/remote/remoteboxlist.rb +32 -0
  20. data/lib/vagrant-nodemaster/remote/remotedestroy.rb +66 -0
  21. data/lib/vagrant-nodemaster/remote/remotehalt.rb +48 -0
  22. data/lib/vagrant-nodemaster/remote/remoteprovision.rb +43 -0
  23. data/lib/vagrant-nodemaster/remote/remoteresume.rb +32 -0
  24. data/lib/vagrant-nodemaster/remote/remotesnapshotcommand.rb +93 -0
  25. data/lib/vagrant-nodemaster/remote/remotesnapshotlist.rb +60 -0
  26. data/lib/vagrant-nodemaster/remote/remotesnapshotrestore.rb +34 -0
  27. data/lib/vagrant-nodemaster/remote/remotesnapshottake.rb +31 -0
  28. data/lib/vagrant-nodemaster/remote/remotessh.rb +55 -0
  29. data/lib/vagrant-nodemaster/remote/remotesuspend.rb +32 -0
  30. data/lib/vagrant-nodemaster/remote/remoteup.rb +43 -0
  31. data/lib/vagrant-nodemaster/remote/remotevmstatus.rb +43 -0
  32. data/lib/vagrant-nodemaster/remotecommand.rb +155 -0
  33. data/lib/vagrant-nodemaster/requestcontroller.rb +344 -0
  34. data/lib/vagrant-nodemaster/version.rb +5 -0
  35. data/vagrant-nodemaster.gemspec +29 -0
  36. metadata +157 -0
@@ -0,0 +1,34 @@
1
+ require 'vagrant-nodemaster/node/nodedbmanager'
2
+
3
+ module Vagrant
4
+ module NodeMaster
5
+
6
+ class NodeList < Vagrant.plugin(2, :command)
7
+ def execute
8
+
9
+ options = {}
10
+
11
+ opts = OptionParser.new do |opts|
12
+ opts.banner = "Usage: vagrant node list"
13
+ end
14
+
15
+ argv = parse_options(opts)
16
+ return if !argv
17
+ raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length != 0
18
+
19
+ dbmanager=DB::NodeDBManager.new
20
+
21
+ @env.ui.info("#{"NODE".ljust(25)} ADDRESS (PORT) ",:prefix => false)
22
+ dbmanager.get_nodes.each do |entry|
23
+ @env.ui.info("#{entry[:name].ljust(25)} #{entry[:address]}(#{entry[:port]})", :prefix => false)
24
+ end
25
+ @env.ui.info(" ", :prefix => false)
26
+ 0
27
+ end
28
+
29
+ end
30
+
31
+
32
+
33
+ end
34
+ end
@@ -0,0 +1,43 @@
1
+ require 'vagrant-nodemaster/node/nodedbmanager'
2
+
3
+ module Vagrant
4
+ module NodeMaster
5
+
6
+ class NodeRemove < Vagrant.plugin(2, :command)
7
+ # def initialize(sub_args, env,db)
8
+ # super(sub_args,env)
9
+ # @db=db
10
+ # end
11
+ def execute
12
+
13
+ options = {}
14
+
15
+ opts = OptionParser.new do |opts|
16
+ opts.banner = "Usage: vagrant node remove [node-name] --clean"
17
+ opts.on("-c","--clean", "Remove all nodes from list") do |c|
18
+ options[:clean] = c
19
+ end
20
+ end
21
+
22
+ argv = parse_options(opts)
23
+
24
+ return if !argv
25
+ raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if (argv.length < 1 && !options[:clean]) || (argv.length >1)
26
+
27
+ dbmanager=DB::NodeDBManager.new
28
+
29
+ if (options[:clean])
30
+ dbmanager.remove_nodes
31
+ elsif
32
+ dbmanager.remove_node(argv[0])
33
+ end
34
+
35
+ 0
36
+ end
37
+
38
+ end
39
+
40
+
41
+
42
+ end
43
+ end
@@ -0,0 +1,73 @@
1
+ require 'vagrant-nodemaster/node/nodedbmanager'
2
+ require 'socket'
3
+ require 'timeout'
4
+
5
+ module Vagrant
6
+ module NodeMaster
7
+
8
+ class NodeStatus < Vagrant.plugin(2, :command)
9
+
10
+ def execute
11
+
12
+ options = {}
13
+
14
+ opts = OptionParser.new do |opts|
15
+ opts.banner = "Usage: vagrant node status"
16
+ end
17
+
18
+ argv = parse_options(opts)
19
+ return if !argv
20
+ raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length != 0
21
+
22
+ dbmanager=DB::NodeDBManager.new
23
+
24
+ status = {}
25
+
26
+
27
+
28
+ dbmanager.get_nodes.each do |entry|
29
+ status[entry[:name]]=ERROR
30
+ if port_open?(entry[:address],entry[:port])
31
+ status[entry[:name]]=OK
32
+ end
33
+ end
34
+
35
+
36
+ #@env.ui.info("Client Status:", :prefix => false)
37
+ @env.ui.info("#{"NODE".ljust(25)} STATUS ",:prefix => false)
38
+ status.each do |name,status|
39
+ @env.ui.info("#{name.ljust(25)} #{status}",:prefix => false)
40
+ end
41
+
42
+ @env.ui.info(" ",:prefix => false)
43
+
44
+ 0
45
+ end
46
+
47
+
48
+ private
49
+ OK="LISTENING"
50
+ ERROR= "HOST DOWN"
51
+
52
+ def port_open?(ip, port, seconds=1)
53
+ begin
54
+ Timeout::timeout(seconds) do
55
+ begin
56
+ TCPSocket.new(ip, port).close
57
+ true
58
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
59
+ false
60
+ end
61
+ end
62
+
63
+ rescue Timeout::Error
64
+ false
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+
71
+
72
+ end
73
+ end
@@ -0,0 +1,43 @@
1
+ require 'vagrant-nodemaster/node/nodedbmanager'
2
+
3
+ module Vagrant
4
+ module NodeMaster
5
+
6
+ class NodeUpdate < Vagrant.plugin(2, :command)
7
+ # def initialize(sub_args, env,db)
8
+ # super(sub_args,env)
9
+ # @db=db
10
+ # end
11
+ def execute
12
+
13
+ options = {}
14
+
15
+ #TODO CAMBIAR LA FORMA DE INVOCAR A ESTE COMANDO PARA NO TENER
16
+ #QUE INTRODUCIR TODOS LOS DATOS SI SE QUIERE MODIFICAR LA INFORMACION
17
+ #DEL CLIENTE
18
+ opts = OptionParser.new do |opts|
19
+ opts.banner = "Usage: vagrant node update <node-name> <node-address> <node-port> --hostname"
20
+ opts.on("--hostname", "Address in dns format") do |d|
21
+ options[:dns] = d
22
+ end
23
+
24
+ end
25
+
26
+ argv = parse_options(opts)
27
+ return if !argv
28
+ raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length != 3
29
+
30
+ dbmanager=DB::NodeDBManager.new
31
+
32
+
33
+ dbmanager.update_node(argv[0],argv[1],argv[2].to_i,options[:dns])
34
+
35
+ 0
36
+ end
37
+
38
+ end
39
+
40
+
41
+
42
+ end
43
+ end
@@ -0,0 +1,102 @@
1
+ require 'vagrant/plugin'
2
+ require 'sqlite3'
3
+
4
+ module Vagrant
5
+ module NodeMaster
6
+
7
+ class Command < Vagrant.plugin(2, :command)
8
+
9
+ def initialize(argv, env)
10
+ super
11
+
12
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
13
+
14
+ # puts "MAIN ARGS #{@main_args}"
15
+ # puts "SUB COMMAND #{@sub_command}"
16
+ # puts "SUB ARGS #{@sub_args}"
17
+
18
+ @subcommands = Vagrant::Registry.new
19
+
20
+ @subcommands.register(:list) do
21
+ require File.expand_path("../node/nodelist", __FILE__)
22
+ NodeList
23
+ end
24
+
25
+ @subcommands.register(:add) do
26
+ require File.expand_path("../node/nodeadd", __FILE__)
27
+ NodeAdd
28
+ end
29
+
30
+ @subcommands.register(:remove) do
31
+ require File.expand_path("../node/noderemove", __FILE__)
32
+ NodeRemove
33
+ end
34
+
35
+ @subcommands.register(:update) do
36
+ require File.expand_path("../node/nodeupdate", __FILE__)
37
+ NodeUpdate
38
+ end
39
+
40
+ @subcommands.register(:status) do
41
+ require File.expand_path("../node/nodestatus", __FILE__)
42
+ NodeStatus
43
+ end
44
+
45
+ end
46
+
47
+
48
+
49
+
50
+
51
+ def execute
52
+ if @main_args.include?("-h") || @main_args.include?("--help")
53
+ # Print the help for all the box commands.
54
+ return help
55
+ end
56
+
57
+
58
+
59
+ # If we reached this far then we must have a subcommand. If not,
60
+ # then we also just print the help and exit.
61
+ command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
62
+ return help if !command_class || !@sub_command
63
+ @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
64
+
65
+ begin
66
+ # Initialize and execute the command class
67
+ command_class.new(@sub_args, @env).execute
68
+ rescue Exception => e
69
+ @env.ui.error(e.message)
70
+ end
71
+
72
+
73
+ 0
74
+ end
75
+
76
+ def help
77
+ opts = OptionParser.new do |opts|
78
+ opts.banner = "Usage: vagrant node <command> [<args>]"
79
+ opts.separator ""
80
+ opts.separator "Available subcommands:"
81
+
82
+ # Add the available subcommands as separators in order to print them
83
+ # out as well.
84
+ keys = []
85
+ @subcommands.each { |key, value| keys << key.to_s }
86
+
87
+ keys.sort.each do |key|
88
+ opts.separator " #{key}"
89
+ end
90
+
91
+ opts.separator ""
92
+ opts.separator "For help on any individual command run `vagrant node COMMAND -h`"
93
+ end
94
+
95
+ @env.ui.info(opts.help, :prefix => false)
96
+ end
97
+
98
+
99
+ end
100
+
101
+ end
102
+ end
@@ -0,0 +1,90 @@
1
+
2
+ require 'vagrant/plugin'
3
+
4
+
5
+ module Vagrant
6
+ module NodeMaster
7
+
8
+ class BackupCommand < Vagrant.plugin(2, :command)
9
+ def initialize(argv, env)
10
+ super
11
+
12
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
13
+
14
+ # puts "MAIN ARGS #{@main_args}"
15
+ # puts "SUB COMMAND #{@sub_command}"
16
+ # puts "SUB ARGS #{@sub_args}"
17
+
18
+ @subcommands = Vagrant::Registry.new
19
+
20
+ @subcommands.register(:take) do
21
+ require File.expand_path("../remotebackuptake", __FILE__)
22
+ BackupTake
23
+ end
24
+
25
+ @subcommands.register(:log) do
26
+ require File.expand_path("../remotebackuplog", __FILE__)
27
+ BackupLog
28
+ end
29
+
30
+
31
+ end
32
+
33
+ def execute
34
+ # if @main_args.include?("-h") || @main_args.include?("--help")
35
+ # Print the help for all the box commands.
36
+ # return help
37
+ # end
38
+
39
+ # If we reached this far then we must have a subcommand. If not,
40
+ # then we also just print the help and exit.
41
+ command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
42
+ return help if !command_class || !@sub_command
43
+
44
+ @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
45
+
46
+
47
+ begin
48
+ # Initialize and execute the command class
49
+ command_class.new(@sub_args, @env).execute
50
+ rescue RestClient::RequestFailed => e
51
+ @env.ui.error("Remote Client \"#{@sub_args[0]}\": Request Failed")
52
+ rescue RestClient::ResourceNotFound => e
53
+ @env.ui.error("Remote Client \"#{@sub_args[0]}\": Box \"#{@sub_args[1]}\" could not be found")
54
+ rescue RestClient::ExceptionWithResponse=> e
55
+ @env.ui.error(e.response)
56
+ rescue Exception => e
57
+ @env.ui.error(e.message)
58
+ end
59
+
60
+
61
+ end
62
+
63
+ def help
64
+ opts = OptionParser.new do |opts|
65
+ opts.banner = "Usage: vagrant remote backup <command> [<args>]"
66
+ opts.separator ""
67
+ opts.separator "Available subcommands:"
68
+
69
+ # Add the available subcommands as separators in order to print them
70
+ # out as well.
71
+ keys = []
72
+ @subcommands.each { |key, value| keys << key.to_s }
73
+
74
+ keys.sort.each do |key|
75
+ opts.separator " #{key}"
76
+ end
77
+
78
+ opts.separator ""
79
+ opts.separator "For help on any individual command run `vagrant remote COMMAND -h`"
80
+ end
81
+
82
+ @env.ui.info(opts.help, :prefix => false)
83
+ end
84
+
85
+
86
+
87
+
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,62 @@
1
+ require 'optparse'
2
+ require 'vagrant-nodemaster/requestcontroller'
3
+
4
+
5
+ module Vagrant
6
+ module NodeMaster
7
+
8
+ class BackupLog < Vagrant.plugin(2, :command)
9
+ def execute
10
+ options = {}
11
+
12
+
13
+ #FIXME add date params
14
+ opts = OptionParser.new do |opts|
15
+ opts.banner = "Usage: vagrant remote backup log <node-name> [vmname] [-h]"
16
+ # opts.separator ""
17
+ # opts.on("-b", "--background", "Take backup in background") do |b|
18
+ # options[:background] = b
19
+ # end
20
+
21
+ end
22
+
23
+
24
+ argv = parse_options(opts)
25
+
26
+ return if !argv
27
+ raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 1 || argv.length > 2
28
+
29
+
30
+ begin
31
+ log_entries=RequestController.node_backup_log(@env.ui,argv[0],argv[1])
32
+
33
+
34
+
35
+ if !log_entries.empty?
36
+ @env.ui.info("--------------------------------------------------------------------------------")
37
+ @env.ui.info("| DATE | VM NAME | STATUS |")
38
+ @env.ui.info("--------------------------------------------------------------------------------")
39
+
40
+ log_entries.each do |date,vm,status|
41
+ @env.ui.info("|#{date}|#{vm.rjust(13).ljust(23)} |#{status.rjust(20).ljust(33)}|")
42
+ @env.ui.info("--------------------------------------------------------------------------------")
43
+ end
44
+ end
45
+ rescue RestClient::ResourceNotFound => e
46
+ @env.ui.error("Remote Client \"#{argv[0]}\": No Records found ", :new_line => false)
47
+ if (argv[1])
48
+ @env.ui.error("for Virtual Machine \"#{argv[1]}\"")
49
+ else
50
+ @env.ui.error("for this node.")
51
+ end
52
+ end
53
+
54
+
55
+
56
+ 0
57
+ end
58
+
59
+
60
+ end
61
+ end
62
+ end