Module: Cuken::Api::Vagrant::Common
- Included in:
- Cuken::Api::Vagrant
- Defined in:
- lib/cuken/api/vagrant/common.rb
Instance Method Summary collapse
- #check_vagrant_file_presence(path, expect_presence = true) ⇒ Object
- #check_vm_active(name, expect_active = true) ⇒ Object
- #check_vm_state(name, state, expect_state = true) ⇒ Object
- #establish_vm_interactive_ssh(boxname) ⇒ Object
- #load_vagrant_file(path, expect_presence = true) ⇒ Object
- #run_vm_manager_command(cmd, vm_name, vm_manager = :vagrant) ⇒ Object
Instance Method Details
#check_vagrant_file_presence(path, expect_presence = true) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cuken/api/vagrant/common.rb', line 37 def check_vagrant_file_presence(path, expect_presence = true) if Pathname(chef.root_dir).exist? in_chef_root do if expect_presence load_vagrant_file(path) end end else in_dir do if expect_presence load_vagrant_file(path) end end end end |
#check_vm_active(name, expect_active = true) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cuken/api/vagrant/common.rb', line 53 def check_vm_active(name, expect_active = true ) in_chef_root do if expect_active if vagrant.environment.local_data[:active][name].nil? vagrant.up(name) end vagrant.environment.local_data[:active][name].should_not be_nil else if vagrant.environment.local_data[:active][name] vagrant.halt(name) end vagrant.environment.local_data[:active][name].should be_nil end end end |
#check_vm_state(name, state, expect_state = true) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cuken/api/vagrant/common.rb', line 69 def check_vm_state(name, state, expect_state = true ) in_chef_root do if expect_state # puts vagrant.status(name).inspect vagrant.vm[name.to_sym].vm.state.should == state else puts vagrant.status(name).inspect vagrant.status(name).include?(state).should be_false end end end |
#establish_vm_interactive_ssh(boxname) ⇒ Object
22 23 24 25 26 |
# File 'lib/cuken/api/vagrant/common.rb', line 22 def establish_vm_interactive_ssh(boxname) name = vagrant.vm.key?(:primary) ? :primary : boxname.to_sym cmd = vagrant.vm[name].ssh.ssh_connect_command run_interactive(unescape(cmd)) end |
#load_vagrant_file(path, expect_presence = true) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/cuken/api/vagrant/common.rb', line 28 def load_vagrant_file(path, expect_presence = true) vagrant.path = Pathname(path)..realdirpath if expect_presence vagrant.path.exist?.should be_true else vagrant.path.exist?.should be_false end end |
#run_vm_manager_command(cmd, vm_name, vm_manager = :vagrant) ⇒ Object
81 82 83 |
# File 'lib/cuken/api/vagrant/common.rb', line 81 def run_vm_manager_command(cmd, vm_name, vm_manager = :vagrant) method(vm_manager).call.send(cmd, vm_name) end |