Class: OsCtld::Commands::Container::RecoverCleanup::RouteList

Inherits:
Object
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
Defined in:
lib/osctld/commands/container/recover_cleanup.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)


83
84
85
86
87
88
89
90
91
# File 'lib/osctld/commands/container/recover_cleanup.rb', line 83

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.



99
100
101
# File 'lib/osctld/commands/container/recover_cleanup.rb', line 99

def index
  @index
end

Instance Method Details

#key(route) ⇒ Object (protected)



101
102
103
104
105
106
107
108
109
# File 'lib/osctld/commands/container/recover_cleanup.rb', line 101

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:



94
95
96
# File 'lib/osctld/commands/container/recover_cleanup.rb', line 94

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