class Sumodev::Commands::Box
Public Instance Methods
box_path()
click to toggle source
# File lib/sumodev/commands/box.rb, line 9 def box_path possible_paths = [ Dir.pwd, Sumodev::Config.get('SUMO_VAGRANT_PATH') ] vagrantfile = possible_paths.detect do |path| File.file?(File.join(File.expand_path(path), "Vagrantfile")) end || raise("No Vagrant file found in #{possible_paths.join(', ')}") File.expand_path(vagrantfile) end
box_running?()
click to toggle source
# File lib/sumodev/commands/box.rb, line 30 def box_running? output = `cd #{box_path}; vagrant status` output =~ /The VM is running/ end
convert_sumofile_into_env_variables()
click to toggle source
# File lib/sumodev/commands/box.rb, line 35 def convert_sumofile_into_env_variables sumofile_path = Dir.pwd + "/Sumofile" file = Sumodev::Sumofile.from_file sumofile_path file.convert_into_json_file end
install()
click to toggle source
# File lib/sumodev/commands/box.rb, line 54 def install # install vagrant plugins %x(vagrant plugin install vagrant-share) %x(vagrant plugin install vagrant-berkshelf) # install .sumorc file unless File.exists?(File.expand_path("~/.sumorc")) File.open(File.expand_path("~/.sumorc"), 'w') do |f| f.write <<-SUMORC export SUMO_VAGRANT_PATH="" SUMORC end end # setup resolver File.open("/tmp/vagrant-resolver", 'w') do |f| f.write <<-RESOLVER # Created by sumo command nameserver 10.11.12.13 port 53 RESOLVER end %x(sudo mv /tmp/vagrant-resolver /etc/resolver/vagrant) end
run_vagrant_command(command, *arguments)
click to toggle source
# File lib/sumodev/commands/box.rb, line 22 def run_vagrant_command(command, *arguments) # See https://github.com/mitchellh/vagrant/issues/5199#issuecomment-73278236 if ["reload", "halt"].include?(command.split(" ")[0]) system "rm -rf #{box_path}/.vagrant/machines/*/virtualbox/synced_folders" end system "cd #{box_path}; vagrant #{command} #{arguments.join(' ')}" end
up()
click to toggle source
# File lib/sumodev/commands/box.rb, line 44 def up say("There is already a box running, you should manually start the box. Or halt the running instance", :red) && exit(1) if box_running? convert_sumofile_into_env_variables run_vagrant_command("up", "--provision") rescue Sumodev::Sumofile::NoSuchFileError say("No Sumofile found! Please define one so the correct versions will be used!", :red) && exit(1) end