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)
Beispiel #2
0
    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)
Beispiel #3
0
    def _parseline(self, line):
        """ parse a line into a key, value and comment

            :param str line: Line to be parsed
            :returns: Tuple of key, value, comment
            :rtype: tuple

            Handle comments and optionally unquote quoted strings
            Returns (key, value, comment) or (None, None, comment)
            key is always UPPERCASE and comment may by "" if none was found.
        """
        s = line.strip()
        # Look for a # outside any quotes
        comment = ""
        comment_index = find_comment(s)
        if comment_index is not None:
            comment = s[comment_index:]
            s = s[:comment_index]   # remove from comment to EOL

        key, eq, val = s.partition('=')
        key = key.strip()
        val = val.strip()
        if self.read_unquote:
            val = unquote(val)
        if key != '' and eq == '=':
            return (upperASCII(key), val, comment)
        else:
            return (None, None, comment)
Beispiel #4
0
    def _parseline(self, line):
        """ parse a line into a key, value and comment

            :param str line: Line to be parsed
            :returns: Tuple of key, value, comment
            :rtype: tuple

            Handle comments and optionally unquote quoted strings
            Returns (key, value, comment) or (None, None, comment)
            key is always UPPERCASE and comment may by "" if none was found.
        """
        s = line.strip()
        # Look for a # outside any quotes
        comment = ""
        comment_index = find_comment(s)
        if comment_index is not None:
            comment = s[comment_index:]
            s = s[:comment_index]  # remove from comment to EOL

        key, eq, val = s.partition('=')
        key = key.strip()
        val = val.strip()
        if self.read_unquote:
            val = unquote(val)
        if key != '' and eq == '=':
            return (upperASCII(key), val, comment)
        else:
            return (None, None, comment)
    def upper_ascii_test(self):
        """Test upperASCII."""

        self.assertEqual(iutil.upperASCII(""), "")
        self.assertEqual(iutil.upperASCII("a"), "A")
        self.assertEqual(iutil.upperASCII("A"), "A")
        self.assertEqual(iutil.upperASCII("aBc"), "ABC")
        self.assertEqual(iutil.upperASCII("_&*'@#$%^aBcžčŘ"), "_&*'@#$%^ABCZCR")
        _out = "HEIZOLRUCKSTOABDAMPFUNG"
        self.assertEqual(iutil.upperASCII("Heizölrückstoßabdämpfung"), _out)
Beispiel #6
0
    def upper_ascii_test(self):
        """Test upperASCII."""

        self.assertEqual(iutil.upperASCII(""),"")
        self.assertEqual(iutil.upperASCII("a"),"A")
        self.assertEqual(iutil.upperASCII("A"),"A")
        self.assertEqual(iutil.upperASCII("aBc"),"ABC")
        self.assertEqual(iutil.upperASCII("_&*'@#$%^aBcžčŘ"),
                                          "_&*'@#$%^ABC\xc5\xbe\xc4\x8d\xc5\x98")
        _out = "HEIZ\xc3\xb6LR\xc3\xbcCKSTO\xc3\x9fABD\xc3\xa4MPFUNG"
        self.assertEqual(iutil.upperASCII("Heizölrückstoßabdämpfung"), _out)
Beispiel #7
0
    def upper_ascii_test(self):
        """Test upperASCII."""

        self.assertEqual(iutil.upperASCII(""),"")
        self.assertEqual(iutil.upperASCII("a"),"A")
        self.assertEqual(iutil.upperASCII("A"),"A")
        self.assertEqual(iutil.upperASCII("aBc"),"ABC")
        self.assertEqual(iutil.upperASCII("_&*'@#$%^aBcžčŘ"),
                                          "_&*'@#$%^ABC\xc5\xbe\xc4\x8d\xc5\x98")
        _out = "HEIZ\xc3\xb6LR\xc3\xbcCKSTO\xc3\x9fABD\xc3\xa4MPFUNG"
        self.assertEqual(iutil.upperASCII("Heizölrückstoßabdämpfung"), _out)
Beispiel #8
0
    def upper_ascii_test(self):
        """Test upperASCII."""

        self.assertEqual(iutil.upperASCII(""), "")
        self.assertEqual(iutil.upperASCII("a"), "A")
        self.assertEqual(iutil.upperASCII("A"), "A")
        self.assertEqual(iutil.upperASCII("aBc"), "ABC")
        self.assertEqual(iutil.upperASCII("_&*'@#$%^aBcžčŘ"),
                         "_&*'@#$%^ABCZCR")
        _out = "HEIZOLRUCKSTOABDAMPFUNG"
        self.assertEqual(iutil.upperASCII("Heizölrückstoßabdämpfung"), _out)
Beispiel #9
0
 def _parseline(self, line):
     """ parse a line into a key, value pair
         Handle comments and optionally unquote quoted strings
         Returns (key, value) or (None, None)
         key is always UPPERCASE
     """
     s = line.strip()
     if '#' in s:
         s = s[:s.find('#')] # remove from comment to EOL
         s = s.strip()       # and any unnecessary whitespace
     key, eq, val = s.partition('=')
     if self.read_unquote:
         val = unquote(val)
     if key != '' and eq == '=':
         return (upperASCII(key), val)
     else:
         return (None, None)
Beispiel #10
0
def ifcfg_to_ksdata(ifcfg, devname):

    from pyanaconda.kickstart import AnacondaKSHandler
    handler = AnacondaKSHandler()
    kwargs = {}

    # no network command for bond slaves
    if ifcfg.get("MASTER"):
        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 iutil.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 iutil.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")

    # bonding
    # FIXME: dracut has only BOND_OPTS
    if ifcfg.get("BONDING_MASTER") == "yes" or ifcfg.get("TYPE") == "Bond":
        slaves = get_bond_slaves_from_ifcfgs([devname, ifcfg.get("UUID")])
        if slaves:
            kwargs["bondslaves"] = ",".join(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":
        kwargs["device"] = ifcfg.get("PHYSDEV")
        kwargs["vlanid"] = ifcfg.get("VLAN_ID")

    # pylint: disable-msg=E1101
    return handler.NetworkData(**kwargs)
def ifcfg_to_ksdata(ifcfg, devname):

    from pyanaconda.kickstart import AnacondaKSHandler
    handler = AnacondaKSHandler()
    kwargs = {}

    # no network command for bond slaves
    if ifcfg.get("MASTER"):
        return None
    # no network command for team slaves
    if ifcfg.get("TEAM_MASTER"):
        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 iutil.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 iutil.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")

    # bonding
    # FIXME: dracut has only BOND_OPTS
    if ifcfg.get("BONDING_MASTER") == "yes" or ifcfg.get("TYPE") == "Bond":
        slaves = get_bond_slaves_from_ifcfgs([devname, ifcfg.get("UUID")])
        if slaves:
            kwargs["bondslaves"] = ",".join(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":
        kwargs["device"] = ifcfg.get("PHYSDEV")
        kwargs["vlanid"] = ifcfg.get("VLAN_ID")

    # pylint: disable-msg=E1101
    nd = handler.NetworkData(**kwargs)

    # teaming
    if ifcfg.get("TYPE") == "Team" or ifcfg.get("DEVICETYPE") == "Team":
        slaves = get_team_slaves([devname, ifcfg.get("UUID")])
        for dev, cfg in slaves:
            nd.teamslaves.append((dev, cfg))

        teamconfig = nm.nm_device_setting_value(devname, "team", "config")
        if teamconfig:
            nd.teamconfig = teamconfig

    return nd
def ifcfg_to_ksdata(ifcfg, devname):

    from pyanaconda.kickstart import AnacondaKSHandler

    handler = AnacondaKSHandler()
    kwargs = {}

    # no network command for bond slaves
    if ifcfg.get("MASTER"):
        return None
    # no network command for team slaves
    if ifcfg.get("TEAM_MASTER"):
        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 iutil.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 iutil.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")

    # bonding
    # FIXME: dracut has only BOND_OPTS
    if ifcfg.get("BONDING_MASTER") == "yes" or ifcfg.get("TYPE") == "Bond":
        slaves = get_bond_slaves_from_ifcfgs([devname, ifcfg.get("UUID")])
        if slaves:
            kwargs["bondslaves"] = ",".join(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":
        kwargs["device"] = ifcfg.get("PHYSDEV")
        kwargs["vlanid"] = ifcfg.get("VLAN_ID")

    # pylint: disable-msg=E1101
    nd = handler.NetworkData(**kwargs)

    # teaming
    if ifcfg.get("TYPE") == "Team" or ifcfg.get("DEVICETYPE") == "Team":
        slaves = get_team_slaves([devname, ifcfg.get("UUID")])
        for dev, cfg in slaves:
            nd.teamslaves.append((dev, cfg))

        teamconfig = nm.nm_device_setting_value(devname, "team", "config")
        if teamconfig:
            nd.teamconfig = teamconfig

    return nd
Beispiel #13
0
 def set(self, *args):
     for key, value in args:
         self.info[upperASCII(key)] = value
Beispiel #14
0
 def get(self, key):
     return self.info.get(upperASCII(key), "")
Beispiel #15
0
 def unset(self, *keys):
     for key in (upperASCII(k) for k in keys):
         if key in self.info:
             del self.info[key]
Beispiel #16
0
 def set(self, *args):
     for key, value in args:
         self.info[upperASCII(key)] = value
Beispiel #17
0
 def get(self, key):
     return self.info.get(upperASCII(key), "")
Beispiel #18
0
 def unset(self, *keys):
     for key in (upperASCII(k) for k in keys):
         if key in self.info:
             del self.info[key]