Class: PoolParty::Remote::VmwareInstance
- Inherits:
-
RemoteInstance
- Object
- RemoteInstance
- PoolParty::Remote::VmwareInstance
- Includes:
- Pinger
- Defined in:
- lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb
Instance Method Summary collapse
-
#initialize(o = {}) ⇒ VmwareInstance
constructor
A new instance of VmwareInstance.
- #instance_id ⇒ Object
- #launch! ⇒ Object
-
#mac_address(mac = nil) ⇒ Object
Get the ip from the arp -a def ip @ip ||= %x[arp -a].select {|a| a if a =~ /#{mac_address.macify}/}.first end Get the mac address in the vmx_file.
- #parse_vmx_file ⇒ Object
-
#pending? ⇒ Boolean
Is this instance pending?.
-
#running? ⇒ Boolean
Is this instance running?.
- #status ⇒ Object
- #terminate!(o) ⇒ Object
-
#terminated? ⇒ Boolean
Has this instance been terminated?.
-
#terminating? ⇒ Boolean
Is this instance terminating?.
- #to_hash ⇒ Object
- #vmx_data ⇒ Object
Methods included from Pinger
Methods inherited from RemoteInstance
#[], #[]=, #each, #elapsed_runtime, #has_key?, #keys, #load, #on_init, #valid?, #values
Constructor Details
#initialize(o = {}) ⇒ VmwareInstance
Returns a new instance of VmwareInstance.
9 10 11 12 13 14 |
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 9 def initialize(o={}) raise "You must pass a vmx_file" unless o[:vmx_file] @vmx_file = ::File.(o[:vmx_file]) # o.delete(:status) super o end |
Instance Method Details
#instance_id ⇒ Object
28 29 30 |
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 28 def instance_id vmx_file end |
#launch! ⇒ Object
53 54 55 56 57 |
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 53 def launch! Vmrun.run_local("#{Vmrun.path_to_binary} start \"#{vmx_file}\"") dputs "Launched new vmware instance from vmx: #{vmx_file}" to_hash end |
#mac_address(mac = nil) ⇒ Object
Get the ip from the arp -a def ip
@ip ||= %x[arp -a].select {|a| a if a =~ /#{mac_address.macify}/}.first[/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/]
end Get the mac address in the vmx_file
68 69 70 71 72 73 74 |
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 68 def mac_address(mac=nil) if mac.nil? [:mac_address] ||= parse_vmx_file[:"ethernet0.generatedAddress"] else [:mac_address] = mac end end |
#parse_vmx_file ⇒ Object
76 77 78 |
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 76 def parse_vmx_file vmx_data.to_hash end |
#pending? ⇒ Boolean
Is this instance pending?
41 42 43 |
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 41 def pending? false end |
#running? ⇒ Boolean
Is this instance running?
37 38 39 |
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 37 def running? true end |
#status ⇒ Object
32 33 34 |
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 32 def status ping_port(ip, 22, 1) ? "running" : "terminated" end |
#terminate!(o) ⇒ Object
59 60 61 |
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 59 def terminate!(o) Vmrun.run_local("#{Vmrun.path_to_binary} stop \"#{vmx_file}\" #{o}") end |
#terminated? ⇒ Boolean
Has this instance been terminated?
49 50 51 |
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 49 def terminated? false end |
#terminating? ⇒ Boolean
Is this instance terminating?
45 46 47 |
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 45 def terminating? false end |
#to_hash ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 16 def to_hash { :status => status, :mac_address => mac_address, :ip => ip, :public_ip => ip, :internal_ip => ip, :instance_id => vmx_file, :vmx_file => vmx_file, :keypair => keypair } end |
#vmx_data ⇒ Object
80 81 82 |
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 80 def vmx_data @vmx_data ||= open(vmx_file).read end |