Class: OsCtld::Container::Recovery::RouteList

Inherits:
Object
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
Defined in:
lib/osctld/container/recovery.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip_v) ⇒ RouteList

Returns a new instance of RouteList.

Parameters:

  • ip_v (Integer)


164
165
166
167
168
169
170
171
172
# File 'lib/osctld/container/recovery.rb', line 164

def initialize(ip_v)
  @index = {}

  JSON.parse(syscmd("ip -#{ip_v} -json route list").output).each do |route|
    next unless route['dev'].start_with?('veth')

    index[route['dst']] = route['dev']
  end
end

Instance Attribute Details

#indexObject (readonly, protected)

Returns the value of attribute index.



181
182
183
# File 'lib/osctld/container/recovery.rb', line 181

def index
  @index
end

Instance Method Details

#key(route) ⇒ Object (protected)



183
184
185
186
187
188
189
190
# File 'lib/osctld/container/recovery.rb', line 183

def key(route)
  if (route.addr.ipv4? && route.addr.prefix == 32) \
      || (route.addr.ipv6? && route.addr.prefix == 128)
    route.addr.to_s
  else
    route.addr.to_string
  end
end

#veth_of(route) ⇒ Object

Parameters:



175
176
177
# File 'lib/osctld/container/recovery.rb', line 175

def veth_of(route)
  index[key(route)]
end