Class: Y2Network::InterfaceType

Inherits:
Object
  • Object
show all
Extended by:
Yast::I18n
Includes:
Yast::I18n
Defined in:
src/lib/y2network/interface_type.rb

Overview

This class represents the interface types which are supported. Class have helpers to check if given type is what needed. It check name and also short name:

Examples:

check for ethernet cards

type.ethernet?

check for wifi

type.wlan?

Constant Summary collapse

ETHERNET =

Ethernet card, integrated or attached

new(N_("Ethernet"), "eth")
WIRELESS =

Wireless card, integrated or attached

new(N_("Wireless"), "wlan")
INFINIBAND =

Infiniband card

new(N_("Infiniband"), "ib")
INFINIBAND_CHILD =

Infiniband card child device. Used in IPoIB (IP-over-InfiniBand)

new(N_("Infiniband Child"), "ibchild")
BONDING =

Bonding device

new(N_("Bonding"), "bond")
BRIDGE =

bridge device

new(N_("Bridge"), "br")
DUMMY =

virtual dummy device provided by dummy kernel module

new(N_("Dummy"), "dummy")
VLAN =

Virtual LAN

new(N_("VLAN"), "vlan")
TUN =

TUN virtual device provided by kernel, operates on layer3 carrying IP packagets

new(N_("TUN"), "tun")
TAP =

TAP virtual device provided by kernel, operates on layer2 carrying Ethernet frames

new(N_("TAP"), "tap")
USB =

ethernet over usb device provided by usbnet kernel module. Do not confuse with ethernet card attached to USB slot as it is common ETHERNET type.

new(N_("USB"), "usb")
QETH =

device using qeth device driver for s390. Can operate on layer2 or layer3.

new(N_("QETH"), "qeth")
LCS =

LAN-Channel-Station (LCS) network devices. S390 specific.

new(N_("LCS"), "lcs")
HSI =

HiperSockets s390 network device

new(N_("HSI"), "hsi")
CTC =

Channel To Channel. S390 specific

new(N_("CTC"), "ctc")
FICON =

FICON-attached direct access storage devices. s390 specific

new(N_("FICON"), "ficon")
PPP =

Point-to-Point Protocol

new(N_("Point-to-Point Protocol"), "ppp")
IPIP =

Ip in Ip protocol

new(N_("Ip-in-ip"), "ipip")
IPV6TNL =

IPv6 Tunnel interface

new(N_("IPv6 Tunnel"), "ip6tnl")
SIT =

IPv6 over IPv4

new(N_("IPv6 over IPv4 Tunnel"), "sit")
GRE =

IP over IPv4

new(N_("IP over IPv4 Tunnel"), "gre")
IRDA =

Infrared

new(N_("Infrared"), "irda")
LO =

Loopback

new(N_("Loopback"), "lo")
UNKNOWN =

Unknown interfaces

new(N_("Unknown"), "unknown")
SUPPORTED_COMMON =
[ETHERNET, VLAN, BRIDGE, TUN, TAP, BONDING].freeze
SUPPORTED_S390 =
[HSI, CTC, FICON, QETH, LCS].freeze
UNSUPPORTED_S390 =
[DUMMY, WIRELESS, INFINIBAND].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, short_name) ⇒ InterfaceType

Constructor

Parameters:

  • name (String)

    Type name

  • short_name (String)

    short name as is used for prefixing of interface name (e.g. bond, eth or wlan)



71
72
73
74
75
# File 'src/lib/y2network/interface_type.rb', line 71

def initialize(name, short_name)
  textdomain "network"
  @name = name
  @short_name = short_name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object

Raises:

  • (ArgumentError)


105
106
107
108
109
110
111
112
# File 'src/lib/y2network/interface_type.rb', line 105

def method_missing(method_name, *arguments, &block)
  return super unless respond_to_missing?(method_name)

  raise ArgumentError, "no params are accepted for method #{method_name}" if !arguments.empty?

  target_name = method_name.to_s[0..-2]
  [name.downcase, short_name].include?(target_name)
end

Instance Attribute Details

#nameString (readonly)

Returns type name

Returns:

  • (String)

    Returns type name



62
63
64
# File 'src/lib/y2network/interface_type.rb', line 62

def name
  @name
end

#short_nameString (readonly)

Returns type's short name

Returns:

  • (String)

    Returns type's short name



64
65
66
# File 'src/lib/y2network/interface_type.rb', line 64

def short_name
  @short_name
end

Class Method Details

.allArray<InterfaceType>

Returns all the existing types

Returns:



39
40
41
42
43
# File 'src/lib/y2network/interface_type.rb', line 39

def all
  @all ||= InterfaceType.constants
    .map { |c| InterfaceType.const_get(c) }
    .select { |c| c.is_a?(InterfaceType) }
end

.from_short_name(short_name) ⇒ InterfaceType?

Returns the interface type with a given short name

Parameters:

  • short_name (String)

    Short name

Returns:



56
57
58
# File 'src/lib/y2network/interface_type.rb', line 56

def from_short_name(short_name)
  all.find { |t| t.short_name == short_name }
end

.supportedArray<InterfaceType>

Returns all the supported interfaces for the current architecture

Returns:



48
49
50
# File 'src/lib/y2network/interface_type.rb', line 48

def supported
  SUPPORTED_COMMON + (Yast::Arch.s390 ? SUPPORTED_S390 : UNSUPPORTED_S390)
end

Instance Method Details

#class_nameString

Returns name for specialized class for this type e.g. for reader, write or builder

Returns:

  • (String)


86
87
88
# File 'src/lib/y2network/interface_type.rb', line 86

def class_name
  name.capitalize
end

#file_nameString

Returns name for file without suffix for this type e.g. for reader, write or builder

Returns:

  • (String)


92
93
94
# File 'src/lib/y2network/interface_type.rb', line 92

def file_name
  name.downcase
end

#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
99
100
101
102
103
# File 'src/lib/y2network/interface_type.rb', line 96

def respond_to_missing?(method_name, _include_private = false)
  return false unless method_name.to_s.end_with?("?")

  target_name = method_name.to_s[0..-2]
  InterfaceType.all.any? do |type|
    [type.name.downcase, type.short_name].include?(target_name)
  end
end

#to_human_stringString

Returns the translated name

Returns:

  • (String)


80
81
82
# File 'src/lib/y2network/interface_type.rb', line 80

def to_human_string
  _(name)
end