Sha256: bfe61653788350190d7b1fd7f3308798f173a9afd1dcd5c42722a303053f9e35
Contents?: true
Size: 1.42 KB
Versions: 2
Compression:
Stored size: 1.42 KB
Contents
require 'forwardable' require 'phut/null_logger' require 'phut/open_vswitch' module Phut # Parsed DSL data. class Configuration extend Forwardable def_delegators :@all, :fetch, :[] def initialize(logger = NullLogger.new) @all = {} @logger = logger end def vswitches @all.values.select { |each| each.is_a? OpenVswitch } end def vhosts @all.values.select { |each| each.is_a? Vhost } end def links @all.values.select { |each| each.is_a? VirtualLink } end def run links.each(&:run) vswitches.each(&:run) vhosts.each { |each| each.run vhosts } end def stop vswitches.each(&:maybe_stop) vhosts.each(&:maybe_stop) links.each(&:maybe_stop) end def add_vswitch(name, attrs) check_name_conflict name @all[name] = OpenVswitch.new(attrs[:dpid], name, @logger) end def add_vhost(name, attrs) check_name_conflict name @all[name] = Vhost.new(attrs[:ip], attrs[:mac], attrs[:promisc], name, @logger) end # This method smells of :reek:LongParameterList def add_link(name_a, device_a, name_b, device_b) @all[[name_a, name_b]] = VirtualLink.new(name_a, device_a, name_b, device_b, @logger) end private def check_name_conflict(name) conflict = @all[name] fail "The name #{name} conflicts with #{conflict}." if conflict end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
phut-0.2.4 | lib/phut/configuration.rb |
phut-0.2.3 | lib/phut/configuration.rb |