Class: Distem::Node::IFBAllocator

Inherits:
Object
  • Object
show all
Defined in:
lib/distem/node/ifballocator.rb

Overview

Class that manages the allocation of IFB devices on a pnode

Instance Method Summary (collapse)

Constructor Details

- (IFBAllocator) initialize

Initialize the allocator. Will automatically guess the number of ifb devices.



10
11
12
13
# File 'lib/distem/node/ifballocator.rb', line 10

def initialize
  @allocmutex = Mutex::new
  @ifbs = Lib::Shell.run('ip link list').scan(/: (ifb\d+):/).map { |e| e[0] }
end

Instance Method Details

- (Object) free_ifb(ifb)

Free an IFB device



28
29
30
31
32
# File 'lib/distem/node/ifballocator.rb', line 28

def free_ifb(ifb)
  @allocmutex.lock
    @ifbs.push(ifb)
  @allocmutex.unlock
end

- (Object) get_ifb

Get an IFB device name (e.g. “ifb42”)



16
17
18
19
20
21
22
23
24
25
# File 'lib/distem/node/ifballocator.rb', line 16

def get_ifb
  @allocmutex.lock
      raise "No more IFB devices" if @ifbs.empty?  # should never happen since there's
         # a safeguard at vnode creation time
    ifb = @ifbs.shift
  @allocmutex.unlock
  # make sure the IFB device is up
  Lib::Shell.run("ip link set dev #{ifb} up")
  return ifb
end