Class: Phut::VhostDaemon
- Inherits:
-
Object
- Object
- Phut::VhostDaemon
- Defined in:
- lib/phut/vhost_daemon.rb
Overview
vhost daemon process rubocop:disable ClassLength
Class Method Summary collapse
Instance Method Summary collapse
- #arp_table=(arp_table) ⇒ Object
- #device ⇒ Object
- #device=(name) ⇒ Object
-
#initialize(options) ⇒ VhostDaemon
constructor
A new instance of VhostDaemon.
- #ip_address ⇒ Object
- #kill ⇒ Object
- #mac_address ⇒ Object
- #name ⇒ Object
- #reset_stats ⇒ Object
- #run ⇒ Object
- #running? ⇒ Boolean
- #send_packets(dest, npackets) ⇒ Object
- #stats ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options) ⇒ VhostDaemon
Returns a new instance of VhostDaemon.
20 21 22 23 24 25 26 27 |
# File 'lib/phut/vhost_daemon.rb', line 20 def initialize() @options = .dup @options[:device] = @options.fetch(:interface) @options[:log_dir] = File.(@options[:log_dir]) @options[:pid_dir] = File.(@options[:pid_dir]) @options[:socket_dir] = File.(@options[:socket_dir]) reset_stats end |
Class Method Details
.process(name, socket_dir) ⇒ Object
16 17 18 |
# File 'lib/phut/vhost_daemon.rb', line 16 def self.process(name, socket_dir) DRbObject.new_with_uri(unix_domain_socket(name, socket_dir)) end |
.unix_domain_socket(name, socket_dir) ⇒ Object
12 13 14 |
# File 'lib/phut/vhost_daemon.rb', line 12 def self.unix_domain_socket(name, socket_dir) "drbunix:#{socket_dir}/vhost.#{name}.ctl" end |
Instance Method Details
#arp_table=(arp_table) ⇒ Object
88 89 90 |
# File 'lib/phut/vhost_daemon.rb', line 88 def arp_table=(arp_table) @options[:arp_table] = arp_table end |
#device ⇒ Object
41 42 43 |
# File 'lib/phut/vhost_daemon.rb', line 41 def device @options[:device] end |
#device=(name) ⇒ Object
45 46 47 |
# File 'lib/phut/vhost_daemon.rb', line 45 def device=(name) @options[:device] = name end |
#ip_address ⇒ Object
33 34 35 |
# File 'lib/phut/vhost_daemon.rb', line 33 def ip_address @options.fetch :ip_address end |
#kill ⇒ Object
66 67 68 |
# File 'lib/phut/vhost_daemon.rb', line 66 def kill @kill = true end |
#mac_address ⇒ Object
37 38 39 |
# File 'lib/phut/vhost_daemon.rb', line 37 def mac_address @options.fetch :mac_address end |
#name ⇒ Object
29 30 31 |
# File 'lib/phut/vhost_daemon.rb', line 29 def name @options.fetch :name end |
#reset_stats ⇒ Object
83 84 85 86 |
# File 'lib/phut/vhost_daemon.rb', line 83 def reset_stats @packets_sent = [] @packets_received = [] end |
#run ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/phut/vhost_daemon.rb', line 49 def run start_logging create_pid_file start_daemon @stop = false rescue shutdown end |
#running? ⇒ Boolean
58 59 60 |
# File 'lib/phut/vhost_daemon.rb', line 58 def running? FileTest.exists?(pid_file) end |
#send_packets(dest, npackets) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/phut/vhost_daemon.rb', line 70 def send_packets(dest, npackets) return unless lookup_arp_table(dest.ip_address) udp = create_udp_packet(dest) npackets.times do write_to_raw_socket udp @logger.info "Sent to #{dest.name}: #{udp}" end end |
#stats ⇒ Object
79 80 81 |
# File 'lib/phut/vhost_daemon.rb', line 79 def stats { tx: @packets_sent, rx: @packets_received } end |
#stop ⇒ Object
62 63 64 |
# File 'lib/phut/vhost_daemon.rb', line 62 def stop @stop = true end |