Skip to content

Commit

Permalink
use ruby builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Dec 10, 2018
1 parent ee59cc3 commit 956a318
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/modules/DNS.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def GetHostnameFromGetent(line)
# @param [String] ip given IP address
# @return resolved canonical hostname (FQDN) for given IP or empty string in case of failure.
def ResolveIP(ip)
command = Builtins.sformat("/usr/bin/getent hosts %1", ip.shellescape)
getent = SCR.Execute(path(".target.bash_output"), command)
command = Builtins.sformat()
getent = SCR.Execute(path(".target.bash_output"), "/usr/bin/getent hosts #{ip.shellescape}")
exit_code = Ops.get_integer(getent, "exit", -1)

if exit_code != 0
Expand Down
89 changes: 27 additions & 62 deletions src/modules/LanItems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2665,72 +2665,43 @@ def export_udevs(devices)
)
end
Builtins.foreach(devs) do |device|
driver = SCR.Execute(
path(".target.bash_output"),
Builtins.sformat(
"driver=$(/usr/bin/ls -l /sys/class/net/%1/device/driver); /usr/bin/echo ${driver##*/} | /usr/bin/tr -d '\n'",
device.shellescape
)
)
begin
driver = File.readlink("/sys/class/net/#{device}/device/driver") rescue nil
rescue Errno => e
Builtins.y2error("Failed to read driver #{e.inspect}")
next
end
driver = File.basename(driver)
device_type = ""
chanids = ""
portname = ""
protocol = ""
if Ops.get_integer(driver, "exit", -1) == 0
case Ops.get_string(driver, "stdout", "")
when "qeth"
device_type = Ops.get_string(driver, "stdout", "")
when "ctcm"
device_type = "ctc"
when "netiucv"
device_type = "iucv"
else
Builtins.y2error(
"unknown driver type :%1",
Ops.get_string(driver, "stdout", "")
)
end
case driver
when "qeth"
device_type = Ops.get_string(driver, "stdout", "")
when "ctcm"
device_type = "ctc"
when "netiucv"
device_type = "iucv"
else
Builtins.y2error("%1", driver)
next
end
chan_ids = Convert.convert(
SCR.Execute(
path(".target.bash_output"),
Builtins.sformat(
"for i in $(seq 0 2); do chanid=$(/usr/bin/ls -l /sys/class/net/%1/device/cdev$i); /usr/bin/echo ${chanid##*/}; done | /usr/bin/tr '\n' ' '",
device.shellescape
)
),
from: "any",
to: "map <string, any>"
)
if Ops.greater_than(
Builtins.size(Ops.get_string(chan_ids, "stdout", "")),
0
)
chanids = String.CutBlanks(Ops.get_string(chan_ids, "stdout", ""))
end
port_name = SCR.Execute(
path(".target.bash_output"),
Builtins.sformat(
"/usr/bin/cat /sys/class/net/%1/device/portname | /usr/bin/tr -d '\n'",
device.shellescape
Builtins.y2error(
"unknown driver type :%1",
Ops.get_string(driver, "stdout", "")
)
)
if !port_name["stdout"].empty?
portname = String.CutBlanks(Ops.get_string(port_name, "stdout", ""))
end
proto = SCR.Execute(
chan_ids = SCR.Execute(
path(".target.bash_output"),
Builtins.sformat(
"/usr/bin/cat /sys/class/net/%1/device/protocol | /usr/bin/tr -d '\n'",
"for i in $(seq 0 2); do chanid=$(/usr/bin/ls -l /sys/class/net/%1/device/cdev$i); /usr/bin/echo ${chanid##*/}; done | /usr/bin/tr '\n' ' '",
device.shellescape
)
)
if !proto["stdout"].empty?
protocol = String.CutBlanks(Ops.get_string(proto, "stdout", ""))
if !chan_ids["stdout"].empty?
chanids = String.CutBlanks(Ops.get_string(chan_ids, "stdout", ""))
end
# we already know that kernel device exist, otherwise next above would apply
portname = ::File.read("/sys/class/net/#{device}/device/portname").strip
portname = ::File.read("/sys/class/net/#{device}/device/protocol").strip
layer2_ret = SCR.Execute(
path(".target.bash"),
Builtins.sformat(
Expand All @@ -2740,15 +2711,9 @@ def export_udevs(devices)
)
layer2 = layer2_ret == 0
Ops.set(ay, ["s390-devices", device], "type" => device_type)
if Ops.greater_than(Builtins.size(chanids), 0)
Ops.set(ay, ["s390-devices", device, "chanids"], chanids)
end
if Ops.greater_than(Builtins.size(portname), 0)
Ops.set(ay, ["s390-devices", device, "portname"], portname)
end
if Ops.greater_than(Builtins.size(protocol), 0)
Ops.set(ay, ["s390-devices", device, "protocol"], protocol)
end
Ops.set(ay, ["s390-devices", device, "chanids"], chanids) if !chanids.empty?
Ops.set(ay, ["s390-devices", device, "portname"], portname) if !portname.empty?
Ops.set(ay, ["s390-devices", device, "protocol"], protocol) if !protocol.empty?
Ops.set(ay, ["s390-devices", device, "layer2"], true) if layer2
port0 = SCR.Execute(
path(".target.bash_output"),
Expand Down

0 comments on commit 956a318

Please sign in to comment.