Class: Wire::Resource::OVSBridge

Inherits:
ResourceBase show all
Defined in:
lib/wire/resource/bridge.rb

Overview

Open vSwitch Bridge resource

Instance Attribute Summary collapse

Attributes inherited from ResourceBase

#name

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ OVSBridge

initialize the bridge object with given name and type params:

  • name bridge name, i.e. “br0”



24
25
26
27
28
29
30
31
# File 'lib/wire/resource/bridge.rb', line 24

def initialize(name)
  super(name)

  # TODO: make configurable
  @executables = {
    :vsctl => '/usr/bin/ovs-vsctl'
  }
end

Instance Attribute Details

#executablesObject

type of bridge (here: ovs) executables [Hash] of binaries needed to control the resource



18
19
20
# File 'lib/wire/resource/bridge.rb', line 18

def executables
  @executables
end

#typeObject

type of bridge (here: ovs) executables [Hash] of binaries needed to control the resource



18
19
20
# File 'lib/wire/resource/bridge.rb', line 18

def type
  @type
end

Instance Method Details

#downObject

deletes the bridge (ovs-vsctl del-br)



64
65
66
67
68
69
70
# File 'lib/wire/resource/bridge.rb', line 64

def down
  LocalExecution.with(@executables[:vsctl],
                      ['del-br', @name]) do |down_exec_obj|
    down_exec_obj.run
    return (down_exec_obj.exitstatus == 0)
  end
end

#down?Boolean

checks if the bridge is down

Returns:

  • (Boolean)


59
60
61
# File 'lib/wire/resource/bridge.rb', line 59

def down?
  !(up?)
end

#exist?Boolean

TODO: move to generic execution method codeclimate.com/github/de-wiring/wire/Wire::Resource::OVSBridge checks if the bridge exists

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# File 'lib/wire/resource/bridge.rb', line 36

def exist?
  LocalExecution.with(@executables[:vsctl],
                      ['br-exists', @name]) do |exec_obj|
    exec_obj.run
    return (exec_obj.exitstatus != 2)
  end
end

#to_sObject

Returns a string representation



73
74
75
# File 'lib/wire/resource/bridge.rb', line 73

def to_s
  "Bridge:[#{name},type=#{type}]"
end

#upObject

adds the bridge (ovs-vsctl add-br)



50
51
52
53
54
55
56
# File 'lib/wire/resource/bridge.rb', line 50

def up
  LocalExecution.with(@executables[:vsctl],
                      ['add-br', @name]) do |up_exec_obj|
    up_exec_obj.run
    return (up_exec_obj.exitstatus == 0)
  end
end

#up?Boolean

checks if the bridge exists

Returns:

  • (Boolean)


45
46
47
# File 'lib/wire/resource/bridge.rb', line 45

def up?
  exist?
end