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(&block) ⇒ Configuration



7
8
9
10
11
12
13
# File 'lib/phut/configuration.rb', line 7

def initialize(&block)
  OpenVswitch.all.clear
  Vhost.all.clear
  Netns.all.clear
  VirtualLink.all.clear
  block.call self
end

Instance Method Details

#fetch(key) ⇒ Object

rubocop:disable MethodLength



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/phut/configuration.rb', line 16

def fetch(key)
  case key
  when String
    [OpenVswitch, Vhost, Netns].each do |each|
      found = each.find_by(name: key)
      return found if found
    end
    fail "Invalid key: #{key.inspect}"
  when Array
    VirtualLink.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



42
43
44
45
46
# File 'lib/phut/configuration.rb', line 42

def run
  [VirtualLink, Vhost, Netns, OpenVswitch].each do |klass|
    klass.each(&:run)
  end
end

#stopObject



48
49
50
51
52
# File 'lib/phut/configuration.rb', line 48

def stop
  [OpenVswitch, Vhost, Netns, VirtualLink].each do |klass|
    klass.each(&:stop)
  end
end

#update_connectionsObject

rubocop:enable MethodLength



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

def update_connections
  update_vswitch_ports
  update_vhost_interfaces
  update_netns_interfaces
  self
end