Class: Phut::Configuration
- Inherits:
-
Object
- Object
- Phut::Configuration
- Defined in:
- lib/phut/configuration.rb
Overview
Parsed DSL data.
Instance Attribute Summary collapse
-
#links ⇒ Object
readonly
Returns the value of attribute links.
Instance Method Summary collapse
- #add_link(name_a, name_b) ⇒ Object
- #add_vhost(name, attrs) ⇒ Object
- #add_vswitch(name, attrs) ⇒ Object
-
#fetch(key) ⇒ Object
rubocop:disable MethodLength.
-
#find_network_device_by_name(name) ⇒ Object
rubocop:enable MethodLength.
-
#initialize(logger = NullLogger.new) ⇒ Configuration
constructor
A new instance of Configuration.
- #run ⇒ Object
- #stop ⇒ Object
- #vhosts ⇒ Object
- #vswitches ⇒ Object
Constructor Details
#initialize(logger = NullLogger.new) ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 |
# File 'lib/phut/configuration.rb', line 9 def initialize(logger = NullLogger.new) @all = {} @links = [] @logger = logger end |
Instance Attribute Details
#links ⇒ Object (readonly)
Returns the value of attribute links.
7 8 9 |
# File 'lib/phut/configuration.rb', line 7 def links @links end |
Instance Method Details
#add_link(name_a, name_b) ⇒ Object
71 72 73 |
# File 'lib/phut/configuration.rb', line 71 def add_link(name_a, name_b) @links << VirtualLink.new(name_a, name_b, @logger) end |
#add_vhost(name, attrs) ⇒ Object
65 66 67 68 69 |
# File 'lib/phut/configuration.rb', line 65 def add_vhost(name, attrs) check_name_conflict name @all[name] = Vhost.new(attrs[:ip], attrs[:mac], attrs[:promisc], name, @logger) end |
#add_vswitch(name, attrs) ⇒ Object
59 60 61 62 63 |
# File 'lib/phut/configuration.rb', line 59 def add_vswitch(name, attrs) check_name_conflict name @all[name] = OpenVswitch.new(attrs[:dpid], attrs[:port_number], name, @logger) end |
#fetch(key) ⇒ Object
rubocop:disable MethodLength
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/phut/configuration.rb', line 16 def fetch(key) case key when String @all.fetch(key) when Array @links.each do |each| return each if [each.name_a, each.name_b].sort == key.sort end fail "link #{key.join ' '} not found." else fail "Invalid key: #{key.inspect}" end end |
#find_network_device_by_name(name) ⇒ Object
rubocop:enable MethodLength
31 32 33 34 35 36 37 |
# File 'lib/phut/configuration.rb', line 31 def find_network_device_by_name(name) @links.each do |each| device = each.find_network_device_by_name(name) return device if device end fail "No network device found for #{name}." end |
#run ⇒ Object
47 48 49 50 51 |
# File 'lib/phut/configuration.rb', line 47 def run links.each(&:run) vhosts.each { |each| each.run vhosts } vswitches.each(&:run) end |
#stop ⇒ Object
53 54 55 56 57 |
# File 'lib/phut/configuration.rb', line 53 def stop vswitches.each(&:maybe_stop) vhosts.each(&:maybe_stop) links.each(&:maybe_stop) end |
#vhosts ⇒ Object
43 44 45 |
# File 'lib/phut/configuration.rb', line 43 def vhosts @all.values.select { |each| each.is_a? Vhost } end |
#vswitches ⇒ Object
39 40 41 |
# File 'lib/phut/configuration.rb', line 39 def vswitches @all.values.select { |each| each.is_a? OpenVswitch } end |