import re
import copy
import crypt
+import os
+import ipaddress
# Third party modules
from pathlib import Path
from .xlate import XLATOR
-__version__ = '2.1.2'
+__version__ = '2.2.0'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
default_cobbler_rootdir = Path('/var/lib/cobbler')
default_cobbler_profile_repos = ['pp-centos8-baseos']
default_cobbler_nameservers = [
- '93.188.109.11',
+ '93.188.104.82',
'93.188.109.12',
- '93.188.109.13',
+ '217.66.52.10',
]
default_cobbler_dns_search = [
'pixelpark.net',
'pixelpark.com',
'pixelpark.de',
]
+ resolv_conf = Path('/etc/resolv.conf')
+ evaluated_resolv_conf = False
+
default_cobbler_ws_base_url = 'http://cobbler.pixelpark.com'
default_cobbler_ws_docroot = Path('/var/www/html')
default_cobbler_ws_rel_filesdir = Path('custom/vmware-template-files')
default_bind_dn = 'uid=readonly,ou=People,o=isp'
re_ldap_section_w_name = re.compile(r'^\s*ldap\s*:\s*(\S+)')
+ re_resolv_ns_entry = re.compile(r'^\s*nameserver\s+(\S+)')
# -------------------------------------------------------------------------
def __init__(
additional_config_file=None, additional_cfgdirs=None, encoding=DEFAULT_ENCODING,
ensure_privacy=False, use_chardet=True, initialized=False):
+ self.eval_resolv_conf()
+
add_stems = []
if additional_stems:
if is_sequence(additional_stems):
res['data_size_mb'] = self.data_size_mb
res['data_size_kb'] = self.data_size_kb
res['data_size'] = self.data_size
+ res['default_cobbler_nameservers'] = self.default_cobbler_nameservers
res['ram_gb'] = self.ram_gb
res['system_ks'] = self.system_ks
res['snippets_dir'] = self.snippets_dir
if not self.template_name_given:
self.template_name = self.current_distro.shortname + '-template'
+ # -------------------------------------------------------------------------
+ @classmethod
+ def eval_resolv_conf(cls):
+
+ if cls.evaluated_resolv_conf:
+ return True
+
+ if not cls.resolv_conf.exists():
+ LOG.error(_("File {!r} not found on current host.").format(str(cls.resolv_conf)))
+ cls.evaluated_resolv_conf = True
+ return False
+
+ if not cls.resolv_conf.is_file():
+ LOG.error(_("Path {!r} is not a regular file.").format(str(cls.resolv_conf)))
+ cls.evaluated_resolv_conf = True
+ return False
+
+ if not os.access(cls.resolv_conf, os.R_OK):
+ LOG.error(_("File {!r} is not readable.").format(str(cls.resolv_conf)))
+ cls.evaluated_resolv_conf = True
+ return False
+
+ LOG.info(_("Evaluating {!r} for nameservers.").format(str(ls.resolv_conf)))
+
+ nameservers = []
+ file_content = cls.resolv_conf.read_text()
+ lines = file_content.splitlines()
+
+ for line in lines:
+ match = cls.re_resolv_ns_entry.match(line)
+ if match:
+ try:
+ ns_address = ipaddress.ip_address(match.group(1))
+ nameservers.append(str(ns_address))
+ except ValueError as e:
+ msg = _("Found invalid IP address {addr!r} as a nameserver in {file!r}:")
+ msg = msg.format(addr=match.group(1), file=str(cls.resolv_conf))
+ msg += ' ' + str(e)
+ LOG.warn(msg)
+
+ cls.evaluated_resolv_conf = True
+ msg = _("Found nameservers in {!r}:").format(str(cls.resolv_conf))
+ msg += ' {}'.format(pp(nameservers))
+ LOG.debug(msg)
+
+ if len(nameservers):
+ cls.default_cobbler_nameservers = nameservers
+ return True
+
+ return False
+
# -------------------------------------------------------------------------
def verify_cobbler_distros(self):