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)


69
70
71
72
73
74
75
76
77
# File 'lib/osctld/commands/container/recover_cleanup.rb', line 69

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



85
86
87
# File 'lib/osctld/commands/container/recover_cleanup.rb', line 85

def index
  @index
end

Instance Method Details

#key(route) ⇒ Object (protected)



87
88
89
90
91
92
93
94
95
# File 'lib/osctld/commands/container/recover_cleanup.rb', line 87

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_string
  else
    fail 'programming error'
  end
end

#veth_of(route) ⇒ Object

Parameters:



80
81
82
# File 'lib/osctld/commands/container/recover_cleanup.rb', line 80

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