summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-11-27 01:40:52 -0800
committerelijah <elijah@riseup.net>2012-11-27 01:40:52 -0800
commit20e74d2a3e029c53439d79436fa8ca2f07a9d100 (patch)
tree9b7aefc099d6e0e5463f09d86f5b750f1f605767
parentb5bf2fe3874f9ce97b36dc37b17ce66270260f03 (diff)
better vagrant commands, now all grouped under 'leap local'
-rw-r--r--lib/leap_cli/commands/vagrant.rb79
1 files changed, 59 insertions, 20 deletions
diff --git a/lib/leap_cli/commands/vagrant.rb b/lib/leap_cli/commands/vagrant.rb
index 41dccc9..7765de0 100644
--- a/lib/leap_cli/commands/vagrant.rb
+++ b/lib/leap_cli/commands/vagrant.rb
@@ -3,27 +3,52 @@ require 'fileutils'
module LeapCli; module Commands
- desc 'Bring up one or more local virtual machines'
- arg_name '[node-filter]', :optional => true, :multiple => false
- command :'local-up' do |c|
- c.action do |global_options,options,args|
- vagrant_command("up", args)
+ desc "Manage local virtual machines"
+ long_desc "This command provides a convient way to manage Vagrant-based virtual machines. The Vagrantfile is automatically generated in test/Vagrantfile."
+ command :local do |c|
+ c.desc 'Starts up the virtual machine'
+ c.arg_name 'node-name', :optional => false #, :multiple => false
+ c.command :start do |c|
+ c.action do |global_options,options,args|
+ vagrant_setup
+ vagrant_command(["up", "sandbox on"], args)
+ end
end
- end
- desc 'Halt one or more local virtual machines'
- arg_name '[node-filter]', :optional => true, :multiple => false
- command :'local-down' do |c|
- c.action do |global_options,options,args|
- vagrant_command("halt", args)
+ c.desc 'Shuts down the virtual machine'
+ c.arg_name 'node-name', :optional => false #, :multiple => false
+ c.command :stop do |c|
+ c.action do |global_options,options,args|
+ vagrant_setup
+ vagrant_command("halt", args)
+ end
end
- end
- desc 'Destroy one or more local virtual machines'
- arg_name '[node-filter]', :optional => true, :multiple => false
- command :'local-reset' do |c|
- c.action do |global_options,options,args|
- vagrant_command("destroy", args)
+ c.desc 'Resets virtual machine to a pristine state'
+ c.arg_name 'node-name', :optional => false #, :multiple => false
+ c.command :reset do |c|
+ c.action do |global_options,options,args|
+ vagrant_setup
+ vagrant_command("sandbox rollback")
+ end
+ end
+
+ c.desc 'Destroys the virtual machine, reclaiming the disk space'
+ c.arg_name 'node-name', :optional => false #, :multiple => false
+ c.command :destroy do |c|
+ c.action do |global_options,options,args|
+ vagrant_setup
+ vagrant_command("destroy", args)
+ end
+ end
+
+ c.desc 'Print the status of local virtual machine'
+ c.arg_name 'node-name', :optional => false #, :multiple => false
+ c.command :status do |c|
+ c.action do |global_options,options,args|
+ vagrant_setup
+ vagrant_command("status", args)
+ end
end
end
@@ -43,12 +68,26 @@ module LeapCli; module Commands
private
- def vagrant_command(cmd, args)
- assert_config! 'provider.vagrant.network'
+ def vagrant_setup
+ assert_bin! 'vagrant', 'run "sudo gem install vagrant"'
+ unless `vagrant gem which sahara`.chars.any?
+ log :installing, "vagrant plugin 'sahara'"
+ assert_run! 'vagrant gem install sahara'
+ end
create_vagrant_file
+ end
+
+ def vagrant_command(cmds, args)
+ cmds = cmds.to_a
+ assert_config! 'provider.vagrant.network'
nodes = manager.filter(args)[:local => true].field(:name)
if nodes.any?
- execute "cd #{File.dirname(Path.named_path(:vagrantfile))}; vagrant #{cmd} #{nodes.join(' ')}"
+ vagrant_dir = File.dirname(Path.named_path(:vagrantfile))
+ exec = ["cd #{vagrant_dir}"]
+ cmds.each do |cmd|
+ exec << "vagrant #{cmd} #{nodes.join(' ')}"
+ end
+ execute exec.join('; ')
else
bail! "No nodes found. This command only works on nodes with ip_address in the network #{manager.provider.vagrant.network}"
end