Class: PoolParty::Remote::VmwareInstance

Inherits:
RemoteInstance show all
Includes:
Pinger
Defined in:
lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb

Instance Method Summary collapse

Methods included from Pinger

included

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.expand_path(o[:vmx_file])
  # o.delete(:status)
  super o
end

Instance Method Details

#instance_idObject



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?
    dsl_options[:mac_address] ||= parse_vmx_file[:"ethernet0.generatedAddress"]
  else
    dsl_options[:mac_address] = mac
  end
end

#parse_vmx_fileObject



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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


37
38
39
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 37

def running?
  true
end

#statusObject



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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


45
46
47
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 45

def terminating?
  false
end

#to_hashObject



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_dataObject



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