aboutsummaryrefslogtreecommitdiff
path: root/lib/leap_cli/commands/vagrant.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-12-08 20:02:27 -0800
committerelijah <elijah@riseup.net>2012-12-08 20:02:27 -0800
commit8572dfd59c21d2032b030adc9dc9a973c6e1c3f5 (patch)
tree3d3fb221339ddf4fa0037cbd88133431307f2e4e /lib/leap_cli/commands/vagrant.rb
parent155d744f6c6f94709925f0674f510b3064b6608e (diff)
downloadleap_cli-8572dfd59c21d2032b030adc9dc9a973c6e1c3f5.tar.gz
leap_cli-8572dfd59c21d2032b030adc9dc9a973c6e1c3f5.tar.bz2
added commands 'node add' 'node rm' and 'node mv'
Diffstat (limited to 'lib/leap_cli/commands/vagrant.rb')
-rw-r--r--lib/leap_cli/commands/vagrant.rb39
1 files changed, 24 insertions, 15 deletions
diff --git a/lib/leap_cli/commands/vagrant.rb b/lib/leap_cli/commands/vagrant.rb
index cd3e71b..a9c2928 100644
--- a/lib/leap_cli/commands/vagrant.rb
+++ b/lib/leap_cli/commands/vagrant.rb
@@ -10,7 +10,6 @@ module LeapCli; module Commands
local.arg_name 'node-filter', :optional => true #, :multiple => false
local.command :start do |start|
start.action do |global_options,options,args|
- vagrant_setup
vagrant_command(["up", "sandbox on"], args)
end
end
@@ -19,7 +18,6 @@ module LeapCli; module Commands
local.arg_name 'node-filter', :optional => true #, :multiple => false
local.command :stop do |stop|
stop.action do |global_options,options,args|
- vagrant_setup
vagrant_command("halt", args)
end
end
@@ -28,7 +26,6 @@ module LeapCli; module Commands
local.arg_name 'node-filter', :optional => true #, :multiple => false
local.command :reset do |reset|
reset.action do |global_options,options,args|
- vagrant_setup
vagrant_command("sandbox rollback", args)
end
end
@@ -37,7 +34,6 @@ module LeapCli; module Commands
local.arg_name 'node-filter', :optional => true #, :multiple => false
local.command :destroy do |destroy|
destroy.action do |global_options,options,args|
- vagrant_setup
vagrant_command("destroy", args)
end
end
@@ -46,7 +42,6 @@ module LeapCli; module Commands
local.arg_name 'node-filter', :optional => true #, :multiple => false
local.command :status do |status|
status.action do |global_options,options,args|
- vagrant_setup
vagrant_command("status", args)
end
end
@@ -66,18 +61,10 @@ module LeapCli; module Commands
return file_path
end
- private
-
- 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
+ protected
def vagrant_command(cmds, args)
+ vagrant_setup
cmds = cmds.to_a
assert_config! 'provider.vagrant.network'
if args.empty?
@@ -99,6 +86,17 @@ module LeapCli; module Commands
end
end
+ private
+
+ 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 execute(cmd)
log 2, :run, cmd
exec cmd
@@ -123,4 +121,15 @@ module LeapCli; module Commands
write_file! :vagrantfile, lines.join("\n")
end
+ def pick_next_vagrant_ip_address
+ taken_ips = manager.nodes[:local => true].field(:ip_address)
+ if taken_ips.any?
+ highest_ip = taken_ips.map{|ip| IPAddr.new(ip)}.max
+ new_ip = highest_ip.succ
+ else
+ new_ip = IPAddr.new(manager.provider.vagrant.network).succ.succ
+ end
+ return new_ip.to_s
+ end
+
end; end \ No newline at end of file