Class: Phut::Vhost
Overview
An interface class to vhost emulation utility program.
Instance Attribute Summary collapse
-
#ip_address ⇒ Object
readonly
Returns the value of attribute ip_address.
-
#mac_address ⇒ Object
readonly
Returns the value of attribute mac_address.
-
#network_device ⇒ Object
Returns the value of attribute network_device.
Class Method Summary collapse
- .create(ip_address, mac_address, promisc, name = nil, logger = NullLogger.new) ⇒ Object
- .each(&block) ⇒ Object
-
.find_by(queries) ⇒ Object
This method smells of :reek:NestedIterators but ignores them.
Instance Method Summary collapse
-
#initialize(ip_address, mac_address, promisc, name, logger) ⇒ Vhost
constructor
A new instance of Vhost.
- #name ⇒ Object
- #run(all_hosts = Vhost.all) ⇒ Object
- #running? ⇒ Boolean
- #stop ⇒ Object
- #stop! ⇒ Object
- #to_s ⇒ Object
Methods included from ShellRunner
Constructor Details
#initialize(ip_address, mac_address, promisc, name, logger) ⇒ Vhost
Returns a new instance of Vhost.
38 39 40 41 42 43 44 |
# File 'lib/phut/vhost.rb', line 38 def initialize(ip_address, mac_address, promisc, name, logger) @ip_address = ip_address @promisc = promisc @name = name @mac_address = mac_address @logger = logger end |
Instance Attribute Details
#ip_address ⇒ Object (readonly)
Returns the value of attribute ip_address.
34 35 36 |
# File 'lib/phut/vhost.rb', line 34 def ip_address @ip_address end |
#mac_address ⇒ Object (readonly)
Returns the value of attribute mac_address.
35 36 37 |
# File 'lib/phut/vhost.rb', line 35 def mac_address @mac_address end |
#network_device ⇒ Object
Returns the value of attribute network_device.
36 37 38 |
# File 'lib/phut/vhost.rb', line 36 def network_device @network_device end |
Class Method Details
.create(ip_address, mac_address, promisc, name = nil, logger = NullLogger.new) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/phut/vhost.rb', line 12 def self.create(ip_address, mac_address, promisc, name = nil, logger = NullLogger.new) new(ip_address, mac_address, promisc, name, logger).tap do |vhost| conflict = find_by(name: vhost.name) fail "The name #{vhost.name} conflicts with #{conflict}." if conflict all << vhost end end |
.each(&block) ⇒ Object
28 29 30 |
# File 'lib/phut/vhost.rb', line 28 def self.each(&block) all.each(&block) end |
.find_by(queries) ⇒ Object
This method smells of :reek:NestedIterators but ignores them
22 23 24 25 26 |
# File 'lib/phut/vhost.rb', line 22 def self.find_by(queries) queries.inject(all) do |memo, (attr, value)| memo.find_all { |vhost| vhost.__send__(attr) == value } end.first end |
Instance Method Details
#name ⇒ Object
46 47 48 |
# File 'lib/phut/vhost.rb', line 46 def name @name || @ip_address end |
#run(all_hosts = Vhost.all) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/phut/vhost.rb', line 54 def run(all_hosts = Vhost.all) @all_hosts ||= all_hosts if ENV['rvm_path'] sh "rvmsudo vhost run #{}" else vhost = File.join(__dir__, '..', '..', 'bin', 'vhost') sh "bundle exec sudo #{vhost} run #{}" end end |
#running? ⇒ Boolean
74 75 76 |
# File 'lib/phut/vhost.rb', line 74 def running? FileTest.exists?(pid_file) end |
#stop ⇒ Object
64 65 66 67 |
# File 'lib/phut/vhost.rb', line 64 def stop return unless running? stop! end |
#stop! ⇒ Object
69 70 71 72 |
# File 'lib/phut/vhost.rb', line 69 def stop! fail "vhost (name = #{name}) is not running!" unless running? sh "vhost stop -n #{name} -S #{Phut.socket_dir}" end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/phut/vhost.rb', line 50 def to_s "vhost (name = #{name}, IP address = #{@ip_address})" end |