-
Notifications
You must be signed in to change notification settings - Fork 34
/
vlan.rb
47 lines (40 loc) · 1.38 KB
/
vlan.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require "yast"
require "y2network/interface_config_builder"
Yast.import "LanItems"
Yast.import "NetworkInterfaces"
module Y2Network
module InterfaceConfigBuilders
class Vlan < InterfaceConfigBuilder
def initialize
super(type: InterfaceType::VLAN)
end
def etherdevice
@config["ETHERDEVICE"]
end
def etherdevice=(value)
@config["ETHERDEVICE"] = value
end
# @return [Hash<String, String>] returns ordered list of devices that can be used for vlan
# Keys are ids for #etherdevice and value are label
def possible_vlans
res = {}
# unconfigured devices
Yast::LanItems.Items.each_value do |lan_item|
next unless (lan_item["ifcfg"] || "").empty?
dev_name = lan_item.fetch("hwinfo", {}).fetch("dev_name", "")
res[dev_name] = dev_name
end
# configured devices
configurations = Yast::NetworkInterfaces.FilterDevices("netcard")
# TODO: API looks horrible
Yast::NetworkInterfaces.CardRegex["netcard"].split("|").each do |devtype|
(configurations[devtype] || {}).each_key do |devname|
next if Yast::NetworkInterfaces.GetType(devname) == type
res[devname] = "#{devname} - #{Yast::Ops.get_string(configurations, [devtype, devname, "NAME"], "")}"
end
end
res
end
end
end
end