Class: Phut::Syntax

Inherits:
Object
  • Object
show all
Defined in:
lib/phut/syntax.rb,
lib/phut/syntax/directive.rb,
lib/phut/syntax/netns_directive.rb,
lib/phut/syntax/vhost_directive.rb,
lib/phut/syntax/vswitch_directive.rb

Overview

DSL syntax definitions.

Defined Under Namespace

Classes: Directive, NetnsDirective, VhostDirective, VswitchDirective

Instance Method Summary collapse

Constructor Details

#initialize(netns) ⇒ Syntax

Returns a new instance of Syntax.



13
14
15
# File 'lib/phut/syntax.rb', line 13

def initialize(netns)
  @netns = netns
end

Instance Method Details



45
46
47
# File 'lib/phut/syntax.rb', line 45

def link(name_a, name_b)
  Link.create(name_a, name_b)
end

#netns(name, &block) ⇒ Object



49
50
51
# File 'lib/phut/syntax.rb', line 49

def netns(name, &block)
  @netns << NetnsDirective.new(name, &block)
end

#vhost(name = nil, &block) ⇒ Object

rubocop:enable MethodLength rubocop:enable LineLength



37
38
39
40
41
42
43
# File 'lib/phut/syntax.rb', line 37

def vhost(name = nil, &block)
  attrs = VhostDirective.new(name, &block)
  Vhost.create(name: attrs[:name],
               ip_address: attrs[:ip],
               mac_address: attrs[:mac],
               promisc: attrs[:promisc])
end

#vswitch(alias_name = nil, &block) ⇒ Object

rubocop:disable MethodLength rubocop:disable LineLength



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

def vswitch(alias_name = nil, &block)
  attrs = VswitchDirective.new(alias_name, &block)
  openflow_version = case Pio::OpenFlow.version
                     when :OpenFlow10
                       1.0
                     when :OpenFlow13
                       1.3
                     else
                       raise "Unknown OpenFlow version: #{Pio::OpenFlow.version}"
                     end
  Vswitch.create(dpid: attrs[:dpid],
                 name: attrs[:name],
                 tcp_port: attrs[:port],
                 openflow_version: openflow_version)
end