コード例 #1
0
def validate_mountpoint(mountpoint, used_mountpoints, strict=True):
    if strict:
        fake_mountpoints = []
    else:
        fake_mountpoints = ["swap", "biosboot", "prepboot"]

    if mountpoint in used_mountpoints:
        return _("That mount point is already in use. Try something else?")
    elif not mountpoint:
        return _("Please enter a valid mount point.")
    elif mountpoint in system_mountpoints:
        return _("That mount point is invalid. Try something else?")
    elif (lowerASCII(mountpoint) not in fake_mountpoints and
          ((len(mountpoint) > 1 and mountpoint.endswith("/")) or
           not mountpoint.startswith("/") or
           " " in mountpoint or
           re.search(r'/\.*/', mountpoint) or
           re.search(r'/\.+$', mountpoint))):
        # - does not end with '/' unless mountpoint _is_ '/'
        # - starts with '/' except for "swap", &c
        # - does not contain spaces
        # - does not contain pairs of '/' enclosing zero or more '.'
        # - does not end with '/' followed by one or more '.'
        return _("That mount point is invalid. Try something else?")
    else:
        return ""
コード例 #2
0
ファイル: iutil_test.py プロジェクト: tuan-hoang1/anaconda
 def lower_ascii_test(self):
     """Test lowerASCII."""
     self.assertEqual(util.lowerASCII(""), "")
     self.assertEqual(util.lowerASCII("A"), "a")
     self.assertEqual(util.lowerASCII("a"), "a")
     self.assertEqual(util.lowerASCII("aBc"), "abc")
     self.assertEqual(util.lowerASCII("_&*'@#$%^aBcžčŘ"), "_&*'@#$%^abczcr")
     _out = "heizolruckstoabdampfung"
     self.assertEqual(util.lowerASCII("Heizölrückstoßabdämpfung"), _out)
コード例 #3
0
    def _check_image_sum(self, image_path, checksum):
        self.report_progress("Checking image checksum")
        sha256 = hashlib.sha256()
        with open(image_path, "rb") as f:
            while True:
                data = f.read(1024 * 1024)
                if not data:
                    break
                sha256.update(data)
        filesum = sha256.hexdigest()
        log.debug("sha256 of %s is %s", image_path, filesum)

        if lowerASCII(checksum) != filesum:
            log.error("%s does not match checksum of %s.", checksum, image_path)
            raise SourceSetupError("Checksum of image {} does not match".format(image_path))
コード例 #4
0
ファイル: queuefactory.py プロジェクト: wathsalav/anaconda
    def addMessage(self, name, argc):
        if name in self.__names:
            raise AttributeError("%s queue already has a message named %s" % (self.name, name))

        # Add a constant.
        const_name = upperASCII(self.name) + "_CODE_" + upperASCII(name)
        setattr(self, const_name, self.__counter)
        self.__counter += 1

        # Add a convenience method for putting things into the queue.
        method_name = "send_" + lowerASCII(name)
        method = self._makeMethod(getattr(self, const_name), method_name, argc)
        setattr(self, method_name, method)

        self.__names.append(name)
コード例 #5
0
 def test_lower_ascii(self):
     """Test lowerASCII."""
     assert util.lowerASCII("") == ""
     assert util.lowerASCII("A") == "a"
     assert util.lowerASCII("a") == "a"
     assert util.lowerASCII("aBc") == "abc"
     assert util.lowerASCII("_&*'@#$%^aBcžčŘ") == \
         "_&*'@#$%^abczcr"
     _out = "heizolruckstoabdampfung"
     assert util.lowerASCII("Heizölrückstoßabdämpfung") == _out
コード例 #6
0
ファイル: iutil_test.py プロジェクト: rvykydal/anaconda
 def lower_ascii_test(self):
     """Test lowerASCII."""
     self.assertEqual(util.lowerASCII(""), "")
     self.assertEqual(util.lowerASCII("A"), "a")
     self.assertEqual(util.lowerASCII("a"), "a")
     self.assertEqual(util.lowerASCII("aBc"), "abc")
     self.assertEqual(util.lowerASCII("_&*'@#$%^aBcžčŘ"),
                      "_&*'@#$%^abczcr")
     _out = "heizolruckstoabdampfung"
     self.assertEqual(util.lowerASCII("Heizölrückstoßabdämpfung"), _out)
コード例 #7
0
    def on_add_confirm_clicked(self, button, *args):
        self.mount_point = self.builder.get_object("addMountPointEntry").get_active_text()

        if lowerASCII(self.mount_point) in ("swap", "biosboot", "prepboot"):
            self._error = None
        else:
            self._error = validate_mount_point(self.mount_point, self.mount_points)

        self._warningLabel.set_text(self._error or "")
        self.window.show_all()
        if self._error:
            return

        self.size = get_size_from_entry(
            self.builder.get_object("addSizeEntry"),
            lower_bound=self.MIN_SIZE_ENTRY,
            units=SIZE_UNITS_DEFAULT
        )
        self.window.destroy()
コード例 #8
0
ファイル: livepayload.py プロジェクト: pp1992m/anaconda
    def preInstall(self):
        """ Get image and loopback mount it.

            This is called after partitioning is setup, we now have space to
            grab the image. If it is a network source Download it to sysroot
            and provide feedback during the download (using urlgrabber
            callback).

            If it is a file:// source then use the file directly.
        """
        error = None
        if self.data.method.url.startswith("file://"):
            self.image_path = self.data.method.url[7:]
        else:
            error = self._preInstall_url_image()

        if error:
            exn = PayloadInstallError(str(error))
            if errorHandler.cb(exn) == ERROR_RAISE:
                raise exn

        # Used to make install progress % look correct
        self._adj_size = os.stat(self.image_path)[stat.ST_SIZE]

        if self.data.method.checksum:
            progressQ.send_message(_("Checking image checksum"))
            sha256 = hashlib.sha256()
            with open(self.image_path, "rb") as f:
                while True:
                    data = f.read(1024 * 1024)
                    if not data:
                        break
                    sha256.update(data)
            filesum = sha256.hexdigest()
            log.debug("sha256 of %s is %s", self.data.method.url, filesum)

            if util.lowerASCII(self.data.method.checksum) != filesum:
                log.error("%s does not match checksum.",
                          self.data.method.checksum)
                exn = PayloadInstallError("Checksum of image does not match")
                if errorHandler.cb(exn) == ERROR_RAISE:
                    raise exn

        # If this looks like a tarfile, skip trying to mount it
        if self.is_tarfile:
            return

        # Mount the image and check to see if it is a LiveOS/*.img
        # style squashfs image. If so, move it to IMAGE_DIR and mount the real
        # root image on INSTALL_TREE
        rc = blivet.util.mount(self.image_path,
                               INSTALL_TREE,
                               fstype="auto",
                               options="ro")
        if rc != 0:
            log.error("mount error (%s) with %s", rc, self.image_path)
            exn = PayloadInstallError("mount error %s" % rc)
            if errorHandler.cb(exn) == ERROR_RAISE:
                raise exn

        # Nothing more to mount
        if not os.path.exists(INSTALL_TREE + "/LiveOS"):
            self._updateKernelVersionList()
            return

        # Mount the first .img in the directory on INSTALL_TREE
        img_files = glob.glob(INSTALL_TREE + "/LiveOS/*.img")
        if img_files:
            # move the mount to IMAGE_DIR
            os.makedirs(IMAGE_DIR, 0o755)
            # work around inability to move shared filesystems
            rc = util.execWithRedirect("mount", ["--make-rprivate", "/"])
            if rc == 0:
                rc = util.execWithRedirect("mount",
                                           ["--move", INSTALL_TREE, IMAGE_DIR])
            if rc != 0:
                log.error("error %s moving mount", rc)
                exn = PayloadInstallError("mount error %s" % rc)
                if errorHandler.cb(exn) == ERROR_RAISE:
                    raise exn

            img_file = IMAGE_DIR + "/LiveOS/" + os.path.basename(
                sorted(img_files)[0])
            rc = blivet.util.mount(img_file,
                                   INSTALL_TREE,
                                   fstype="auto",
                                   options="ro")
            if rc != 0:
                log.error("mount error (%s) with %s", rc, img_file)
                exn = PayloadInstallError("mount error %s with %s" %
                                          (rc, img_file))
                if errorHandler.cb(exn) == ERROR_RAISE:
                    raise exn

            self._updateKernelVersionList()

            source = os.statvfs(INSTALL_TREE)
            self.source_size = source.f_frsize * (source.f_blocks -
                                                  source.f_bfree)
コード例 #9
0
def get_kickstart_network_data(ifcfg,
                               nm_client,
                               network_data_class,
                               root_path=""):
    """Get kickstart data from ifcfg object.

    :param ifcfg: ifcfg file object
    :type ifcfg: IfcfgFile
    :param nm_client: instance of NetworkManager client
    :type nm_client: NM.Client
    :param network_data_class: pykickstart network command data class
    :type: pykickstart BaseData
    :param root_path: optional root path for ifcfg files to be updated
    :type root_path: str
    :returns: network_data object corresponding to the ifcfg object
    :rtype: network_data_class object instance
    """
    ifcfg.read()
    kwargs = {}

    # no network command for non-virtual device slaves
    if ifcfg.get("TYPE") not in ("Bond",
                                 "Team") and ifcfg.get("DEVICETYPE") != "Team":
        if ifcfg.get("MASTER") or ifcfg.get("TEAM_MASTER") or ifcfg.get(
                "BRIDGE"):
            return None

    # no support for wireless
    if ifcfg.get("TYPE") == "Wireless":
        return None

    # ipv4 and ipv6
    if ifcfg.get("ONBOOT") and ifcfg.get("ONBOOT") == "no":
        kwargs["onboot"] = False
    if ifcfg.get('MTU') and ifcfg.get('MTU') != "0":
        kwargs["mtu"] = ifcfg.get('MTU')
    # ipv4
    if not ifcfg.get('BOOTPROTO'):
        kwargs["noipv4"] = True
    else:
        if util.lowerASCII(ifcfg.get('BOOTPROTO')) == 'dhcp':
            kwargs["bootProto"] = "dhcp"
            if ifcfg.get('DHCPCLASS'):
                kwargs["dhcpclass"] = ifcfg.get('DHCPCLASS')
        elif ifcfg.get('IPADDR'):
            kwargs["bootProto"] = "static"
            kwargs["ip"] = ifcfg.get('IPADDR')
            netmask = ifcfg.get('NETMASK')
            prefix = ifcfg.get('PREFIX')
            if not netmask and prefix:
                netmask = prefix2netmask(int(prefix))
            if netmask:
                kwargs["netmask"] = netmask
            # note that --gateway is common for ipv4 and ipv6
            if ifcfg.get('GATEWAY'):
                kwargs["gateway"] = ifcfg.get('GATEWAY')
        elif ifcfg.get('IPADDR0'):
            kwargs["bootProto"] = "static"
            kwargs["ip"] = ifcfg.get('IPADDR0')
            prefix = ifcfg.get('PREFIX0')
            if prefix:
                netmask = prefix2netmask(int(prefix))
                kwargs["netmask"] = netmask
            # note that --gateway is common for ipv4 and ipv6
            if ifcfg.get('GATEWAY0'):
                kwargs["gateway"] = ifcfg.get('GATEWAY0')

    # ipv6
    if not ifcfg.get('IPV6INIT') or ifcfg.get('IPV6INIT') == "no":
        kwargs["noipv6"] = True
    else:
        if ifcfg.get('IPV6_AUTOCONF') in ("yes", ""):
            kwargs["ipv6"] = "auto"
        else:
            if ifcfg.get('IPV6ADDR'):
                kwargs["ipv6"] = ifcfg.get('IPV6ADDR')
                if ifcfg.get('IPV6_DEFAULTGW') \
                        and ifcfg.get('IPV6_DEFAULTGW') != "::":
                    kwargs["ipv6gateway"] = ifcfg.get('IPV6_DEFAULTGW')
            if ifcfg.get('DHCPV6C') == "yes":
                kwargs["ipv6"] = "dhcp"

    # ipv4 and ipv6
    dnsline = ''
    for key in ifcfg.info.keys():
        if util.upperASCII(key).startswith('DNS'):
            if dnsline == '':
                dnsline = ifcfg.get(key)
            else:
                dnsline += "," + ifcfg.get(key)
    if dnsline:
        kwargs["nameserver"] = dnsline

    if ifcfg.get("ETHTOOL_OPTS"):
        kwargs["ethtool"] = ifcfg.get("ETHTOOL_OPTS")

    if ifcfg.get("ESSID"):
        kwargs["essid"] = ifcfg.get("ESSID")

    # hostname
    if ifcfg.get("DHCP_HOSTNAME"):
        kwargs["hostname"] = ifcfg.get("DHCP_HOSTNAME")

    iface = ifcfg.get("DEVICE")
    if not iface:
        hwaddr = ifcfg.get("HWADDR")
        if hwaddr:
            iface = get_iface_from_hwaddr(nm_client, hwaddr)
    if iface:
        kwargs["device"] = iface

    # bonding
    # FIXME: dracut has only BOND_OPTS
    if ifcfg.get("BONDING_MASTER") == "yes" or ifcfg.get("TYPE") == "Bond":
        slaves = sorted(
            get_slaves_from_ifcfgs(
                nm_client,
                "MASTER",
                [ifcfg.get("DEVICE"), ifcfg.get("UUID")],
                root_path=root_path))
        if slaves:
            kwargs["bondslaves"] = ",".join(iface for iface, uuid in slaves)
        bondopts = ifcfg.get("BONDING_OPTS")
        if bondopts:
            sep = ","
            if sep in bondopts:
                sep = ";"
            kwargs["bondopts"] = sep.join(bondopts.split())

    # vlan
    if ifcfg.get("VLAN") == "yes" or ifcfg.get("TYPE") == "Vlan":
        physdev = ifcfg.get("PHYSDEV")
        if len(physdev) == NM_CONNECTION_UUID_LENGTH:
            physdev = get_iface_from_connection(nm_client, physdev)
        kwargs["device"] = physdev
        kwargs["vlanid"] = ifcfg.get("VLAN_ID")
        interface_name = ifcfg.get("DEVICE")
        default_name = default_ks_vlan_interface_name(kwargs["device"],
                                                      kwargs["vlanid"])
        if interface_name and interface_name != default_name:
            kwargs["interfacename"] = interface_name

    # bridging
    if ifcfg.get("TYPE") == "Bridge":
        slaves = sorted(
            get_slaves_from_ifcfgs(
                nm_client,
                "BRIDGE",
                [ifcfg.get("DEVICE"), ifcfg.get("UUID")],
                root_path=root_path))
        if slaves:
            kwargs["bridgeslaves"] = ",".join(iface for iface, uuid in slaves)

        bridgeopts = ifcfg.get("BRIDGING_OPTS").replace('_', '-').split()
        if ifcfg.get("STP"):
            bridgeopts.append("%s=%s" % ("stp", ifcfg.get("STP")))
        if ifcfg.get("DELAY"):
            bridgeopts.append("%s=%s" % ("forward-delay", ifcfg.get("DELAY")))
        if bridgeopts:
            kwargs["bridgeopts"] = ",".join(bridgeopts)

    nd = network_data_class(**kwargs)

    # teaming
    if ifcfg.get("TYPE") == "Team" or ifcfg.get("DEVICETYPE") == "Team":
        slaves = sorted(
            get_slaves_from_ifcfgs(
                nm_client,
                "TEAM_MASTER",
                [ifcfg.get("DEVICE"), ifcfg.get("UUID")],
                root_path=root_path))
        for iface, uuid in slaves:
            team_port_cfg = get_team_port_config_from_connection(
                nm_client, uuid)
            nd.teamslaves.append((iface, team_port_cfg))
        teamconfig = get_team_config_from_connection(nm_client,
                                                     ifcfg.get("UUID"))
        if teamconfig:
            nd.teamconfig = teamconfig
    return nd
コード例 #10
0
ファイル: livepayload.py プロジェクト: rvykydal/anaconda
    def pre_install(self):
        """ Get image and loopback mount it.

            This is called after partitioning is setup, we now have space to
            grab the image. If it is a network source Download it to sysroot
            and provide feedback during the download (using urlgrabber
            callback).

            If it is a file:// source then use the file directly.
        """
        error = None
        if self.data.method.url.startswith("file://"):
            self.image_path = self.data.method.url[7:]
        else:
            error = self._pre_install_url_image()

        if error:
            exn = PayloadInstallError(str(error))
            if errorHandler.cb(exn) == ERROR_RAISE:
                raise exn

        # Used to make install progress % look correct
        self._adj_size = os.stat(self.image_path)[stat.ST_SIZE]

        if self.data.method.checksum:
            progressQ.send_message(_("Checking image checksum"))
            sha256 = hashlib.sha256()
            with open(self.image_path, "rb") as f:
                while True:
                    data = f.read(1024 * 1024)
                    if not data:
                        break
                    sha256.update(data)
            filesum = sha256.hexdigest()
            log.debug("sha256 of %s is %s", self.data.method.url, filesum)

            if util.lowerASCII(self.data.method.checksum) != filesum:
                log.error("%s does not match checksum.", self.data.method.checksum)
                exn = PayloadInstallError("Checksum of image does not match")
                if errorHandler.cb(exn) == ERROR_RAISE:
                    raise exn

        # If this looks like a tarfile, skip trying to mount it
        if self.is_tarfile:
            return

        # Mount the image and check to see if it is a LiveOS/*.img
        # style squashfs image. If so, move it to IMAGE_DIR and mount the real
        # root image on INSTALL_TREE
        rc = payload_utils.mount(self.image_path, INSTALL_TREE, fstype="auto", options="ro")
        if rc != 0:
            log.error("mount error (%s) with %s", rc, self.image_path)
            exn = PayloadInstallError("mount error %s" % rc)
            if errorHandler.cb(exn) == ERROR_RAISE:
                raise exn

        # Nothing more to mount
        if not os.path.exists(INSTALL_TREE + "/LiveOS"):
            self._update_kernel_version_list()
            return

        # Mount the first .img in the directory on INSTALL_TREE
        img_files = glob.glob(INSTALL_TREE + "/LiveOS/*.img")
        if img_files:
            # move the mount to IMAGE_DIR
            os.makedirs(IMAGE_DIR, 0o755)
            # work around inability to move shared filesystems
            rc = util.execWithRedirect("mount",
                                       ["--make-rprivate", "/"])
            if rc == 0:
                rc = util.execWithRedirect("mount",
                                           ["--move", INSTALL_TREE, IMAGE_DIR])
            if rc != 0:
                log.error("error %s moving mount", rc)
                exn = PayloadInstallError("mount error %s" % rc)
                if errorHandler.cb(exn) == ERROR_RAISE:
                    raise exn

            img_file = IMAGE_DIR+"/LiveOS/" + os.path.basename(sorted(img_files)[0])
            rc = payload_utils.mount(img_file, INSTALL_TREE, fstype="auto", options="ro")
            if rc != 0:
                log.error("mount error (%s) with %s", rc, img_file)
                exn = PayloadInstallError("mount error %s with %s" % (rc, img_file))
                if errorHandler.cb(exn) == ERROR_RAISE:
                    raise exn

            self._update_kernel_version_list()

            source = os.statvfs(INSTALL_TREE)
            self.source_size = source.f_frsize * (source.f_blocks - source.f_bfree)
コード例 #11
0
ファイル: ifcfg.py プロジェクト: ptalbert/anaconda
def get_dracut_arguments_from_ifcfg(nm_client, 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 nm_client: instance of NetworkManager client
    :type nm_client: NM.Client
    :param ifcfg: ifcfg file object
    :type ifcfg: IfcfgFile
    :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
    :returns: dracut arguments
    :rtype: set(str)
    """
    netargs = set()

    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(nm_client, "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) == NM_CONNECTION_UUID_LENGTH:
                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(nm_client, 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
コード例 #12
0
ファイル: ifcfg.py プロジェクト: rvykydal/anaconda
def get_dracut_arguments_from_ifcfg(nm_client, 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 nm_client: instance of NetworkManager client
    :type nm_client: NM.Client
    :param ifcfg: ifcfg file object
    :type ifcfg: IfcfgFile
    :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
    :returns: dracut arguments
    :rtype: set(str)
    """
    netargs = set()

    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 = sorted(get_slaves_from_ifcfgs(nm_client, "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) == NM_CONNECTION_UUID_LENGTH:
                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(nm_client, 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
コード例 #13
0
ファイル: ifcfg.py プロジェクト: rvykydal/anaconda
def get_kickstart_network_data(ifcfg, nm_client, network_data_class, root_path=""):
    """Get kickstart data from ifcfg object.

    :param ifcfg: ifcfg file object
    :type ifcfg: IfcfgFile
    :param nm_client: instance of NetworkManager client
    :type nm_client: NM.Client
    :param network_data_class: pykickstart network command data class
    :type: pykickstart BaseData
    :param root_path: optional root path for ifcfg files to be updated
    :type root_path: str
    :returns: network_data object corresponding to the ifcfg object
    :rtype: network_data_class object instance
    """
    ifcfg.read()
    kwargs = {}

    # no network command for non-virtual device slaves
    if ifcfg.get("TYPE") not in ("Bond", "Team") and ifcfg.get("DEVICETYPE") != "Team":
        if ifcfg.get("MASTER") or ifcfg.get("TEAM_MASTER") or ifcfg.get("BRIDGE"):
            return None

    # no support for wireless
    if ifcfg.get("TYPE") == "Wireless":
        return None

    # ipv4 and ipv6
    if ifcfg.get("ONBOOT") and ifcfg.get("ONBOOT") == "no":
        kwargs["onboot"] = False
    if ifcfg.get('MTU') and ifcfg.get('MTU') != "0":
        kwargs["mtu"] = ifcfg.get('MTU')
    # ipv4
    if not ifcfg.get('BOOTPROTO'):
        kwargs["noipv4"] = True
    else:
        if util.lowerASCII(ifcfg.get('BOOTPROTO')) == 'dhcp':
            kwargs["bootProto"] = "dhcp"
            if ifcfg.get('DHCPCLASS'):
                kwargs["dhcpclass"] = ifcfg.get('DHCPCLASS')
        elif ifcfg.get('IPADDR'):
            kwargs["bootProto"] = "static"
            kwargs["ip"] = ifcfg.get('IPADDR')
            netmask = ifcfg.get('NETMASK')
            prefix = ifcfg.get('PREFIX')
            if not netmask and prefix:
                netmask = prefix2netmask(int(prefix))
            if netmask:
                kwargs["netmask"] = netmask
            # note that --gateway is common for ipv4 and ipv6
            if ifcfg.get('GATEWAY'):
                kwargs["gateway"] = ifcfg.get('GATEWAY')
        elif ifcfg.get('IPADDR0'):
            kwargs["bootProto"] = "static"
            kwargs["ip"] = ifcfg.get('IPADDR0')
            prefix = ifcfg.get('PREFIX0')
            if prefix:
                netmask = prefix2netmask(int(prefix))
                kwargs["netmask"] = netmask
            # note that --gateway is common for ipv4 and ipv6
            if ifcfg.get('GATEWAY0'):
                kwargs["gateway"] = ifcfg.get('GATEWAY0')

    # ipv6
    if not ifcfg.get('IPV6INIT') or ifcfg.get('IPV6INIT') == "no":
        kwargs["noipv6"] = True
    else:
        if ifcfg.get('IPV6_AUTOCONF') in ("yes", ""):
            kwargs["ipv6"] = "auto"
        else:
            if ifcfg.get('IPV6ADDR'):
                kwargs["ipv6"] = ifcfg.get('IPV6ADDR')
                if ifcfg.get('IPV6_DEFAULTGW') \
                        and ifcfg.get('IPV6_DEFAULTGW') != "::":
                    kwargs["ipv6gateway"] = ifcfg.get('IPV6_DEFAULTGW')
            if ifcfg.get('DHCPV6C') == "yes":
                kwargs["ipv6"] = "dhcp"

    # ipv4 and ipv6
    dnsline = ''
    for key in ifcfg.info.keys():
        if util.upperASCII(key).startswith('DNS'):
            if dnsline == '':
                dnsline = ifcfg.get(key)
            else:
                dnsline += "," + ifcfg.get(key)
    if dnsline:
        kwargs["nameserver"] = dnsline

    if ifcfg.get("ETHTOOL_OPTS"):
        kwargs["ethtool"] = ifcfg.get("ETHTOOL_OPTS")

    if ifcfg.get("ESSID"):
        kwargs["essid"] = ifcfg.get("ESSID")

    # hostname
    if ifcfg.get("DHCP_HOSTNAME"):
        kwargs["hostname"] = ifcfg.get("DHCP_HOSTNAME")

    iface = ifcfg.get("DEVICE")
    if not iface:
        hwaddr = ifcfg.get("HWADDR")
        if hwaddr:
            iface = get_iface_from_hwaddr(nm_client, hwaddr)
    if iface:
        kwargs["device"] = iface

    # bonding
    # FIXME: dracut has only BOND_OPTS
    if ifcfg.get("BONDING_MASTER") == "yes" or ifcfg.get("TYPE") == "Bond":
        slaves = sorted(get_slaves_from_ifcfgs(nm_client,
                                               "MASTER",
                                               [ifcfg.get("DEVICE"), ifcfg.get("UUID")],
                                               root_path=root_path))
        if slaves:
            kwargs["bondslaves"] = ",".join(iface for iface, uuid in slaves)
        bondopts = ifcfg.get("BONDING_OPTS")
        if bondopts:
            sep = ","
            if sep in bondopts:
                sep = ";"
            kwargs["bondopts"] = sep.join(bondopts.split())

    # vlan
    if ifcfg.get("VLAN") == "yes" or ifcfg.get("TYPE") == "Vlan":
        physdev = ifcfg.get("PHYSDEV")
        if len(physdev) == NM_CONNECTION_UUID_LENGTH:
            physdev = get_iface_from_connection(nm_client, physdev)
        kwargs["device"] = physdev
        kwargs["vlanid"] = ifcfg.get("VLAN_ID")
        interface_name = ifcfg.get("DEVICE")
        if interface_name and interface_name != default_ks_vlan_interface_name(kwargs["device"], kwargs["vlanid"]):
            kwargs["interfacename"] = interface_name

    # bridging
    if ifcfg.get("TYPE") == "Bridge":
        slaves = sorted(get_slaves_from_ifcfgs(nm_client,
                                               "BRIDGE",
                                               [ifcfg.get("DEVICE"), ifcfg.get("UUID")],
                                               root_path=root_path))
        if slaves:
            kwargs["bridgeslaves"] = ",".join(iface for iface, uuid in slaves)

        bridgeopts = ifcfg.get("BRIDGING_OPTS").replace('_', '-').split()
        if ifcfg.get("STP"):
            bridgeopts.append("%s=%s" % ("stp", ifcfg.get("STP")))
        if ifcfg.get("DELAY"):
            bridgeopts.append("%s=%s" % ("forward-delay", ifcfg.get("DELAY")))
        if bridgeopts:
            kwargs["bridgeopts"] = ",".join(bridgeopts)

    nd = network_data_class(**kwargs)

    # teaming
    if ifcfg.get("TYPE") == "Team" or ifcfg.get("DEVICETYPE") == "Team":
        slaves = sorted(get_slaves_from_ifcfgs(nm_client,
                                               "TEAM_MASTER",
                                               [ifcfg.get("DEVICE"), ifcfg.get("UUID")],
                                               root_path=root_path))
        for iface, uuid in slaves:
            team_port_cfg = get_team_port_config_from_connection(nm_client, uuid)
            nd.teamslaves.append((iface, team_port_cfg))
        teamconfig = get_team_config_from_connection(nm_client, ifcfg.get("UUID"))
        if teamconfig:
            nd.teamconfig = teamconfig
    return nd
コード例 #14
0
ファイル: installation.py プロジェクト: kkang-wr/anaconda
 def _normalize_checksum(checksum):
     """Normalize the given checksum."""
     return lowerASCII(checksum)