Beispiel #1
0
    def setNetworkOnbootDefault(self, ksdata):
        # if something's already enabled, we can just leave the config alone
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                onboot = nm.nm_device_setting_value(devName, "connection",
                                                    "autoconnect")
            except nm.DeviceSettingsNotFoundError:
                continue
            if not onboot == False:
                return

        # the default otherwise: bring up the first wired netdev with link
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                link_up = nm.nm_device_carrier(devName)
            except ValueError:
                continue
            if link_up:
                ifcfg_path = network.find_ifcfg_file_of_device(
                    devName, root_path=ROOT_PATH)
                if not ifcfg_path:
                    continue
                ifcfg = network.IfcfgFile(ifcfg_path)
                ifcfg.read()
                ifcfg.set(('ONBOOT', 'yes'))
                ifcfg.write()
                for nd in ksdata.network.network:
                    if nd.device == devName:
                        nd.onboot = True
                        break
                break
    def setNetworkOnbootDefault(self, ksdata):
        # if something's already enabled, we can just leave the config alone
        for devName in nm.nm_devices():
            if not nm.nm_device_type_is_wifi(devName) and \
               network.get_ifcfg_value(devName, "ONBOOT", ROOT_PATH) == "yes":
                return

        # the default otherwise: bring up the first wired netdev with link
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                link_up = nm.nm_device_carrier(devName)
            except ValueError as e:
                continue
            if link_up:
                dev = network.NetworkDevice(ROOT_PATH + network.netscriptsDir, devName)
                dev.loadIfcfgFile()
                dev.set(('ONBOOT', 'yes'))
                dev.writeIfcfgFile()
                for nd in ksdata.network.network:
                    if nd.device == dev.iface:
                        nd.onboot = True
                        break
                break
Beispiel #3
0
    def setNetworkOnbootDefault(self, ksdata):
        # if something's already enabled, we can just leave the config alone
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                onboot = nm.nm_device_setting_value(devName, "connection", "autoconnect")
            except nm.SettingsNotFoundError:
                continue
            if not onboot == False:
                return

        # the default otherwise: bring up the first wired netdev with link
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                link_up = nm.nm_device_carrier(devName)
            except ValueError:
                continue
            if link_up:
                ifcfg_path = network.find_ifcfg_file_of_device(devName, root_path=ROOT_PATH)
                if not ifcfg_path:
                    continue
                ifcfg = network.IfcfgFile(ifcfg_path)
                ifcfg.read()
                ifcfg.set(('ONBOOT', 'yes'))
                ifcfg.write()
                for nd in ksdata.network.network:
                    if nd.device == devName:
                        nd.onboot = True
                        break
                break
def networkInitialize(ksdata):

    log.debug("network: devices found %s", nm.nm_devices())
    logIfcfgFiles("network initialization")

    if not flags.imageInstall:
        devnames = apply_kickstart_from_pre_section(ksdata)
        if devnames:
            msg = "kickstart pre section applied for devices %s" % devnames
            log.debug("network: %s", msg)
            logIfcfgFiles(msg)
        devnames = dumpMissingDefaultIfcfgs()
        if devnames:
            msg = "missing ifcfgs created for devices %s" % devnames
            log.debug("network: %s", msg)
            logIfcfgFiles(msg)

    # For kickstart network --activate option we set ONBOOT=yes
    # in dracut to get devices activated by NM. The real network --onboot
    # value is set here.
    devnames = setOnboot(ksdata)
    if devnames:
        msg = "setting real kickstart ONBOOT value for devices %s" % devnames
        log.debug("network: %s", msg)
        logIfcfgFiles(msg)

    if ksdata.network.hostname is None:
        hostname = getHostname()
        update_hostname_data(ksdata, hostname)
def dumpMissingDefaultIfcfgs():
    """
    Dump missing default ifcfg file for wired devices.
    For default auto connections created by NM upon start - which happens
    in case of missing ifcfg file - rename the connection using device name
    and dump its ifcfg file. (For server, default auto connections will
    be turned off in NetworkManager.conf.)
    The connection id (and consequently ifcfg file) is set to device name.
    Returns True if any ifcfg file was dumped.

    """
    rv = False

    for devname in nm.nm_devices():
        # for each ethernet device
        # FIXME add more types (infiniband, bond...?)
        if not nm.nm_device_type_is_ethernet(devname):
            continue

        # if there is no ifcfg file for the device
        device_cfg = NetworkDevice(netscriptsDir, devname)
        if os.access(device_cfg.path, os.R_OK):
            continue

        try:
            nm.nm_update_settings_of_device(devname, 'connection', 'id', devname)
            log.debug("network: dumping ifcfg file for default autoconnection on %s" % devname)
            nm.nm_update_settings_of_device(devname, 'connection', 'autoconnect', False)
            log.debug("network: setting autoconnect of %s to False" % devname)
        except nm.DeviceSettingsNotFoundError as e:
            log.debug("network: no ifcfg file for %s" % devname)
        rv = True

    return rv
def find_ifcfg_file_of_device(devname, root_path=""):
    ifcfg_path = None

    if devname not in nm.nm_devices():
        return None

    if nm.nm_device_type_is_wifi(devname):
        ssid = nm.nm_device_active_ssid(devname)
        if ssid:
            ifcfg_path = find_ifcfg_file([("ESSID", ssid)])
    elif nm.nm_device_type_is_bond(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_team(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_vlan(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_ethernet(devname):
        try:
            hwaddr = nm.nm_device_hwaddress(devname)
        except nm.PropertyNotFoundError:
            hwaddr = None
        if hwaddr:
            hwaddr_check = lambda mac: mac.upper() == hwaddr.upper()
            nonempty = lambda x: x
            # slave configration created in GUI takes precedence
            ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check), ("MASTER", nonempty)], root_path)
            if not ifcfg_path:
                ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check), ("TEAM_MASTER", nonempty)], root_path)
            if not ifcfg_path:
                ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check)], root_path)
        if not ifcfg_path:
            ifcfg_path = find_ifcfg_file([("DEVICE", devname)], root_path)

    return ifcfg_path
Beispiel #7
0
    def setNetworkOnbootDefault(self, ksdata):
        # if there is no device to be autoactivated after reboot
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                onboot = nm.nm_device_setting_value(devName, "connection",
                                                    "autoconnect")
            except nm.SettingsNotFoundError:
                continue
            if not onboot == False:
                return

        # set ONBOOT=yes for the device used during installation
        # (ie for majority of cases the one having the default route)
        devName = network.default_route_device()
        if not devName:
            return
        if nm.nm_device_type_is_wifi(devName):
            return
        ifcfg_path = network.find_ifcfg_file_of_device(devName,
                                                       root_path=ROOT_PATH)
        if not ifcfg_path:
            return
        ifcfg = network.IfcfgFile(ifcfg_path)
        ifcfg.read()
        ifcfg.set(('ONBOOT', 'yes'))
        ifcfg.write()
        for nd in ksdata.network.network:
            if nd.device == devName:
                nd.onboot = True
                break
def networkInitialize(ksdata):

    log.debug("network: devices found %s", nm.nm_devices())
    logIfcfgFiles("network initialization")

    if not flags.imageInstall:
        devnames = apply_kickstart_from_pre_section(ksdata)
        if devnames:
            msg = "kickstart pre section applied for devices %s" % devnames
            log.debug("network: %s", msg)
            logIfcfgFiles(msg)
        devnames = dumpMissingDefaultIfcfgs()
        if devnames:
            msg = "missing ifcfgs created for devices %s" % devnames
            log.debug("network: %s", msg)
            logIfcfgFiles(msg)

    # For kickstart network --activate option we set ONBOOT=yes
    # in dracut to get devices activated by NM. The real network --onboot
    # value is set here.
    devnames = setOnboot(ksdata)
    if devnames:
        msg = "setting real kickstart ONBOOT value for devices %s" % devnames
        log.debug("network: %s", msg)
        logIfcfgFiles(msg)

    if ksdata.network.hostname is None:
        hostname = getHostname()
        update_hostname_data(ksdata, hostname)
Beispiel #9
0
    def refresh(self):
        """
        The refresh method that is called every time the spoke is displayed.
        It should update the UI elements according to the contents of
        self.data.

        :see: pyanaconda.ui.common.UIObject.refresh

        """
        ## Every time we enter, make a list of all the devices that
        # are not the public interface (user might have changed this)
        pubif = network.default_route_device()
        allifs = filter(lambda x: nm.nm_device_type_is_ethernet(x),\
                nm.nm_devices())
        privates = filter(lambda x: x != pubif,allifs)
        idx = self.ifaceCombo.get_active()
        self.deviceStore.clear()
        for x in privates:
            entry=[None,None,None,None]
            entry[DEVICEIDX] = x
            entry[TYPEIDX] = "ethernet"
            entry[MACIDX] = nm.nm_device_perm_hwaddress(x)
            entry[LABELIDX] = "%s;%s" % (x,entry[MACIDX])
            self.deviceStore.append(entry)
        if len(privates) == 0:
            entry=[None,None,None,None]
            entry[DEVICEIDX] = "%s:0" % pubif
            entry[LABELIDX] = "%s;virtual interface" % entry[DEVICEIDX] 
            entry[TYPEIDX] = "virtual"
            entry[MACIDX] = ""
            self.deviceStore.append(entry)

        # Set the active entry, even if we reodered 
        self.ifaceCombo.set_active(idx)
Beispiel #10
0
    def _update_network_data(self):
        hostname = self._network_module.proxy.Hostname

        self.data.network.network = []
        for i, name in enumerate(nm.nm_devices()):
            if network.is_ibft_configured_device(name):
                continue
            nd = network.ksdata_from_ifcfg(name)
            if not nd:
                continue
            if name in nm.nm_activated_devices():
                nd.activate = True
            else:
                # First network command defaults to --activate so we must
                # use --no-activate explicitly to prevent the default
                if i == 0:
                    nd.activate = False
            self.data.network.network.append(nd)

        (valid, error) = network.sanityCheckHostname(self._value)
        if valid:
            hostname = self._value
        else:
            self.errors.append(_("Host name is not valid: %s") % error)
            self._value = hostname
        network.update_hostname_data(self.data, hostname)
def get_bond_slaves_from_ifcfgs(master_specs):
    """List of slave device names of master specified by master_specs.

       master_specs is a list containing device name of master (dracut)
       and/or master's connection uuid
    """
    slaves = []

    for filepath in _ifcfg_files(netscriptsDir):
        ifcfg = IfcfgFile(filepath)
        ifcfg.read()
        master = ifcfg.get("MASTER")
        if master in master_specs:
            device = ifcfg.get("DEVICE")
            if device:
                slaves.append(device)
            else:
                hwaddr = ifcfg.get("HWADDR")
                for devname in nm.nm_devices():
                    try:
                        h = nm.nm_device_property(devname, "PermHwAddress")
                    except nm.PropertyNotFoundError:
                        log.debug("can't get PermHwAddress of devname %s",
                                  devname)
                        continue
                    if h.upper() == hwaddr.upper():
                        slaves.append(devname)
                        break
    return slaves
Beispiel #12
0
    def _update_network_data(self):
        hostname = self.data.network.hostname

        self.data.network.network = []
        for i, name in enumerate(nm.nm_devices()):
            if network.is_ibft_configured_device(name):
                continue
            nd = network.ksdata_from_ifcfg(name)
            if not nd:
                continue
            if name in nm.nm_activated_devices():
                nd.activate = True
            else:
                # First network command defaults to --activate so we must
                # use --no-activate explicitly to prevent the default
                if i == 0:
                    nd.activate = False
            self.data.network.network.append(nd)

        (valid, error) = network.sanityCheckHostname(self.hostname_dialog.value)
        if valid:
            hostname = self.hostname_dialog.value
        else:
            self.errors.append(_("Host name is not valid: %s") % error)
            self.hostname_dialog.value = hostname
        network.update_hostname_data(self.data, hostname)
Beispiel #13
0
    def refresh(self):
        """
        The refresh method that is called every time the spoke is displayed.
        It should update the UI elements according to the contents of
        self.data.

        :see: pyanaconda.ui.common.UIObject.refresh

        """
        ## Every time we enter, make a list of all the devices that
        # are not the public interface (user might have changed this)
        pubif = network.default_route_device()
        allifs = filter(lambda x: nm.nm_device_type_is_ethernet(x),\
                nm.nm_devices())
        privates = filter(lambda x: x != pubif,allifs)
        idx = self.ifaceCombo.get_active()
        self.deviceStore.clear()
        for x in privates:
            entry=[None,None,None,None]
            entry[DEVICEIDX] = x
            entry[TYPEIDX] = "ethernet"
            entry[MACIDX] = nm.nm_device_valid_hwaddress(x)
            entry[LABELIDX] = "%s;%s" % (x,entry[MACIDX])
            self.deviceStore.append(entry)
        if len(privates) == 0:
            entry=[None,None,None,None]
            entry[DEVICEIDX] = "%s:0" % pubif
            entry[LABELIDX] = "%s;virtual interface" % entry[DEVICEIDX] 
            entry[TYPEIDX] = "virtual"
            entry[MACIDX] = ""
            self.deviceStore.append(entry)

        # Set the active entry, even if we reodered 
        self.ifaceCombo.set_active(idx)
def get_bond_slaves_from_ifcfgs(master_specs):
    """List of slave device names of master specified by master_specs.

       master_specs is a list containing device name of master (dracut)
       and/or master's connection uuid
    """
    slaves = []

    for filepath in _ifcfg_files(netscriptsDir):
        ifcfg = IfcfgFile(filepath)
        ifcfg.read()
        master = ifcfg.get("MASTER")
        if master in master_specs:
            device = ifcfg.get("DEVICE")
            if device:
                slaves.append(device)
            else:
                hwaddr = ifcfg.get("HWADDR")
                for devname in nm.nm_devices():
                    try:
                        h = nm.nm_device_property(devname, "PermHwAddress")
                    except nm.PropertyNotFoundError:
                        log.debug("can't get PermHwAddress of devname %s", devname)
                        continue
                    if h.upper() == hwaddr.upper():
                        slaves.append(devname)
                        break
    return slaves
def get_device_name(devspec):

    devices = nm.nm_devices()
    devname = None

    if not devspec:
        if "ksdevice" in flags.cmdline:
            msg = "ksdevice boot parameter"
            devname = ks_spec_to_device_name(flags.cmdline["ksdevice"])
        elif nm.nm_is_connected():
            # device activated in stage 1 by network kickstart command
            msg = "first active device"
            try:
                devname = nm.nm_activated_devices()[0]
            except IndexError:
                log.debug("get_device_name: NM is connected but no activated devices found")
        else:
            msg = "first device found"
            devname = min(devices)
        log.info("unspecified network --device in kickstart, using %s (%s)", devname, msg)
    else:
        if iutil.lowerASCII(devspec) == "ibft":
            devname = ""
        if iutil.lowerASCII(devspec) == "link":
            for dev in sorted(devices):
                try:
                    link_up = nm.nm_device_carrier(dev)
                except ValueError as e:
                    log.debug("get_device_name: %s", e)
                    continue
                if link_up:
                    devname = dev
                    break
            else:
                log.error("Kickstart: No network device with link found")
        elif iutil.lowerASCII(devspec) == "bootif":
            if "BOOTIF" in flags.cmdline:
                # MAC address like 01-aa-bb-cc-dd-ee-ff
                devname = flags.cmdline["BOOTIF"][3:]
                devname = devname.replace("-", ":")
            else:
                log.error("Using --device=bootif without BOOTIF= boot option supplied")
        else:
            devname = devspec

    if devname and devname not in devices:
        for d in devices:
            try:
                hwaddr = nm.nm_device_hwaddress(d)
            except ValueError as e:
                log.debug("get_device_name: %s", e)
                continue
            if hwaddr.lower() == devname.lower():
                devname = d
                break
        else:
            return ""

    return devname
    def refresh(self):
        self._nicCombo.remove_all()

        for devname in nm.nm_devices():
            if nm.nm_device_type_is_ethernet(devname):
                self._nicCombo.append_text("%s - %s" % (devname, nm.nm_device_hwaddress(devname)))

        self._nicCombo.set_active(0)
Beispiel #17
0
    def refresh(self):
        self._nicCombo.remove_all()

        for devname in nm.nm_devices():
            if nm.nm_device_type_is_ethernet(devname):
                self._nicCombo.append_text("%s - %s" % (devname, nm.nm_device_hwaddress(devname)))

        self._nicCombo.set_active(0)
Beispiel #18
0
def devices_used_by_fcoe(storage):
    fcoe_nics = {
        d.nic
        for d in storage.devices if isinstance(d, FcoeDiskDevice)
    }
    fcoe_devices = [
        device for device in nm.nm_devices() if device in fcoe_nics
    ]
    return fcoe_devices
Beispiel #19
0
def disableIPV6(rootpath):
    cfgfile = os.path.normpath(rootpath + ipv6ConfFile)
    if ('noipv6' in flags.cmdline
        and all(nm.nm_device_setting_value(dev, "ipv6", "method") == "ignore"
                for dev in nm.nm_devices() if nm.nm_device_type_is_ethernet(dev))):
        log.info('Disabling ipv6 on target system')
        with open(cfgfile, "a") as f:
            f.write("# Anaconda disabling ipv6 (noipv6 option)\n")
            f.write("net.ipv6.conf.all.disable_ipv6=1\n")
            f.write("net.ipv6.conf.default.disable_ipv6=1\n")
def disableIPV6(rootpath):
    cfgfile = os.path.normpath(rootpath + ipv6ConfFile)
    if ('noipv6' in flags.cmdline and all(
            nm.nm_device_setting_value(dev, "ipv6", "method") == "ignore"
            for dev in nm.nm_devices() if nm.nm_device_type_is_ethernet(dev))):
        log.info('Disabling ipv6 on target system')
        with open(cfgfile, "a") as f:
            f.write("# Anaconda disabling ipv6 (noipv6 option)\n")
            f.write("net.ipv6.conf.all.disable_ipv6=1\n")
            f.write("net.ipv6.conf.default.disable_ipv6=1\n")
Beispiel #21
0
    def initialize(self):
        for name in nm.nm_devices():
            if nm.nm_device_type_is_ethernet(name):
                # ignore slaves
                if nm.nm_device_setting_value(name, "connection", "slave-type"):
                    continue
                self.supported_devices.append(name)

        EditTUISpoke.initialize(self)
        if not self.data.network.seen:
            self._update_network_data()
Beispiel #22
0
    def initialize(self):
        for name in nm_devices():
            if nm_device_type_is_ethernet(name):
                # ignore slaves
                if nm_device_setting_value(name, "connection", "slave-type"):
                    continue
                self.supported_devices.append(name)

        EditTUISpoke.initialize(self)
        if not self.data.network.seen:
            self._update_network_data()
def disableNMForStorageDevices(rootpath, storage):
    for devname in nm.nm_devices():
        if usedByFCoE(devname, storage) or usedByRootOnISCSI(devname, storage):
            ifcfg_path = find_ifcfg_file_of_device(devname, root_path=rootpath)
            if not ifcfg_path:
                log.warning("disableNMForStorageDevices: ifcfg file for %s not found", devname)
                continue
            ifcfg = IfcfgFile(ifcfg_path)
            ifcfg.read()
            ifcfg.set(("NM_CONTROLLED", "no"))
            ifcfg.write()
            log.info("network device %s used by storage will not be " "controlled by NM", devname)
Beispiel #24
0
def get_device_name(network_data):

    ksspec = network_data.device or flags.cmdline.get('ksdevice', "")
    dev_name = ks_spec_to_device_name(ksspec)
    if not dev_name:
        return ""
    if dev_name not in nm.nm_devices():
        if not any((network_data.vlanid, network_data.bondslaves, network_data.teamslaves)):
            return ""
    if network_data.vlanid:
        dev_name = "%s.%s" % (dev_name, network_data.vlanid)

    return dev_name
Beispiel #25
0
def networkInitialize(ksdata):
    if not conf.system.can_configure_network:
        return

    log.debug("devices found %s", nm.nm_devices())
    logIfcfgFiles("network initialization")

    log.debug("ensure single initramfs connections")
    network_proxy = NETWORK.get_proxy()
    devnames = network_proxy.ConsolidateInitramfsConnections()
    if devnames:
        msg = "single connection ensured for devices %s" % devnames
        log.debug("%s", msg)
        logIfcfgFiles(msg)
    log.debug("apply kickstart")
    devnames = network_proxy.ApplyKickstart()
    if devnames:
        msg = "kickstart pre section applied for devices %s" % devnames
        log.debug("%s", msg)
        logIfcfgFiles(msg)
    log.debug("create missing ifcfg files")
    devnames = network_proxy.DumpMissingIfcfgFiles()
    if devnames:
        msg = "missing ifcfgs created for devices %s" % devnames
        log.debug("%s", msg)
        logIfcfgFiles(msg)

    # For kickstart network --activate option we set ONBOOT=yes
    # in dracut to get devices activated by NM. The real network --onboot
    # value is set here.
    log.debug("set real ONBOOT value")
    devnames = network_proxy.SetRealOnbootValuesFromKickstart()
    if devnames:
        msg = "real kickstart ONBOOT value set for devices %s" % devnames
        log.debug("%s", msg)
        logIfcfgFiles(msg)

    # initialize ksdata hostname
    if network_proxy.Hostname == DEFAULT_HOSTNAME:
        bootopts_hostname = hostname_from_cmdline(flags.cmdline)
        if bootopts_hostname:
            log.debug("updating host name from boot options: %s",
                      bootopts_hostname)
            network_proxy.SetHostname(bootopts_hostname)

    # Create device configuration tracking in the module.
    # It will be used to generate kickstart from persistent network configuration
    # managed by NM (ifcfgs) and updated by NM signals on device configuration
    # changes.
    log.debug("create network configurations")
    network_proxy.CreateDeviceConfigurations()
Beispiel #26
0
def get_device_name(network_data):

    ksspec = network_data.device or flags.cmdline.get('ksdevice', "")
    dev_name = ks_spec_to_device_name(ksspec)
    if not dev_name:
        return ""
    if dev_name not in nm.nm_devices():
        if not any((network_data.vlanid, network_data.bondslaves,
                    network_data.teamslaves)):
            return ""
    if network_data.vlanid:
        dev_name = "%s.%s" % (dev_name, network_data.vlanid)

    return dev_name
Beispiel #27
0
def get_device_name(network_data):

    ksspec = network_data.device or flags.cmdline.get('ksdevice', "")
    dev_name = ks_spec_to_device_name(ksspec)
    if not dev_name:
        return ""
    if dev_name not in nm.nm_devices():
        if not any((network_data.vlanid, network_data.bondslaves, network_data.teamslaves)):
            return ""
    if network_data.vlanid:
        network_data.parent = dev_name
        dev_name = network_data.interfacename or default_ks_vlan_interface_name(network_data.parent, network_data.vlanid)

    return dev_name
Beispiel #28
0
 def setNetworkOnbootDefault(self, ksdata):
     if network.has_some_wired_autoconnect_device():
         return
     # choose first wired device having link
     for dev in nm.nm_devices():
         if nm.nm_device_type_is_wifi(dev):
             continue
         try:
             link_up = nm.nm_device_carrier(dev)
         except (nm.UnknownDeviceError, nm.PropertyNotFoundError):
             continue
         if link_up:
             network.update_onboot_value(dev, "yes", ksdata)
             break
Beispiel #29
0
    def _load_new_devices(self):
        devices = nm.nm_devices()
        intf_dumped = network.dumpMissingDefaultIfcfgs()
        if intf_dumped:
            log.debug("Dumped interfaces: %s", intf_dumped)

        for name in devices:
            if name in self.supported_devices:
                continue
            if nm.nm_device_type_is_ethernet(name):
                # ignore slaves
                if nm.nm_device_setting_value(name, "connection", "slave-type"):
                    continue
                self.supported_devices.append(name)
def disableNMForStorageDevices(rootpath, storage):
    for devname in nm.nm_devices():
        if (usedByFCoE(devname, storage) or
            usedByRootOnISCSI(devname, storage)):
            dev = NetworkDevice(rootpath + netscriptsDir, devname)
            if os.access(dev.path, os.R_OK):
                dev.loadIfcfgFile()
                dev.set(('NM_CONTROLLED', 'no'))
                dev.writeIfcfgFile()
                log.info("network device %s used by storage will not be "
                         "controlled by NM" % devname)
            else:
                log.warning("disableNMForStorageDevices: ifcfg file for %s not found" %
                            devname)
Beispiel #31
0
 def setNetworkOnbootDefault(self, ksdata):
     if any(nd.onboot for nd in ksdata.network.network if nd.device):
         return
     # choose first wired device having link
     for dev in nm.nm_devices():
         if nm.nm_device_type_is_wifi(dev):
             continue
         try:
             link_up = nm.nm_device_carrier(dev)
         except (nm.UnknownDeviceError, nm.PropertyNotFoundError):
             continue
         if link_up:
             network.update_onboot_value(dev, True, ksdata=ksdata)
             break
Beispiel #32
0
 def setNetworkOnbootDefault(self, ksdata):
     if network.has_some_wired_autoconnect_device():
         return
     # choose first wired device having link
     for dev in nm.nm_devices():
         if nm.nm_device_type_is_wifi(dev):
             continue
         try:
             link_up = nm.nm_device_carrier(dev)
         except (nm.UnknownDeviceError, nm.PropertyNotFoundError):
             continue
         if link_up:
             network.update_onboot_value(dev, "yes", ksdata)
             break
Beispiel #33
0
    def _load_new_devices(self):
        devices = nm.nm_devices()
        intf_dumped = network.dumpMissingDefaultIfcfgs()
        if intf_dumped:
            log.debug("Dumped interfaces: %s", intf_dumped)

        for name in devices:
            if name in self.supported_devices:
                continue
            if nm.nm_device_type_is_ethernet(name):
                # ignore slaves
                if nm.nm_device_setting_value(name, "connection", "slave-type"):
                    continue
                self.supported_devices.append(name)
Beispiel #34
0
 def setNetworkOnbootDefault(self, ksdata):
     if any(nd.onboot for nd in ksdata.network.network if nd.device):
         return
     # choose first wired device having link
     for dev in nm.nm_devices():
         if nm.nm_device_type_is_wifi(dev):
             continue
         try:
             link_up = nm.nm_device_carrier(dev)
         except (nm.UnknownDeviceError, nm.PropertyNotFoundError):
             continue
         if link_up:
             network.update_onboot_value(dev, True, ksdata=ksdata)
             break
Beispiel #35
0
def disableNMForStorageDevices(rootpath, storage):
    for devname in nm.nm_devices():
        if (usedByFCoE(devname, storage)
                or usedByRootOnISCSI(devname, storage)):
            ifcfg_path = find_ifcfg_file_of_device(devname, root_path=rootpath)
            if not ifcfg_path:
                log.warning(
                    "disableNMForStorageDevices: ifcfg file for %s not found" %
                    devname)
                continue
            ifcfg = IfcfgFile(ifcfg_path)
            ifcfg.read()
            ifcfg.set(('NM_CONTROLLED', 'no'))
            ifcfg.write()
            log.info("network device %s used by storage will not be "
                     "controlled by NM" % devname)
Beispiel #36
0
def get_device_name(network_data):

    ksspec = network_data.device or flags.cmdline.get('ksdevice', "")
    dev_name = ks_spec_to_device_name(ksspec)
    if not dev_name:
        return ""
    if dev_name not in nm.nm_devices():
        if not any((network_data.vlanid, network_data.bondslaves,
                    network_data.teamslaves)):
            return ""
    if network_data.vlanid:
        network_data.parent = dev_name
        dev_name = network_data.interfacename or default_ks_vlan_interface_name(
            network_data.parent, network_data.vlanid)

    return dev_name
def autostartFCoEDevices(rootpath, storage, ksdata):
    for devname in nm.nm_devices():
        if usedByFCoE(devname, storage):
            dev = NetworkDevice(rootpath + netscriptsDir, devname)
            if os.access(dev.path, os.R_OK):
                dev.loadIfcfgFile()
                dev.set(('ONBOOT', 'yes'))
                dev.writeIfcfgFile()
                log.debug("setting ONBOOT=yes for network device %s used by fcoe"
                          % devname)
                for nd in ksdata.network.network:
                    if nd.device == dev.iface:
                        nd.onboot = True
                        break
            else:
                log.warning("autoconnectFCoEDevices: ifcfg file for %s not found" %
                            devname)
Beispiel #38
0
    def refresh(self):
        self._addButton = self.builder.get_object("addButton")
        self._cancelButton = self.builder.get_object("cancelButton")
        self._addSpinner = self.builder.get_object("addSpinner")
        self._errorBox = self.builder.get_object("errorBox")

        self._nicCombo = self.builder.get_object("nicCombo")
        self._nicCombo.remove_all()

        self._dcbCheckbox = self.builder.get_object("dcbCheckbox")
        self._autoCheckbox = self.builder.get_object("autoCheckbox")

        for devname in nm.nm_devices():
            if nm.nm_device_type_is_ethernet(devname):
                self._nicCombo.append_text("%s - %s" % (devname, nm.nm_device_hwaddress(devname)))

        self._nicCombo.set_active(0)
Beispiel #39
0
def networkInitialize(ksdata):

    log.debug("network: devices found %s", nm.nm_devices())
    logIfcfgFiles("network initialization")

    if not flags.imageInstall and 0:  # sabayon
        if dumpMissingDefaultIfcfgs():
            logIfcfgFiles("ifcfgs created")

    # For kickstart network --activate option we set ONBOOT=yes
    # in dracut to get devices activated by NM. The real network --onboot
    # value is set here.
    setOnboot(ksdata)

    if ksdata.network.hostname is None:
        hostname = getHostname()
        update_hostname_data(ksdata, hostname)
Beispiel #40
0
def networkInitialize(ksdata):

    log.debug("network: devices found %s", nm.nm_devices())
    logIfcfgFiles("network initialization")

    if not flags.imageInstall and 0:  # sabayon
        if dumpMissingDefaultIfcfgs():
            logIfcfgFiles("ifcfgs created")

    # For kickstart network --activate option we set ONBOOT=yes
    # in dracut to get devices activated by NM. The real network --onboot
    # value is set here.
    setOnboot(ksdata)

    if ksdata.network.hostname is None:
        hostname = getHostname()
        update_hostname_data(ksdata, hostname)
def autostartFCoEDevices(rootpath, storage, ksdata):
    for devname in nm.nm_devices():
        if usedByFCoE(devname, storage):
            ifcfg_path = find_ifcfg_file_of_device(devname, root_path=rootpath)
            if not ifcfg_path:
                log.warning("autoconnectFCoEDevices: ifcfg file for %s not found", devname)
                continue

            ifcfg = IfcfgFile(ifcfg_path)
            ifcfg.read()
            ifcfg.set(("ONBOOT", "yes"))
            ifcfg.write()
            log.debug("setting ONBOOT=yes for network device %s used by fcoe", devname)
            for nd in ksdata.network.network:
                if nd.device == devname:
                    nd.onboot = True
                    break
Beispiel #42
0
def ksdata_from_ifcfg(devname, uuid=None):

    if devname not in nm.nm_devices():
        return None

    if nm.nm_device_is_slave(devname):
        return None
    if nm.nm_device_type_is_wifi(devname):
        # wifi from kickstart is not supported yet
        return None

    if not uuid:
        # Find ifcfg file for the device.
        # If the device is active, use uuid of its active connection.
        uuid = nm.nm_device_active_con_uuid(devname)

    if uuid:
        ifcfg_path = find_ifcfg_file([("UUID", uuid)])
    else:
        # look it up by other values depending on its type
        ifcfg_path = find_ifcfg_file_of_device(devname)

    if not ifcfg_path:
        return None

    ifcfg = IfcfgFile(ifcfg_path)
    ifcfg.read()
    nd = ifcfg_to_ksdata(ifcfg, devname)

    if not nd:
        return None

    if nm.nm_device_type_is_ethernet(devname):
        nd.device = devname
    elif nm.nm_device_type_is_wifi(devname):
        nm.device = ""
    elif nm.nm_device_type_is_bond(devname):
        nd.device = devname
    elif nm.nm_device_type_is_team(devname):
        nd.device = devname
    elif nm.nm_device_type_is_vlan(devname):
        if devname != default_ks_vlan_interface_name(nd.device, nd.vlanid):
            nd.interfacename = devname

    return nd
def ks_spec_to_device_name(ksspec=""):

    if not ksspec:
        ksspec = flags.cmdline.get('ksdevice', "")
    ksdevice = ksspec

    bootif_mac = ''
    if ksdevice == 'bootif' and "BOOTIF" in flags.cmdline:
        bootif_mac = flags.cmdline["BOOTIF"][3:].replace("-", ":").upper()
    for dev in sorted(nm.nm_devices()):
        # "eth0"
        if ksdevice == dev:
            break
        # "link"
        elif ksdevice == 'link':
            try:
                link_up = nm.nm_device_carrier(dev)
            except ValueError as e:
                log.debug("ks_spec_to_device_name: %s", e)
                continue
            if link_up:
                ksdevice = dev
                break
        # "XX:XX:XX:XX:XX:XX" (mac address)
        elif ':' in ksdevice:
            try:
                hwaddr = nm.nm_device_hwaddress(dev)
            except ValueError as e:
                log.debug("ks_spec_to_device_name: %s", e)
                continue
            if ksdevice.lower() == hwaddr.lower():
                ksdevice = dev
                break
        # "bootif" and BOOTIF==XX:XX:XX:XX:XX:XX
        elif ksdevice == 'bootif':
            try:
                hwaddr = nm.nm_device_hwaddress(dev)
            except ValueError as e:
                log.debug("ks_spec_to_device_name: %s", e)
                continue
            if bootif_mac.lower() == hwaddr.lower():
                ksdevice = dev
                break

    return ksdevice
def ks_spec_to_device_name(ksspec=""):

    if not ksspec:
        ksspec = flags.cmdline.get("ksdevice", "")
    ksdevice = ksspec

    bootif_mac = ""
    if ksdevice == "bootif" and "BOOTIF" in flags.cmdline:
        bootif_mac = flags.cmdline["BOOTIF"][3:].replace("-", ":").upper()
    for dev in sorted(nm.nm_devices()):
        # "eth0"
        if ksdevice == dev:
            break
        # "link"
        elif ksdevice == "link":
            try:
                link_up = nm.nm_device_carrier(dev)
            except ValueError as e:
                log.debug("ks_spec_to_device_name: %s", e)
                continue
            if link_up:
                ksdevice = dev
                break
        # "XX:XX:XX:XX:XX:XX" (mac address)
        elif ":" in ksdevice:
            try:
                hwaddr = nm.nm_device_hwaddress(dev)
            except ValueError as e:
                log.debug("ks_spec_to_device_name: %s", e)
                continue
            if ksdevice.lower() == hwaddr.lower():
                ksdevice = dev
                break
        # "bootif" and BOOTIF==XX:XX:XX:XX:XX:XX
        elif ksdevice == "bootif":
            try:
                hwaddr = nm.nm_device_hwaddress(dev)
            except ValueError as e:
                log.debug("ks_spec_to_device_name: %s", e)
                continue
            if bootif_mac.lower() == hwaddr.lower():
                ksdevice = dev
                break

    return ksdevice
def dracutSetupArgs(networkStorageDevice):

    if networkStorageDevice.nic == "default" or ":" in networkStorageDevice.nic:
        nic = ifaceForHostIP(networkStorageDevice.host_address)
        if not nic:
            return ""
    else:
        nic = networkStorageDevice.nic

    if nic not in nm.nm_devices():
        log.error('Unknown network interface: %s' % nic)
        return ""

    ifcfg = NetworkDevice(netscriptsDir, nic)
    ifcfg.loadIfcfgFile()
    return dracutBootArguments(ifcfg,
                               networkStorageDevice.host_address,
                               getHostname())
Beispiel #46
0
def apply_kickstart_from_pre_section(ksdata):
    applied_devices = []

    for network_data in ksdata.network.network:

        # TODO: wireless not supported yet
        if network_data.essid:
            continue

        # get device name for device specified by MAC, link, bootif, etc...
        dev_name = ks_spec_to_device_name(network_data.device)
        if (not dev_name
            or (dev_name not in nm.nm_devices()
                and not network_data.vlanid
                and not network_data.bondslaves)):
            log.error("network: pre kickstart: --device %s does not exist", network_data.device)
            continue

        if network_data.vlanid:
            dev_name = "%s.%s" % (dev_name, network_data.vlanid)

        ifcfg_path = find_ifcfg_file_of_device(dev_name)
        # if the device was already configured in intramfs by kickstart ignore it
        if ifcfg_path:
            with open(ifcfg_path, 'r') as f:
                if "Generated by parse-kickstart" in f.read():
                    continue

        applied_devices.append(dev_name)
        if ifcfg_path:
            # if the device was already configured in initramfs update the settings
            log.debug("network: pre kickstart - updating settings of device %s", dev_name)
            con_uuid = update_settings_with_ksdata(dev_name, network_data)
            added_connections = [(con_uuid, dev_name)]
        else:
            log.debug("network: pre kickstart - adding connection for %s", dev_name)
            # Virtual devices (eg vlan, bond) return dev_name == None
            added_connections = add_connection_for_ksdata(network_data, dev_name)

        if network_data.activate:
            for con_uuid, dev_name in added_connections:
                nm.nm_activate_device_connection(dev_name, con_uuid)

    return applied_devices
Beispiel #47
0
    def _update_network_data(self):
        hostname = self.data.network.hostname

        self.data.network.network = []
        for name in nm.nm_devices():
            nd = network.ksdata_from_ifcfg(name)
            if not nd:
                continue
            if name in nm.nm_activated_devices():
                nd.activate = True
            self.data.network.network.append(nd)

        (valid, error) = network.sanityCheckHostname(self.hostname_dialog.value)
        if valid:
            hostname = self.hostname_dialog.value
        else:
            self.errors.append(_("Host name is not valid: %s") % error)
            self.hostname_dialog.value = hostname
        network.update_hostname_data(self.data, hostname)
Beispiel #48
0
    def parse(self, args):
        fc = super().parse(args)

        if fc.nic not in nm.nm_devices():
            raise KickstartParseError(_("NIC \"{}\" given in fcoe command does not "
                                        "exist.").format(fc.nic), lineno=self.lineno)

        if fc.nic in (info[0] for info in fcoe.nics):
            log.info("Kickstart fcoe device %s was already added from EDD, ignoring.", fc.nic)
        else:
            msg = fcoe.add_san(nic=fc.nic, dcb=fc.dcb, auto_vlan=True)

            if not msg:
                msg = "Succeeded."
                fcoe.added_nics.append(fc.nic)

            log.info("Adding FCoE SAN on %s: %s", fc.nic, msg)

        return fc
Beispiel #49
0
    def _load_new_devices(self):
        devices = nm.nm_devices()
        intf_dumped = network.dumpMissingDefaultIfcfgs()
        if intf_dumped:
            log.debug("dumped interfaces: %s", intf_dumped)

        for name in devices:
            if name in self.supported_devices:
                continue
            if network.is_ibft_configured_device(name):
                continue
            if network.device_type_is_supported_wired(name):
                # ignore slaves
                try:
                    if nm.nm_device_setting_value(name, "connection", "slave-type"):
                        continue
                except nm.MultipleSettingsFoundError as e:
                    log.debug("%s during initialization", e)
                self.supported_devices.append(name)
Beispiel #50
0
    def _load_new_devices(self):
        devices = nm.nm_devices()
        intf_dumped = network.dumpMissingDefaultIfcfgs()
        if intf_dumped:
            log.debug("dumped interfaces: %s", intf_dumped)

        for name in devices:
            if name in self.supported_devices:
                continue
            if network.is_ibft_configured_device(name):
                continue
            if network.device_type_is_supported_wired(name):
                # ignore slaves
                try:
                    if nm.nm_device_setting_value(name, "connection", "slave-type"):
                        continue
                except nm.MultipleSettingsFoundError as e:
                    log.debug("%s during initialization", e)
                self.supported_devices.append(name)
Beispiel #51
0
    def _update_network_data(self):
        hostname = self.data.network.hostname

        self.data.network.network = []
        for name in nm.nm_devices():
            nd = network.ksdata_from_ifcfg(name)
            if not nd:
                continue
            if name in nm.nm_activated_devices():
                nd.activate = True
            self.data.network.network.append(nd)

        (valid, error) = network.sanityCheckHostname(self.hostname_dialog.value)
        if valid:
            hostname = self.hostname_dialog.value
        else:
            self.errors.append(_("Host name is not valid: %s") % error)
            self.hostname_dialog.value = hostname
        network.update_hostname_data(self.data, hostname)
def dumpMissingDefaultIfcfgs():
    """
    Dump missing default ifcfg file for wired devices.
    For default auto connections created by NM upon start - which happens
    in case of missing ifcfg file - rename the connection using device name
    and dump its ifcfg file. (For server, default auto connections will
    be turned off in NetworkManager.conf.)
    The connection id (and consequently ifcfg file) is set to device name.
    Returns list of devices for which ifcfg file was dumped.

    """
    rv = []

    for devname in nm.nm_devices():
        # for each ethernet device
        # FIXME add more types (infiniband, bond...?)
        if not nm.nm_device_type_is_ethernet(devname):
            continue

        # check that device has connection without ifcfg file
        try:
            con_uuid = nm.nm_device_setting_value(devname, "connection",
                                                  "uuid")
        except nm.SettingsNotFoundError:
            continue
        if find_ifcfg_file_of_device(devname):
            continue

        try:
            nm.nm_update_settings_of_device(
                devname, [['connection', 'id', devname, None]])
            log.debug(
                "network: dumping ifcfg file for default autoconnection on %s",
                devname)
            nm.nm_update_settings_of_device(
                devname, [['connection', 'autoconnect', False, None]])
            log.debug("network: setting autoconnect of %s to False", devname)
        except nm.SettingsNotFoundError:
            log.debug("network: no ifcfg file for %s", devname)
        rv.append(devname)

    return rv
def dracutSetupArgs(networkStorageDevice):

    if networkStorageDevice.nic == "default" or ":" in networkStorageDevice.nic:
        nic = ifaceForHostIP(networkStorageDevice.host_address)
        if not nic:
            return ""
    else:
        nic = networkStorageDevice.nic

    if nic not in nm.nm_devices():
        log.error("Unknown network interface: %s", nic)
        return ""

    ifcfg_path = find_ifcfg_file_of_device(nic)
    if not ifcfg_path:
        log.error("dracutSetupArgs: can't find ifcfg file for %s", nic)
        return ""
    ifcfg = IfcfgFile(ifcfg_path)
    ifcfg.read()
    return dracutBootArguments(nic, ifcfg, networkStorageDevice.host_address, getHostname())
def autostartFCoEDevices(rootpath, storage, ksdata):
    for devname in nm.nm_devices():
        if usedByFCoE(devname, storage):
            ifcfg_path = find_ifcfg_file_of_device(devname, root_path=rootpath)
            if not ifcfg_path:
                log.warning(
                    "autoconnectFCoEDevices: ifcfg file for %s not found",
                    devname)
                continue

            ifcfg = IfcfgFile(ifcfg_path)
            ifcfg.read()
            ifcfg.set(('ONBOOT', 'yes'))
            ifcfg.write()
            log.debug("setting ONBOOT=yes for network device %s used by fcoe",
                      devname)
            for nd in ksdata.network.network:
                if nd.device == devname:
                    nd.onboot = True
                    break
def dracutSetupArgs(networkStorageDevice):

    if networkStorageDevice.nic == "default" or ":" in networkStorageDevice.nic:
        nic = ifaceForHostIP(networkStorageDevice.host_address)
        if not nic:
            return ""
    else:
        nic = networkStorageDevice.nic

    if nic not in nm.nm_devices():
        log.error('Unknown network interface: %s', nic)
        return ""

    ifcfg_path = find_ifcfg_file_of_device(nic)
    if not ifcfg_path:
        log.error("dracutSetupArgs: can't find ifcfg file for %s", nic)
        return ""
    ifcfg = IfcfgFile(ifcfg_path)
    ifcfg.read()
    return dracutBootArguments(nic, ifcfg, networkStorageDevice.host_address,
                               getHostname())
def find_ifcfg_file_of_device(devname, root_path=""):
    ifcfg_path = None

    if devname not in nm.nm_devices():
        return None

    if nm.nm_device_type_is_wifi(devname):
        ssid = nm.nm_device_active_ssid(devname)
        if ssid:
            ifcfg_path = find_ifcfg_file([("ESSID", ssid)])
    elif nm.nm_device_type_is_bond(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_team(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_vlan(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_ethernet(devname):
        try:
            hwaddr = nm.nm_device_hwaddress(devname)
        except nm.PropertyNotFoundError:
            hwaddr = None
        if hwaddr:
            hwaddr_check = lambda mac: mac.upper() == hwaddr.upper()
            nonempty = lambda x: x
            # slave configration created in GUI takes precedence
            ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check),
                                          ("MASTER", nonempty)], root_path)
            if not ifcfg_path:
                ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check),
                                              ("TEAM_MASTER", nonempty)],
                                             root_path)
            if not ifcfg_path:
                ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check)],
                                             root_path)
        if not ifcfg_path:
            ifcfg_path = find_ifcfg_file([("DEVICE", devname)], root_path)

    return ifcfg_path
Beispiel #57
0
    def parse(self, args):
        fc = super().parse(args)

        if fc.nic not in nm.nm_devices():
            raise KickstartParseError(_(
                "NIC \"{}\" given in fcoe command does not "
                "exist.").format(fc.nic),
                                      lineno=self.lineno)

        if fc.nic in (info[0] for info in fcoe.nics):
            log.info(
                "Kickstart fcoe device %s was already added from EDD, ignoring.",
                fc.nic)
        else:
            msg = fcoe.add_san(nic=fc.nic, dcb=fc.dcb, auto_vlan=True)

            if not msg:
                msg = "Succeeded."
                fcoe.added_nics.append(fc.nic)

            log.info("Adding FCoE SAN on %s: %s", fc.nic, msg)

        return fc
def dumpMissingDefaultIfcfgs():
    """
    Dump missing default ifcfg file for wired devices.
    For default auto connections created by NM upon start - which happens
    in case of missing ifcfg file - rename the connection using device name
    and dump its ifcfg file. (For server, default auto connections will
    be turned off in NetworkManager.conf.)
    The connection id (and consequently ifcfg file) is set to device name.
    Returns list of devices for which ifcfg file was dumped.

    """
    rv = []

    for devname in nm.nm_devices():
        # for each ethernet device
        # FIXME add more types (infiniband, bond...?)
        if not nm.nm_device_type_is_ethernet(devname):
            continue

        # check that device has connection without ifcfg file
        try:
            con_uuid = nm.nm_device_setting_value(devname, "connection", "uuid")
        except nm.SettingsNotFoundError:
            continue
        if find_ifcfg_file_of_device(devname):
            continue

        try:
            nm.nm_update_settings_of_device(devname, [["connection", "id", devname, None]])
            log.debug("network: dumping ifcfg file for default autoconnection on %s", devname)
            nm.nm_update_settings_of_device(devname, [["connection", "autoconnect", False, None]])
            log.debug("network: setting autoconnect of %s to False", devname)
        except nm.SettingsNotFoundError:
            log.debug("network: no ifcfg file for %s", devname)
        rv.append(devname)

    return rv
Beispiel #59
0
def dumpMissingDefaultIfcfgs():
    """
    Dump missing default ifcfg file for wired devices.
    Returns list of devices for which ifcfg file was dumped.
    """
    rv = []

    for devname in nm.nm_devices():
        if not nm.nm_device_type_is_ethernet(devname):
            continue

        try:
            con_uuid = nm.nm_device_setting_value(devname, "connection",
                                                  "uuid")
        except nm.SettingsNotFoundError:
            if find_ifcfg_file_of_device(devname):
                continue
            from pyanaconda.kickstart import AnacondaKSHandler
            handler = AnacondaKSHandler()
            network_data = handler.NetworkData(onboot=False, ipv6="auto")
            add_connection_for_ksdata(network_data, devname)
            rv.append(devname)

    return rv
Beispiel #60
0
    def setup(self, storage, ksdata, instclass):
        """
        The setup method that should make changes to the runtime environment
        according to the data stored in this object.

        :param storage: object storing storage-related information
                        (disks, partitioning, bootloader, etc.)
        :type storage: blivet.Blivet instance
        :param ksdata: data parsed from the kickstart file and set in the
                       installation process
        :type ksdata: pykickstart.base.BaseHandler instance
        :param instclass: distribution-specific information
        :type instclass: pyanaconda.installclass.BaseInstallClass
        """

        log = logging.getLogger("anaconda")
        log.info("ROCKS KS SETUP: %s" % ksdata.__str__())

        ## At this point rolls have been selected, the in-memory rocks database
        ## is set up and cluster information has been added by the user. now
        ## need to
        ##   A. add the attributes from ksdata.addons.org_rocks_rolls.info
        ##      into the in-memory database
        ##   B. rolls are in  ksdata.addons.org_rocks_rolls.rolls
        ##      process the xml files for the rolls specified, then generate
        ##      packages

        ## We don't have "rolls" if we are a clientInstall
        if self.clientInstall or ksdata.addons.org_rocks_rolls.info is None:
            return
        for row in ksdata.addons.org_rocks_rolls.info:
            log.info("ROCKS ADD ATTR %s=%s" % (row[2], row[1]))
            self.addAttr(row[2], row[1])
        cmd = ["/opt/rocks/bin/rocks", "report", "host", "attr", "pydict=true"]
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
        attrs = p.stdout.readlines()[0].strip()

        f = open("/tmp/site.attrs", "w")
        atdict = eval(attrs)
        for key in atdict.keys():
            f.write("%s:%s\n" % (key, atdict[key]))
        f.close()

        ## Write out all of the Ethernet devices so that we can load
        ## Load into the installed FE database. See database-data.xm
        etherifs = filter(lambda x: nm.nm_device_type_is_ethernet(x),\
           nm.nm_devices())
        ethermacs = map(lambda x: nm.nm_device_valid_hwaddress(x), etherifs)
        g = open("/tmp/frontend-ifaces.sh", "w")
        g.write("/opt/rocks/bin/rocks config host interface localhost iface='%s' mac='%s' flag='' module=''\n" % \
            (",".join(etherifs),",".join(ethermacs)))
        g.close()

        cmd = ["/opt/rocks/bin/rocks","list","node", "xml", \
           "attrs=%s" % attrs, "basedir=/tmp/rocks/export/profile", "server"]
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
        nodexml = p.stdout.readlines()

        cmd = ["/opt/rocks/sbin/kgen", "--section=packages"]
        p = subprocess.Popen(cmd,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE)
        out, err = p.communicate(input="".join(nodexml))
        pkgs = filter(lambda x: len(x) > 0, out.split("\n"))

        for pkg in pkgs:
            if "%" in pkg or "#" in pkg:
                continue
            if not pkg in ksdata.packages.packageList:
                ksdata.packages.packageList.append(pkg)

        ## Generate the post scripts section
        log.info("ROCKS GENERATING POST SCRIPTS")
        cmd = ["/opt/rocks/sbin/kgen", "--section=post"]
        p = subprocess.Popen(cmd,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE)
        self.postscripts, err = p.communicate(input="".join(nodexml))
        log.info("ROCKS POST SCRIPTS GENERATED")

        ksparser = kickstart.AnacondaKSParser(ksdata)
        ksparser.readKickstartFromString(self.postscripts, reset=False)

        ## Add eula and firstboot stanzas
        log.info("ROCKS FIRSTBOOT/EULA")
        ksparser = kickstart.AnacondaKSParser(ksdata)
        ksparser.readKickstartFromString("eula --agreed", reset=False)
        ksparser.readKickstartFromString("firstboot --disable", reset=False)
        log.info("ROCKS FIRSBOOT/EULA END ")