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)
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(util.upperASCII(""), "") self.assertEqual(util.upperASCII("a"), "A") self.assertEqual(util.upperASCII("A"), "A") self.assertEqual(util.upperASCII("aBc"), "ABC") self.assertEqual(util.upperASCII("_&*'@#$%^aBcžčŘ"), "_&*'@#$%^ABCZCR") _out = "HEIZOLRUCKSTOABDAMPFUNG" self.assertEqual(util.upperASCII("Heizölrückstoßabdämpfung"), _out)
def test_upper_ascii(self): """Test upperASCII.""" assert util.upperASCII("") == "" assert util.upperASCII("a") == "A" assert util.upperASCII("A") == "A" assert util.upperASCII("aBc") == "ABC" assert util.upperASCII("_&*'@#$%^aBcžčŘ") == \ "_&*'@#$%^ABCZCR" _out = "HEIZOLRUCKSTOABDAMPFUNG" assert util.upperASCII("Heizölrückstoßabdämpfung") == _out
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
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
def get(self, key): return self.info.get(upperASCII(key), "")
def unset(self, *keys): for key in (upperASCII(k) for k in keys): if key in self.info: del self.info[key]
def set(self, *args): for key, value in args: self.info[upperASCII(key)] = value