Class: Phut::Syntax::VswitchDirective

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

Overview

The ‘vswitch(name) { …attributes… }’ directive.

Instance Method Summary collapse

Constructor Details

#initialize(alias_name, &block) ⇒ VswitchDirective

Returns a new instance of VswitchDirective.



9
10
11
12
# File 'lib/phut/syntax.rb', line 9

def initialize(alias_name, &block)
  @attributes = { name: alias_name, port_number: 6653 }
  instance_eval(&block)
end

Instance Method Details

#[](key) ⇒ Object



29
30
31
# File 'lib/phut/syntax.rb', line 29

def [](key)
  @attributes[key]
end

#dpid(value) ⇒ Object Also known as: datapath_id



14
15
16
17
18
19
20
21
22
# File 'lib/phut/syntax.rb', line 14

def dpid(value)
  dpid = if value.is_a?(String) && /^0x/=~ value
           value.hex
         else
           value.to_i
         end
  @attributes[:dpid] = dpid
  @attributes[:name] ||= format('%#x', @attributes[:dpid])
end

#port(port_no) ⇒ Object



25
26
27
# File 'lib/phut/syntax.rb', line 25

def port(port_no)
  @attributes[:port_number] = port_no
end