Class: Y2Network::Serializer::RouteSysconfig

Inherits:
Object
  • Object
show all
Defined in:
src/lib/y2network/serializer/route_sysconfig.rb

Overview

This class is responsible of serializing Routes from a hash and to a hash representation based on sysconfig routing configuration.

Constant Summary collapse

DEFAULT_DEST =
"default".freeze
MISSING_VALUE =
"-".freeze

Instance Method Summary collapse

Instance Method Details

#from_hash(hash) ⇒ Y2Network::Route

Build a route given a hash based on sysconfig route files syntax

Parameters:

  • hash (Hash)

    based on sysconfig route files syntax

Returns:



53
54
55
56
57
58
59
60
# File 'src/lib/y2network/serializer/route_sysconfig.rb', line 53

def from_hash(hash)
  Y2Network::Route.new(
    to:        destination_from(hash),
    interface: interface_from(hash),
    gateway:   build_ip(hash["gateway"]),
    options:   hash["extrapara"] || ""
  )
end

#to_hash(route) ⇒ Hash

Returns a hash representation of the Route object based on sysconfig route files syntax

Parameters:

Returns:

  • (Hash)

    based on sysconfig route files syntax



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'src/lib/y2network/serializer/route_sysconfig.rb', line 34

def to_hash(route)
  hash = if route.default?
    { "destination" => "default", "netmask" => "-" }
  else
    dest = route.to
    # netmask column of routes file has been marked as deprecated -> using prefix
    { "destination" => "#{dest}/#{dest.prefix}", "netmask" => "-" }
  end

  hash["extrapara"] = route.options unless route.options.to_s.empty?
  hash["gateway"] = route.gateway ? route.gateway.to_s : "-"
  hash["device"] = route.interface.nil? ? "-" : route.interface.name
  hash
end