Skip to content

Commit

Permalink
network module: add support for getting dracut arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
rvykydal committed Jan 23, 2019
1 parent f935a12 commit f85682f
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 1 deletion.
102 changes: 102 additions & 0 deletions pyanaconda/modules/network/ifcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,105 @@ def update_slaves_onboot_value(master_devname, onboot, root_path="", uuid=None):
updated_devices.append(slave)

return updated_devices


def get_dracut_arguments_from_ifcfg(iface, target_ip, hostname):
"""Get dracut arguments for the iface and iSCSI target.
The dracut arguments would activate the iface in initramfs so that the
iSCSI target can be attached (for example to mount root filesystem).
:param iface: network interface used to connect to the target
:type iface: str
:param target_ip: IP of the iSCSI target
:type target_ip: str
:param hostname: static hostname to be configured
:type hostname: str
"""
netargs = []
ifcfg = get_ifcfg_file_of_device(iface)
if not ifcfg:
log.error("get dracut arguments from ifcfg for %s: no ifcfg file found", iface)
return netargs

if ifcfg.get('BOOTPROTO') == 'ibft':
netargs.add("rd.iscsi.ibft")
elif target_ip:
if hostname is None:
hostname = ""
# if using ipv6
if ':' in target_ip:
if ifcfg.get('DHCPV6C') == "yes":
# XXX combination with autoconf not yet clear,
# support for dhcpv6 is not yet implemented in NM/ifcfg-rh
netargs.add("ip=%s:dhcp6" % iface)
elif ifcfg.get('IPV6_AUTOCONF') == "yes":
netargs.add("ip=%s:auto6" % iface)
elif ifcfg.get('IPV6ADDR'):
ipaddr = "[%s]" % ifcfg.get('IPV6ADDR')
if ifcfg.get('IPV6_DEFAULTGW'):
gateway = "[%s]" % ifcfg.get('IPV6_DEFAULTGW')
else:
gateway = ""
netargs.add("ip=%s::%s::%s:%s:none" % (ipaddr, gateway,
hostname, iface))
else:
if util.lowerASCII(ifcfg.get('bootproto')) == 'dhcp':
netargs.add("ip=%s:dhcp" % iface)
else:
cfgidx = ''
if ifcfg.get('IPADDR0'):
cfgidx = '0'
if ifcfg.get('GATEWAY%s' % cfgidx):
gateway = ifcfg.get('GATEWAY%s' % cfgidx)
else:
gateway = ""
netmask = ifcfg.get('NETMASK%s' % cfgidx)
prefix = ifcfg.get('PREFIX%s' % cfgidx)
if not netmask and prefix:
netmask = prefix2netmask(int(prefix))
ipaddr = ifcfg.get('IPADDR%s' % cfgidx)
netargs.add("ip=%s::%s:%s:%s:%s:none" %
(ipaddr, gateway, netmask, hostname, iface))

hwaddr = ifcfg.get("HWADDR")
if hwaddr:
netargs.add("ifname=%s:%s" % (iface, hwaddr.lower()))

if ifcfg.get("TYPE") == "Team" or ifcfg.get("DEVICETYPE") == "Team":
slaves = get_slaves_from_ifcfgs("TEAM_MASTER", [iface, ifcfg.get("UUID")])
netargs.add("team=%s:%s" % (iface,
",".join(s_iface for s_iface, _uuid in slaves)))

if ifcfg.get("TYPE") == "Vlan":
physdev_spec = ifcfg.get("PHYSDEV")
physdev = None
# physical device can be specified by connection uuid (eg from nm-c-e)
if len(physdev_spec) == 36:
ifcfg = get_ifcfg_file([("UUID", physdev_spec)])
if ifcfg:
# On s390 with net.ifnames=0 there is no DEVICE
physdev = ifcfg.get("DEVICE") or ifcfg.get("NAME")
else:
ifcfg = get_ifcfg_file_of_device(physdev_spec)
if ifcfg:
physdev = physdev_spec
if physdev:
netargs.add("vlan=%s:%s" % (iface, physdev))
else:
log.error("can't find ifcfg of parent of vlan device %s specified by %s",
iface, physdev_spec)
return netargs

# For vlan ifcfg now refers to the physical device file
nettype = ifcfg.get("NETTYPE")
subchannels = ifcfg.get("SUBCHANNELS")
if is_s390() and nettype and subchannels:
znet = "rd.znet=%s,%s" % (nettype, subchannels)
options = ifcfg.get("OPTIONS").strip("'\"")
if options:
options = filter(lambda x: x != '', options.split(' '))
znet += ",%s" % (','.join(options))
netargs.add(znet)

return netargs
20 changes: 19 additions & 1 deletion pyanaconda/modules/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
add_connection_from_ksdata, update_connection_from_ksdata, ensure_active_connection_for_device, \
update_iface_setting_values, bound_hwaddr_of_device, devices_ignore_ipv6
from pyanaconda.modules.network.ifcfg import get_ifcfg_file_of_device, update_onboot_value, \
update_slaves_onboot_value, find_ifcfg_uuid_of_device
update_slaves_onboot_value, find_ifcfg_uuid_of_device, get_dracut_arguments_from_ifcfg
from pyanaconda.modules.network.installation import NetworkInstallationTask
from pyanaconda.modules.network.utils import get_default_route_iface

Expand Down Expand Up @@ -617,3 +617,21 @@ def network_device_configuration_changed(self):
if not self._device_configurations:
log.error("Got request to use DeviceConfigurations that has not been created yet")
self._use_device_configurations = True

def get_dracut_arguments(self, iface, target_ip, hostname):
"""Get dracut arguments for the iface and iSCSI target.
The dracut arguments would activate the iface in initramfs so that the
iSCSI target can be attached (for example to mount root filesystem).
:param iface: network interface used to connect to the target
:param target_ip: IP of the iSCSI target
:param hostname: static hostname to be configured
"""
dracut_args = []

if iface not in (device.get_iface() for device in self.nm_client.get_devices()):
log.error("get dracut argumetns for %s: device not found", iface)
return dracut_args

return get_dracut_arguments_from_ifcfg(iface, target_ip, hostname)
12 changes: 12 additions & 0 deletions pyanaconda/modules/network/network_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,15 @@ def NetworkDeviceConfigurationChanged(self):
from persistent configuration instead of using original kickstart data.
"""
return self.implementation.network_device_configuration_changed()

def GetDracutArguments(self, iface: Str, target_ip: Str, hostname: Str) -> List[Str]:
"""Get dracut arguments for the iface and iSCSI target.
The dracut arguments would activate the iface in initramfs so that the
iSCSI target can be attached (for example to mount root filesystem).
:param iface: network interface used to connect to the target
:param target_ip: IP of the iSCSI target
:param hostname: static hostname to be configured
"""
return self.implementation.get_dracut_arguments(iface, target_ip, hostname)

0 comments on commit f85682f

Please sign in to comment.