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)


158
159
160
161
162
163
164
165
166
# File 'lib/osctld/container/recovery.rb', line 158

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.



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

def index
  @index
end

Instance Method Details

#key(route) ⇒ Object (protected)



176
177
178
179
180
181
182
183
184
# File 'lib/osctld/container/recovery.rb', line 176

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

#veth_of(route) ⇒ Object

Parameters:



169
170
171
# File 'lib/osctld/container/recovery.rb', line 169

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