Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # note this requires vagrant ~>1.0
- # sahara as shipped requires vagrant ~>0.9
- # forcing sahara's vagrant dependency to >0.9 seems to make it go
- # though I don't know what it may break
- # evolving at https://github.com/jon-proulx/cucumber-vagrant-sahara
- require 'rubygems'
- require 'vagrant'
- require 'sahara'
- class VagrantBox
- attr_reader :env, :cwd
- def initialize(basebox)
- #brittle code...
- @name=basebox
- @cwd=File.join("/scratch/vagrant-boxen",@name)
- @env=Vagrant::Environment.new(:cwd =>@cwd)
- Dir.mkdir(@cwd) unless File::directory?(@cwd)
- File.open(File.join(@cwd,"Vagrantfile"),"w+") do |conf_file|
- conf_file.write """Vagrant::Config.run do |config|
- config.vm.box = \'#{@name}\'
- end
- """
- end
- end
- def up
- # We might be created but suspended too, need to handle more cases
- if @env.primary_vm.state != :running
- print "Booting #{@name} patience..."
- @env.cli("up")
- puts "done"
- end
- raise "Failed to start vm #{@name} " if @env.primary_vm.state != :running
- end
- def freeze
- @env.cli("sandbox","on")
- end
- def rollback
- @env.cli("sandbox","rollback")
- end
- end
- Given /^a vagrant vm (\w+) (?:is running|is up|)$/ do |box|
- @mybox=VagrantBox.new(box)
- @mybox.up
- end
- Given /^I freeze the vm$/ do
- @mybox.env.cli("sandbox","on")
- end
Advertisement
Add Comment
Please, Sign In to add comment