Class: Phut::Configuration
- Inherits:
-
Object
- Object
- Phut::Configuration
- Defined in:
- lib/phut/configuration.rb
Overview
Parsed DSL data.
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.
-
#initialize(logger = NullLogger.new) ⇒ Configuration
constructor
A new instance of Configuration.
- #run ⇒ Object
- #stop ⇒ Object
-
#update_connections ⇒ Object
rubocop:enable MethodLength.
- #vhosts ⇒ Object
- #vswitches ⇒ Object
Constructor Details
#initialize(logger = NullLogger.new) ⇒ Configuration
Returns a new instance of Configuration.
7 8 9 10 11 |
# File 'lib/phut/configuration.rb', line 7 def initialize(logger = NullLogger.new) @all = {} @links = [] @logger = logger end |
Instance Method Details
#add_link(name_a, name_b) ⇒ Object
67 68 69 |
# File 'lib/phut/configuration.rb', line 67 def add_link(name_a, name_b) @links << VirtualLink.new(name_a, name_b, @logger) end |
#add_vhost(name, attrs) ⇒ Object
61 62 63 64 65 |
# File 'lib/phut/configuration.rb', line 61 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
55 56 57 58 59 |
# File 'lib/phut/configuration.rb', line 55 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
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/phut/configuration.rb', line 14 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 |
#run ⇒ Object
43 44 45 46 47 |
# File 'lib/phut/configuration.rb', line 43 def run @links.each(&:run) vhosts.each { |each| each.run vhosts } vswitches.each(&:run) end |
#stop ⇒ Object
49 50 51 52 53 |
# File 'lib/phut/configuration.rb', line 49 def stop vswitches.each(&:maybe_stop) vhosts.each(&:maybe_stop) @links.each(&:maybe_stop) end |
#update_connections ⇒ Object
rubocop:enable MethodLength
29 30 31 32 33 |
# File 'lib/phut/configuration.rb', line 29 def update_connections update_vswitch_ports update_vhost_interfaces self end |
#vhosts ⇒ Object
39 40 41 |
# File 'lib/phut/configuration.rb', line 39 def vhosts @all.values.select { |each| each.is_a? Vhost } end |
#vswitches ⇒ Object
35 36 37 |
# File 'lib/phut/configuration.rb', line 35 def vswitches @all.values.select { |each| each.is_a? OpenVswitch } end |