Module: Roby::App::Vagrant
- Defined in:
- lib/roby/app/vagrant.rb
Overview
Utilities related to Vagrant VMs
Defined Under Namespace
Classes: CannotResolveHostname, NotFound, NotRunning
Class Method Summary collapse
-
.resolve_ip(vagrant_name) ⇒ Object
Resolve the IP of a vagrant VM.
-
.resolve_vm(vagrant_name) ⇒ Object
Resolves the global ID of a vagrant VM.
Class Method Details
.resolve_ip(vagrant_name) ⇒ Object
Resolve the IP of a vagrant VM
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/roby/app/vagrant.rb', line 42 def self.resolve_ip(vagrant_name) id = resolve_vm(vagrant_name) IO.popen(["vagrant", "ssh-config", id]).each_line do |line| if line =~ /HostName (.*)/ return $1.strip end end raise CannotResolveHostname, "did not find a Hostname in the ssh-config of vagrant VM "\ "#{vagrant_name} (with id #{id}). Check the result of "\ "vagrant ssh-config #{id}" end |
.resolve_vm(vagrant_name) ⇒ Object
Resolves the global ID of a vagrant VM
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/roby/app/vagrant.rb', line 23 def self.resolve_vm(vagrant_name) IO.popen(%w[vagrant global-status]).each_line do |line| id, name, provider, state, * = line.chomp.split(/\s+/) if vagrant_name == id || vagrant_name == name if state != "running" raise NotRunning, "cannot connect to vagrant VM #{vagrant_name}: "\ "in state #{state} (requires running)" end return id end end raise NotFound, "cannot find a vagrant VM called #{vagrant_name}, "\ "run vagrant global-status to check vagrant's status" end |