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)


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

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



83
84
85
# File 'lib/osctld/commands/container/recover_cleanup.rb', line 83

def index
  @index
end

Instance Method Details

#key(route) ⇒ Object (protected)



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

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:



78
79
80
# File 'lib/osctld/commands/container/recover_cleanup.rb', line 78

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