Class: Phut::Vhost

Inherits:
Object
  • Object
show all
Includes:
ShellRunner
Defined in:
lib/phut/vhost.rb

Overview

An interface class to vhost emulation utility program.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ShellRunner

#sh

Constructor Details

#initialize(ip_address, mac_address, promisc, name = nil, logger = NullLogger.new) ⇒ Vhost

Returns a new instance of Vhost.



15
16
17
18
19
20
21
22
# File 'lib/phut/vhost.rb', line 15

def initialize(ip_address, mac_address, promisc,
               name = nil, logger = NullLogger.new)
  @ip_address = ip_address
  @promisc = promisc
  @name = name
  @mac_address = mac_address
  @logger = logger
end

Instance Attribute Details

#ip_addressObject (readonly)

Returns the value of attribute ip_address.



11
12
13
# File 'lib/phut/vhost.rb', line 11

def ip_address
  @ip_address
end

#mac_addressObject (readonly)

Returns the value of attribute mac_address.



12
13
14
# File 'lib/phut/vhost.rb', line 12

def mac_address
  @mac_address
end

#network_deviceObject

Returns the value of attribute network_device.



13
14
15
# File 'lib/phut/vhost.rb', line 13

def network_device
  @network_device
end

Instance Method Details

#maybe_stopObject



42
43
44
45
# File 'lib/phut/vhost.rb', line 42

def maybe_stop
  return unless running?
  stop
end

#nameObject



24
25
26
# File 'lib/phut/vhost.rb', line 24

def name
  @name || @ip_address
end

#run(all_hosts = []) ⇒ Object



32
33
34
35
# File 'lib/phut/vhost.rb', line 32

def run(all_hosts = [])
  @all_hosts ||= all_hosts
  sh "rvmsudo vhost run #{run_options}"
end

#running?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/phut/vhost.rb', line 47

def running?
  FileTest.exists?(pid_file)
end

#stopObject



37
38
39
40
# File 'lib/phut/vhost.rb', line 37

def stop
  fail "vhost (name = #{name}) is not running!" unless running?
  sh "vhost stop -n #{name} -s #{Phut.socket_dir}"
end

#to_sObject



28
29
30
# File 'lib/phut/vhost.rb', line 28

def to_s
  "vhost (name = #{name}, IP address = #{@ip_address})"
end