vagrant-nodemaster 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/vagrant-nodemaster.rb +26 -0
- data/lib/vagrant-nodemaster/apidesc.rb +220 -0
- data/lib/vagrant-nodemaster/node/nodeadd.rb +33 -0
- data/lib/vagrant-nodemaster/node/nodedbmanager.rb +176 -0
- data/lib/vagrant-nodemaster/node/nodelist.rb +34 -0
- data/lib/vagrant-nodemaster/node/noderemove.rb +43 -0
- data/lib/vagrant-nodemaster/node/nodestatus.rb +73 -0
- data/lib/vagrant-nodemaster/node/nodeupdate.rb +43 -0
- data/lib/vagrant-nodemaster/nodecommand.rb +102 -0
- data/lib/vagrant-nodemaster/remote/remotebackupcommand.rb +90 -0
- data/lib/vagrant-nodemaster/remote/remotebackuplog.rb +62 -0
- data/lib/vagrant-nodemaster/remote/remotebackuptake.rb +50 -0
- data/lib/vagrant-nodemaster/remote/remoteboxadd.rb +35 -0
- data/lib/vagrant-nodemaster/remote/remoteboxcommand.rb +98 -0
- data/lib/vagrant-nodemaster/remote/remoteboxdelete.rb +40 -0
- data/lib/vagrant-nodemaster/remote/remoteboxlist.rb +32 -0
- data/lib/vagrant-nodemaster/remote/remotedestroy.rb +66 -0
- data/lib/vagrant-nodemaster/remote/remotehalt.rb +48 -0
- data/lib/vagrant-nodemaster/remote/remoteprovision.rb +43 -0
- data/lib/vagrant-nodemaster/remote/remoteresume.rb +32 -0
- data/lib/vagrant-nodemaster/remote/remotesnapshotcommand.rb +93 -0
- data/lib/vagrant-nodemaster/remote/remotesnapshotlist.rb +60 -0
- data/lib/vagrant-nodemaster/remote/remotesnapshotrestore.rb +34 -0
- data/lib/vagrant-nodemaster/remote/remotesnapshottake.rb +31 -0
- data/lib/vagrant-nodemaster/remote/remotessh.rb +55 -0
- data/lib/vagrant-nodemaster/remote/remotesuspend.rb +32 -0
- data/lib/vagrant-nodemaster/remote/remoteup.rb +43 -0
- data/lib/vagrant-nodemaster/remote/remotevmstatus.rb +43 -0
- data/lib/vagrant-nodemaster/remotecommand.rb +155 -0
- data/lib/vagrant-nodemaster/requestcontroller.rb +344 -0
- data/lib/vagrant-nodemaster/version.rb +5 -0
- data/vagrant-nodemaster.gemspec +29 -0
- metadata +157 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
|
2
|
+
require 'vagrant/plugin'
|
3
|
+
|
4
|
+
|
5
|
+
module Vagrant
|
6
|
+
module NodeMaster
|
7
|
+
|
8
|
+
class SnapshotCommand < 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
|
+
|
21
|
+
@subcommands.register(:list) do
|
22
|
+
require File.expand_path("../remotesnapshotlist", __FILE__)
|
23
|
+
SnapshotList
|
24
|
+
end
|
25
|
+
|
26
|
+
@subcommands.register(:take) do
|
27
|
+
require File.expand_path("../remotesnapshottake", __FILE__)
|
28
|
+
SnapshotTake
|
29
|
+
end
|
30
|
+
|
31
|
+
@subcommands.register(:restore) do
|
32
|
+
require File.expand_path("../remotesnapshotrestore", __FILE__)
|
33
|
+
SnapshotRestore
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute
|
40
|
+
# if @main_args.include?("-h") || @main_args.include?("--help")
|
41
|
+
# Print the help for all the box commands.
|
42
|
+
# return help
|
43
|
+
# end
|
44
|
+
|
45
|
+
# If we reached this far then we must have a subcommand. If not,
|
46
|
+
# then we also just print the help and exit.
|
47
|
+
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
48
|
+
return help if !command_class || !@sub_command
|
49
|
+
|
50
|
+
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
|
51
|
+
|
52
|
+
begin
|
53
|
+
# Initialize and execute the command class
|
54
|
+
command_class.new(@sub_args, @env).execute
|
55
|
+
rescue RestClient::RequestFailed => e
|
56
|
+
@env.ui.error("Remote Client \"#{@sub_args[0]}\": Request Failed")
|
57
|
+
rescue RestClient::ResourceNotFound => e
|
58
|
+
@env.ui.error("Remote Client \"#{@sub_args[0]}\": Virtual Machine \"#{@sub_args[1]}\" could not be found")
|
59
|
+
rescue RestClient::ExceptionWithResponse=> e
|
60
|
+
@env.ui.error(e.response)
|
61
|
+
rescue Exception => e
|
62
|
+
@env.ui.error(e.message)
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def help
|
70
|
+
opts = OptionParser.new do |opts|
|
71
|
+
opts.banner = "Usage: vagrant remote snapshot <command> [<args>]"
|
72
|
+
opts.separator ""
|
73
|
+
opts.separator "Available subcommands:"
|
74
|
+
|
75
|
+
# Add the available subcommands as separators in order to print them
|
76
|
+
# out as well.
|
77
|
+
keys = []
|
78
|
+
@subcommands.each { |key, value| keys << key.to_s }
|
79
|
+
|
80
|
+
keys.sort.each do |key|
|
81
|
+
opts.separator " #{key}"
|
82
|
+
end
|
83
|
+
|
84
|
+
opts.separator ""
|
85
|
+
opts.separator "For help on any individual command run `vagrant remote COMMAND -h`"
|
86
|
+
end
|
87
|
+
|
88
|
+
@env.ui.info(opts.help, :prefix => false)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'vagrant-nodemaster/requestcontroller'
|
3
|
+
module Vagrant
|
4
|
+
module NodeMaster
|
5
|
+
#FIXME Mejorar tema de pintado, añadir opciones para una salida
|
6
|
+
#más reducidad y otra más extensa
|
7
|
+
class SnapshotList < Vagrant.plugin(2, :command)
|
8
|
+
def execute
|
9
|
+
options = {}
|
10
|
+
|
11
|
+
opts = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: vagrant remote snapshot list <node-name> [vmname]"
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
argv = parse_options(opts)
|
17
|
+
|
18
|
+
return if !argv
|
19
|
+
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 1 && argv.length > 2
|
20
|
+
|
21
|
+
snapshots = RequestController.get_remote_snapshots(argv[0],argv[1])
|
22
|
+
|
23
|
+
@env.ui.info("Remote Client \"#{argv[0]}\":", :prefix => false)
|
24
|
+
snapshots.each do |vmname,snapshots|
|
25
|
+
|
26
|
+
if (!snapshots || snapshots.empty?)
|
27
|
+
@env.ui.info("\nMachine \"#{vmname}\" #{NO_SNAPSHOT_MESSAGE}", :prefix => false)
|
28
|
+
else
|
29
|
+
@env.ui.info("\n--------------------------------------------------------------")
|
30
|
+
@env.ui.info("Machine \"#{vmname}\" Snapshots: ", :prefix => false)
|
31
|
+
@env.ui.info("--------------------------------------------------------------")
|
32
|
+
print_snapshots(snapshots)
|
33
|
+
@env.ui.info("\n")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
0
|
38
|
+
end
|
39
|
+
private
|
40
|
+
NO_SNAPSHOT_MESSAGE = "does not have any snapshots"
|
41
|
+
|
42
|
+
def print_snapshots(snapshots,level=1)
|
43
|
+
return if snapshots.empty?
|
44
|
+
|
45
|
+
snapshots.each { |snapshot|
|
46
|
+
space = " " * level
|
47
|
+
space = space + "* " if (snapshot[:current_state])
|
48
|
+
|
49
|
+
@env.ui.info("#{space}Date: #{snapshot[:timestamp].ljust(3)}")
|
50
|
+
@env.ui.info("#{space}Name: #{snapshot[:name]}")
|
51
|
+
@env.ui.info("#{space}UUID: #{snapshot[:uuid]}")
|
52
|
+
@env.ui.info("#{space}Description: #{snapshot[:description]}")
|
53
|
+
@env.ui.info("#{space}-----------------------------------------------------")
|
54
|
+
print_snapshots(snapshot[:snapshots],level+1)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'vagrant-nodemaster/requestcontroller'
|
3
|
+
module Vagrant
|
4
|
+
module NodeMaster
|
5
|
+
|
6
|
+
class SnapshotRestore < Vagrant.plugin(2, :command)
|
7
|
+
def execute
|
8
|
+
options = {}
|
9
|
+
|
10
|
+
opts = OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: vagrant remote snapshot restore <node-name> <vmname> <snapshot-uuid|snapshot-name]>"
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
argv = parse_options(opts)
|
16
|
+
|
17
|
+
return if !argv
|
18
|
+
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length != 3
|
19
|
+
|
20
|
+
begin
|
21
|
+
snapshot = RequestController.vm_snapshot_restore(argv[0],argv[1],argv[2])
|
22
|
+
|
23
|
+
@env.ui.info("Remote Client \"#{argv[0]}\": Virtual Machine \"#{argv[1]}\" => Restoring snapshot \"#{argv[2]}\"", :prefix => false)
|
24
|
+
#@env.ui.info("Snapshot \"#{snapshot[:name]}\" with UUID #{snapshot[:id]} succesfully created.")
|
25
|
+
rescue RestClient::ResourceNotFound => e
|
26
|
+
@env.ui.error("Remote Client \"#{@argv[0]}\": Virtual Machine \"#{argv[1]}\" => Snapshot \"#{argv[2]}\" could not be found")
|
27
|
+
end
|
28
|
+
0
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'vagrant-nodemaster/requestcontroller'
|
3
|
+
module Vagrant
|
4
|
+
module NodeMaster
|
5
|
+
|
6
|
+
class SnapshotTake < Vagrant.plugin(2, :command)
|
7
|
+
def execute
|
8
|
+
options = {}
|
9
|
+
|
10
|
+
opts = OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: vagrant remote snapshot take <node-name> <vmname> <name> [description]"
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
argv = parse_options(opts)
|
16
|
+
|
17
|
+
return if !argv
|
18
|
+
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 3 || argv.length > 4
|
19
|
+
|
20
|
+
snapshot = RequestController.vm_snapshot_take(argv[0],argv[1],argv[2],argv[3])
|
21
|
+
|
22
|
+
@env.ui.info("Remote Client: #{argv[0]}", :prefix => false)
|
23
|
+
@env.ui.info("Snapshot \"#{snapshot[:name]}\" with UUID #{snapshot[:id]} succesfully created.")
|
24
|
+
|
25
|
+
0
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'vagrant-nodemaster/requestcontroller'
|
3
|
+
|
4
|
+
require "vagrant/util/ssh"
|
5
|
+
|
6
|
+
module Vagrant
|
7
|
+
module NodeMaster
|
8
|
+
class SSHVM < Vagrant.plugin(2, :command)
|
9
|
+
include Vagrant::Util
|
10
|
+
def execute
|
11
|
+
options = {}
|
12
|
+
options[:force] = false
|
13
|
+
|
14
|
+
opts = OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage: vagrant remote ssh <node-name> <vm_name> [-h]"
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
argv = parse_options(opts)
|
21
|
+
return if !argv
|
22
|
+
|
23
|
+
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if (argv.length != 2)
|
24
|
+
|
25
|
+
|
26
|
+
#begin
|
27
|
+
|
28
|
+
#Gettting SSH Config for vm. Inside this machine, the parameter
|
29
|
+
#port is one that will be used at the client to make the redirection
|
30
|
+
#to the virtual machine
|
31
|
+
vminfo=RequestController.vm_ssh_config(argv[0],argv[1])
|
32
|
+
|
33
|
+
raise Errors::SSHNotReady if vminfo.nil?
|
34
|
+
|
35
|
+
SSH.exec(vminfo)
|
36
|
+
|
37
|
+
|
38
|
+
# rescue RestClient::RequestFailed => e
|
39
|
+
# @env.ui.error("Remote Client \"#{argv[0]}\": Request Failed")
|
40
|
+
# rescue RestClient::ResourceNotFound => e
|
41
|
+
# @env.ui.error("Remote Client \"#{argv[0]}\": Virtual Machine \"#{argv[1]}\" could not be found")
|
42
|
+
# rescue RestClient::ExceptionWithResponse=> e
|
43
|
+
# @env.ui.error(e.response)
|
44
|
+
# rescue Exception => e
|
45
|
+
# @env.ui.error(e.message)
|
46
|
+
# end
|
47
|
+
|
48
|
+
0
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'vagrant-nodemaster/requestcontroller'
|
3
|
+
module Vagrant
|
4
|
+
module NodeMaster
|
5
|
+
class SuspendVM < Vagrant.plugin(2, :command)
|
6
|
+
def execute
|
7
|
+
|
8
|
+
options = {}
|
9
|
+
|
10
|
+
opts = OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: vagrant remote suspend <node-name> [vm_name]"
|
12
|
+
end
|
13
|
+
|
14
|
+
argv = parse_options(opts)
|
15
|
+
return if !argv
|
16
|
+
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if (argv.length < 1 || argv.length > 2)
|
17
|
+
|
18
|
+
|
19
|
+
machines=RequestController.vm_suspend(argv[0],argv[1])
|
20
|
+
|
21
|
+
|
22
|
+
machines.each do |machine|
|
23
|
+
@env.ui.info("Remote Client \"#{argv[0]}\":Virtual Machine \"#{machine}\" suspended")
|
24
|
+
end
|
25
|
+
|
26
|
+
@env.ui.info(" ")
|
27
|
+
0
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'vagrant-nodemaster/requestcontroller'
|
3
|
+
module Vagrant
|
4
|
+
module NodeMaster
|
5
|
+
class UpVM < Vagrant.plugin(2, :command)
|
6
|
+
def execute
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
opts = OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: vagrant remote up <node-name> [vm_name]"
|
11
|
+
end
|
12
|
+
|
13
|
+
argv = parse_options(opts)
|
14
|
+
return if !argv
|
15
|
+
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if (argv.length < 1 || argv.length > 2)
|
16
|
+
|
17
|
+
# begin
|
18
|
+
|
19
|
+
|
20
|
+
machines=RequestController.vm_up(argv[0],argv[1])
|
21
|
+
|
22
|
+
|
23
|
+
machines.each do |machine|
|
24
|
+
@env.ui.info("Remote Client \"#{argv[0]}\": Virtual Machine \"#{machine}\" launched")
|
25
|
+
end
|
26
|
+
|
27
|
+
@env.ui.info(" ")
|
28
|
+
|
29
|
+
# rescue RestClient::RequestFailed => e
|
30
|
+
# @env.ui.error("Remote Client \"#{argv[0]}\": Request Failed")
|
31
|
+
# rescue RestClient::ResourceNotFound => e
|
32
|
+
# @env.ui.error("Remote Client \"#{argv[0]}\": Virtual Machine \"#{argv[1]}\" could not be found")
|
33
|
+
# rescue RestClient::ExceptionWithResponse=> e
|
34
|
+
# @env.ui.error(e.response)
|
35
|
+
# rescue Exception => e
|
36
|
+
# @env.ui.error(e.message)
|
37
|
+
# end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'vagrant-nodemaster/requestcontroller'
|
3
|
+
module Vagrant
|
4
|
+
module NodeMaster
|
5
|
+
class StatusVM < Vagrant.plugin(2, :command)
|
6
|
+
def execute
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
opts = OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: vagrant remote status <node-name> [vm_name]"
|
11
|
+
end
|
12
|
+
|
13
|
+
argv = parse_options(opts)
|
14
|
+
return if !argv
|
15
|
+
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if (argv.length < 1 || argv.length > 2)
|
16
|
+
|
17
|
+
# begin
|
18
|
+
machine_status=RequestController.vm_status(argv[0],argv[1])
|
19
|
+
|
20
|
+
@env.ui.info("Remote Client: #{argv[0]}", :prefix => false)
|
21
|
+
|
22
|
+
machine_status.each do |machine|
|
23
|
+
@env.ui.info(" * #{machine["name"].ljust(25)} #{machine["status"]} (#{machine["provider"]})", :prefix => false)
|
24
|
+
end
|
25
|
+
|
26
|
+
@env.ui.info(" ")
|
27
|
+
|
28
|
+
# rescue RestClient::RequestFailed => e
|
29
|
+
# @env.ui.error("Remote Client \"#{argv[0]}\": Request Failed")
|
30
|
+
# rescue RestClient::ResourceNotFound => e
|
31
|
+
# @env.ui.error("Remote Client \"#{argv[0]}\": Virtual Machine \"#{argv[1]}\" could not be found")
|
32
|
+
# rescue RestClient::ExceptionWithResponse=> e
|
33
|
+
# @env.ui.error(e.response)
|
34
|
+
# rescue Exception => e
|
35
|
+
# @env.ui.error(e.message)
|
36
|
+
# end
|
37
|
+
|
38
|
+
|
39
|
+
0
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
|
2
|
+
require 'vagrant/plugin'
|
3
|
+
|
4
|
+
|
5
|
+
module Vagrant
|
6
|
+
module NodeMaster
|
7
|
+
|
8
|
+
class Command < 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
|
+
# @subcommands.register(:add) do
|
20
|
+
# require File.expand_path("../add", __FILE__)
|
21
|
+
# Add
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# @subcommands.register(:boxlist) do
|
25
|
+
# require File.expand_path("../remoteboxlist", __FILE__)
|
26
|
+
# BoxList
|
27
|
+
# end
|
28
|
+
|
29
|
+
@subcommands.register(:box) do
|
30
|
+
require File.expand_path("../remote/remoteboxcommand", __FILE__)
|
31
|
+
BoxCommand
|
32
|
+
end
|
33
|
+
|
34
|
+
@subcommands.register(:up) do
|
35
|
+
require File.expand_path("../remote/remoteup", __FILE__)
|
36
|
+
UpVM
|
37
|
+
end
|
38
|
+
|
39
|
+
@subcommands.register(:halt) do
|
40
|
+
require File.expand_path("../remote/remotehalt", __FILE__)
|
41
|
+
HaltVM
|
42
|
+
end
|
43
|
+
|
44
|
+
@subcommands.register(:suspend) do
|
45
|
+
require File.expand_path("../remote/remotesuspend", __FILE__)
|
46
|
+
SuspendVM
|
47
|
+
end
|
48
|
+
|
49
|
+
@subcommands.register(:resume) do
|
50
|
+
require File.expand_path("../remote/remoteresume", __FILE__)
|
51
|
+
ResumeVM
|
52
|
+
end
|
53
|
+
|
54
|
+
@subcommands.register(:status) do
|
55
|
+
require File.expand_path("../remote/remotevmstatus", __FILE__)
|
56
|
+
StatusVM
|
57
|
+
end
|
58
|
+
|
59
|
+
@subcommands.register(:destroy) do
|
60
|
+
require File.expand_path("../remote/remotedestroy", __FILE__)
|
61
|
+
DestroyVM
|
62
|
+
end
|
63
|
+
|
64
|
+
@subcommands.register(:provision) do
|
65
|
+
require File.expand_path("../remote/remoteprovision", __FILE__)
|
66
|
+
ProvisionVM
|
67
|
+
end
|
68
|
+
|
69
|
+
@subcommands.register(:ssh) do
|
70
|
+
require File.expand_path("../remote/remotessh", __FILE__)
|
71
|
+
SSHVM
|
72
|
+
end
|
73
|
+
|
74
|
+
@subcommands.register(:snapshot) do
|
75
|
+
require File.expand_path("../remote/remotesnapshotcommand", __FILE__)
|
76
|
+
SnapshotCommand
|
77
|
+
end
|
78
|
+
|
79
|
+
@subcommands.register(:backup) do
|
80
|
+
require File.expand_path("../remote/remotebackupcommand", __FILE__)
|
81
|
+
BackupCommand
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
def execute
|
87
|
+
if @main_args.include?("-h") || @main_args.include?("--help")
|
88
|
+
# Print the help for all the box commands.
|
89
|
+
return help
|
90
|
+
end
|
91
|
+
|
92
|
+
# If we reached this far then we must have a subcommand. If not,
|
93
|
+
# then we also just print the help and exit.
|
94
|
+
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
95
|
+
return help if !command_class || !@sub_command
|
96
|
+
|
97
|
+
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
|
98
|
+
|
99
|
+
begin
|
100
|
+
# Initialize and execute the command class
|
101
|
+
command_class.new(@sub_args, @env).execute
|
102
|
+
rescue RestClient::RequestFailed => e
|
103
|
+
@env.ui.error("Remote Client \"#{@sub_args[0]}\": Request Failed")
|
104
|
+
rescue RestClient::ResourceNotFound => e
|
105
|
+
@env.ui.error("Remote Client \"#{@sub_args[0]}\": Virtual Machine \"#{@sub_args[1]}\" could not be found")
|
106
|
+
rescue RestClient::ExceptionWithResponse=> e
|
107
|
+
@env.ui.error(e.response)
|
108
|
+
rescue Exception => e
|
109
|
+
@env.ui.error(e.message)
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
def help
|
115
|
+
opts = OptionParser.new do |opts|
|
116
|
+
opts.banner = "Usage: vagrant remote <command> [<args>]"
|
117
|
+
opts.separator ""
|
118
|
+
opts.separator "Available subcommands:"
|
119
|
+
|
120
|
+
# Add the available subcommands as separators in order to print them
|
121
|
+
# out as well.
|
122
|
+
keys = []
|
123
|
+
@subcommands.each { |key, value| keys << key.to_s }
|
124
|
+
|
125
|
+
keys.sort.each do |key|
|
126
|
+
opts.separator " #{key}"
|
127
|
+
end
|
128
|
+
|
129
|
+
opts.separator ""
|
130
|
+
opts.separator "For help on any individual command run `vagrant remote COMMAND -h`"
|
131
|
+
end
|
132
|
+
|
133
|
+
@env.ui.info(opts.help, :prefix => false)
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
private
|
139
|
+
def echoEnv
|
140
|
+
puts "DEFAULT LOCAL DATA #{::Vagrant::Environment::DEFAULT_LOCAL_DATA}"
|
141
|
+
puts "VAGRANT FILE_NAME #{@env.vagrantfile_name}"
|
142
|
+
puts "VAGRANT CONFIG GLOBAL #{@env.config_global}"
|
143
|
+
puts "VAGRANT GEMS_PATH #{@env.gems_path}"
|
144
|
+
puts "VAGRANT HOME_PATH #{@env.home_path}"
|
145
|
+
puts "VAGRANT LOCAL_DATA_PATH #{@env.local_data_path}"
|
146
|
+
puts "VAGRANT TMP_PATH #{@env.tmp_path}"
|
147
|
+
puts "VAGRANT UI_OBJ #{@env.ui}"
|
148
|
+
puts "VAGRANT HOST_OBJ #{@env.host}"
|
149
|
+
puts "VAGRANT CWD #{@env.cwd}"
|
150
|
+
puts "VAGRANT LOCK_PATH #{@env.lock_path}"
|
151
|
+
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|