Class: Phut::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/phut/configuration.rb

Overview

Parsed DSL data.

Instance Method Summary collapse

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



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

#runObject



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

#stopObject



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_connectionsObject

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

#vhostsObject



39
40
41
# File 'lib/phut/configuration.rb', line 39

def vhosts
  @all.values.select { |each| each.is_a? Vhost }
end

#vswitchesObject



35
36
37
# File 'lib/phut/configuration.rb', line 35

def vswitches
  @all.values.select { |each| each.is_a? OpenVswitch }
end