Class: Phut::Syntax::VswitchDirective

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

Overview

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

Instance Method Summary collapse

Methods inherited from Directive

#[], attribute

Constructor Details

#initialize(alias_name, &block) ⇒ VswitchDirective



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

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

Instance Method Details

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



14
15
16
17
18
19
20
21
22
# File 'lib/phut/syntax/vswitch_directive.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