Class: Yast::NetHwDetectionClass

Inherits:
Module
  • Object
show all
Defined in:
src/modules/NetHwDetection.rb

Instance Method Summary collapse

Instance Method Details

#DuplicateIP(ip) ⇒ Object

Duplicate IP detection

Parameters:

  • ip (String)

    tested IP address

Returns:

  • true if duplicate found

See Also:

  • ip(8)


152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'src/modules/NetHwDetection.rb', line 152

def DuplicateIP(ip)
  # missing param for arping. Arping does nothing in such case only
  # floods logs.
  return false if ip.nil? || ip.empty?

  command = "LC_ALL=C /usr/sbin/ip link show | /usr/bin/grep BROADCAST | " \
            "/usr/bin/grep -v NOARP | /usr/bin/cut -d: -f2"
  exe = SCR.Execute(path(".target.bash_output"), command)
  ifs = Ops.get_string(exe, "stdout", "")
  ifsl = Builtins.filter(Builtins.splitstring(ifs, " \t\n")) { |i| i != "" }

  # #45169: must only probe the interface being set up
  # but I don't know which one it is :-(
  # so pretend there are no dups if we have more interfaces
  return false if Ops.greater_than(Builtins.size(ifsl), 1)

  # find the interface that detects the dup
  ifc = Builtins.find(ifsl) do |ifname|
    # no need to be quiet, diagnostics is good
    command = "/usr/sbin/arping  -D -c2 -w3 -I#{ifname.shellescape} #{ip.shellescape}"
    # 0 no dup, 1 dup, 2 other error (eg. ifc not up, #182473)
    SCR.Execute(path(".target.bash"), command) == 1
  end

  !ifc.nil?
end

#LoadNetModulesObject

Set up the first eth interface, if not already running WATCH OUT, this is the place where modules are loaded

Returns:

  • true if success



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'src/modules/NetHwDetection.rb', line 88

def LoadNetModules
  log.info "Network detection prepare"

  hardware = ReadHardware("netcard")

  log.debug("Hardware=#{hardware.inspect}")
  return false if hardware.empty?

  @detection_modules = needed_modules(hardware).dup
  @detection_modules.each { |name| load_module(name) }

  log.info("Network detection prepare (end)")

  true
end

#mainObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'src/modules/NetHwDetection.rb', line 63

def main
  Yast.import "UI"
  textdomain "network"

  Yast.import "Directory"
  Yast.import "Package"
  Yast.import "String"

  Yast.include self, "network/routines.rb"

  # Detection result
  # (in dhcpcd-<i>interface</i>.info format)
  @result = {}

  # True, if detection is running
  @running = false

  @tmpdir = Directory.tmpdir

  @detection_modules = []
end

#ResolveIP(ip) ⇒ Object

this function is moved here just to kee it out of the tangle of includes which will be torn apart in the next release. dependency hell. Resolve IP to hostname

Parameters:

  • ip (String)

    given IP address

Returns:

  • resolved host



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'src/modules/NetHwDetection.rb', line 185

def ResolveIP(ip)
  # quick check to avoid timeout
  if Builtins.size(ip) == 0 ||
      Convert.to_integer(
        SCR.Execute(
          path(".target.bash"),
          Builtins.sformat("/usr/bin/grep -q %1 /etc/hosts", ip.shellescape)
        )
      ) != 0
    return ""
  end

  command = "/usr/bin/getent hosts #{ip.shellescape} | /usr/bin/sed \"s/^[0-9.: \t]\\+//g\""
  getent = SCR.Execute(path(".target.bash_output"), command)
  hnent = Ops.get_string(getent, "stdout", "")
  Builtins.y2debug("%1", hnent)
  hnent = String.FirstChunk(hnent, " \t\n")
  hnent = "" if hnent.nil?
  Builtins.y2debug("'%1'", hnent)
  String.CutBlanks(hnent)
end

#StartObject

Start the detection

Returns:

  • true on success



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'src/modules/NetHwDetection.rb', line 106

def Start
  if @running == true
    Builtins.y2error("Detection already running")
    return false
  end

  Builtins.y2milestone(
    "IFCONFIG1: %1",
    SCR.Execute(path(".target.bash_output"), "/usr/sbin/ip addr show")
  )
  ret = false
  if LoadNetModules()
    @running = true
    ret = true
  end

  Builtins.y2milestone(
    "IFCONFIG2: %1",
    SCR.Execute(path(".target.bash_output"), "/usr/sbin/ip addr show")
  )
  Builtins.y2milestone("Detection start result: %1", ret)
  ret
end

#StopObject

Stop the detection

Returns:

  • true on success



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'src/modules/NetHwDetection.rb', line 132

def Stop
  if @running != true
    Builtins.y2error("Detection not running")
    return false
  end
  @running = false

  Builtins.y2milestone(
    "IFCONFIG3: %1",
    SCR.Execute(path(".target.bash_output"), "/usr/sbin/ip addr show")
  )

  Builtins.y2milestone("Detection stop ")
  true
end