Class: PoolParty::Remote::VmwareInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(o = {}, cld = nil) ⇒ VmwareInstance

Returns a new instance of VmwareInstance.



7
8
9
10
11
12
13
14
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 7

def initialize(o={}, cld=nil)
  raise "You must pass a vmx_file" unless o[:vmx_file]
  @vmx_file = ::File.expand_path(o[:vmx_file])
  @ip = o[:ip]
  @keypair = o[:keypair]
  
  @cloud = cld
end

Instance Attribute Details

#cloudObject (readonly)

Returns the value of attribute cloud.



5
6
7
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 5

def cloud
  @cloud
end

#ipObject (readonly)

Returns the value of attribute ip.



5
6
7
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 5

def ip
  @ip
end

#keypairObject (readonly)

Returns the value of attribute keypair.



5
6
7
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 5

def keypair
  @keypair
end

#mac_addressObject (readonly)

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



58
59
60
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 58

def mac_address
  @mac_address
end

#vmx_fileObject (readonly)

Returns the value of attribute vmx_file.



5
6
7
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 5

def vmx_file
  @vmx_file
end

Instance Method Details

#launch!Object



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

def launch!
  Vmrun.run_local("#{Vmrun.path_to_binary} start \"#{vmx_file}\"")
  dputs "Launched new vmware instance from vmx: #{vmx_file}"
  to_hash
end

#parse_vmx_fileObject



61
62
63
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 61

def parse_vmx_file
  vmx_data.to_hash
end

#pending?Boolean

Is this instance pending?

Returns:

  • (Boolean)


34
35
36
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 34

def pending?
  false
end

#running?Boolean

Is this instance running?

Returns:

  • (Boolean)


30
31
32
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 30

def running?
  true
end

#statusObject



26
27
28
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 26

def status
  "running"
end

#terminate!(o) ⇒ Object



50
51
52
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 50

def terminate!(o)
  Vmrun.run_local("#{Vmrun.path_to_binary} stop \"#{vmx_file}\" #{o}")
end

#terminated?Boolean

Has this instance been terminated?

Returns:

  • (Boolean)


42
43
44
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 42

def terminated?
  false
end

#terminating?Boolean

Is this instance terminating?

Returns:

  • (Boolean)


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

def terminating?
  false
end

#to_hashObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 16

def to_hash
  {
    :status => status,
    :mac_addresses => mac_address,
    :ip => ip,
    :instance_id => vmx_file,
    :internal_ip => ip,
    :keypair => keypair
  }
end

#vmx_dataObject



64
65
66
# File 'lib/poolparty/net/remoter_bases/vmrun/vmrun_instance.rb', line 64

def vmx_data
  @vmx_data ||= open(vmx_file).read
end