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.



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

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

Instance Method Details

#[](key) ⇒ Object



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

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

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



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

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



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

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