Esempio n. 1
0
    def __init__(self, api=None):
        """
        Constructor

        :param api: The API to resolve information with.
        """
        if api is None:
            raise ValueError(
                "cobbler hardlink requires the Cobbler-API for resolving the root folders."
            )
        self.api = api
        self.hardlink = ""
        self.logger = logging.getLogger()
        self.family = utils.get_family()
        self.webdir = self.api.settings().webdir

        # Getting the path to hardlink
        for possible_location in ["/usr/bin/hardlink", "/usr/sbin/hardlink"]:
            if os.path.exists(possible_location):
                self.hardlink = possible_location
        if not self.hardlink:
            utils.die("please install 'hardlink' to use this feature")

        # Setting the args for hardlink according to the distribution. Must end with a space!
        if self.family == "debian":
            hardlink_args = "-f -p -o -t -v "
        elif self.family == "suse":
            hardlink_args = "-f -v "
        else:
            hardlink_args = "-c -v "
        self.hardlink_cmd = "%s %s %s/distro_mirror %s/repo_mirror" \
                            % (self.hardlink, hardlink_args, self.webdir, self.webdir)
Esempio n. 2
0
    def __init__(self, collection_mgr, logger=None):
        """
        Constructor
        """
        # self.collection_mgr   = collection_mgr
        # self.api      = collection_mgr.api
        # self.settings = collection_mgr.settings()
        self.hardlink = None
        if logger is None:
            logger = clogger.Logger()
        self.logger = logger
        self.family = utils.get_family()

        # Getting the path to hardlink
        for possible_location in ["/usr/bin/hardlink", "/usr/sbin/hardlink"]:
            if os.path.exists(possible_location):
                self.hardlink = possible_location
        if not self.hardlink:
            utils.die(self.logger,
                      "please install 'hardlink' to use this feature")

        # Setting the args for hardlink accodring to the distribution
        if self.family == "debian":
            self.hardlink_args = "-f -p -o -t -v /var/www/cobbler/distro_mirror /var/www/cobbler/repo_mirror"
        elif self.family == "suse":
            self.hardlink_args = "-f -v /var/www/cobbler/distro_mirror /var/www/cobbler/repo_mirror"
        else:
            self.hardlink_args = "-c -v /var/www/cobbler/distro_mirror /var/www/cobbler/repo_mirror"
        self.hardlink_cmd = "%s %s" % (self.hardlink, self.hardlink_args)
Esempio n. 3
0
def regen_ss_file():
    """
    This is only used for Kerberos auth at the moment. It identifies XMLRPC requests from Apache that have already been
    cleared by Kerberos.

    :return: 1 if this was successful.
    """
    ssfile = "/var/lib/cobbler/web.ss"
    fd = open("/dev/urandom", 'rb')
    data = fd.read(512)
    fd.close()

    fd = os.open(ssfile, os.O_CREAT | os.O_RDWR, 0o660)
    os.write(fd, binascii.hexlify(data))
    os.close(fd)

    http_user = "******"
    family = utils.get_family()
    if family == "debian":
        http_user = "******"
    elif family == "suse":
        http_user = "******"
    os.lchown("/var/lib/cobbler/web.ss", pwd.getpwnam(http_user)[2], -1)

    return 1
Esempio n. 4
0
def test_get_family():
    # Arrange
    distros = ("suse", "redhat", "debian")

    # Act
    result = utils.get_family()

    # Assert
    assert result in distros
Esempio n. 5
0
def test_get_family():
    # Arrange
    # TODO: Make this nicer so it doesn't need to run on suse specific distros to succeed.

    # Act
    result = utils.get_family()

    # Assert
    assert result == "suse"
Esempio n. 6
0
    def createrepo_walker(self, repo, dirname, fnames):
        """
        Used to run createrepo on a copied Yum mirror.

        :param repo: The repository object to run for.
        :param dirname: The directory to run in.
        :param fnames: Not known what this is for.
        """
        if os.path.exists(dirname) or repo['breed'] == 'rsync':
            utils.remove_yum_olddata(dirname)

            # add any repo metadata we can use
            mdoptions = []
            if os.path.isfile("%s/.origin/repodata/repomd.xml" % (dirname)):
                if HAS_LIBREPO:
                    rd = self.librepo_getinfo("%s/.origin" % (dirname))
                elif HAS_YUM:
                    rmd = yum.repoMDObject.RepoMD(
                        '', "%s/.origin/repodata/repomd.xml" % (dirname))
                    rd = rmd.repoData
                else:
                    utils.die(self.logger,
                              "yum/librepo is required to use this feature")

                if "group" in rd:
                    if HAS_LIBREPO:
                        groupmdfile = rd['group']['location_href']
                    else:
                        groupmdfile = rmd.getData("group").location[1]
                    mdoptions.append("-g %s" % groupmdfile)
                if "prestodelta" in rd:
                    # need createrepo >= 0.9.7 to add deltas
                    if utils.get_family() in ("redhat", "suse"):
                        cmd = "/usr/bin/rpmquery --queryformat=%{VERSION} createrepo"
                        createrepo_ver = utils.subprocess_get(self.logger, cmd)
                        if not createrepo_ver[0:1].isdigit():
                            cmd = "/usr/bin/rpmquery --queryformat=%{VERSION} createrepo_c"
                            createrepo_ver = utils.subprocess_get(
                                self.logger, cmd)
                        if utils.compare_versions_gt(createrepo_ver, "0.9.7"):
                            mdoptions.append("--deltas")
                        else:
                            self.logger.error(
                                "this repo has presto metadata; you must upgrade createrepo to >= 0.9.7 first and then need to resync the repo through Cobbler."
                            )

            blended = utils.blender(self.api, False, repo)
            flags = blended.get("createrepo_flags", "(ERROR: FLAGS)")
            try:
                cmd = "createrepo %s %s %s" % (" ".join(mdoptions), flags,
                                               pipes.quote(dirname))
                utils.subprocess_call(self.logger, cmd)
            except:
                utils.log_exc(self.logger)
                self.logger.error("createrepo failed.")
            del fnames[:]  # we're in the right place
Esempio n. 7
0
    def run(self):
        """
        The CLI usage is "cobbler check" before "cobbler sync".

        :return: None if there are no errors, otherwise returns a list of things to correct prior to running application
                 'for real'.
        """
        status = []
        self.checked_family = utils.get_family()
        self.check_name(status)
        self.check_selinux(status)
        if self.settings.manage_dhcp:
            mode = self.collection_mgr.api.get_sync().dhcp.what()
            if mode == "isc":
                self.check_dhcpd_bin(status)
                self.check_dhcpd_conf(status)
                self.check_service(status, "dhcpd")
            elif mode == "dnsmasq":
                self.check_dnsmasq_bin(status)
                self.check_service(status, "dnsmasq")

        if self.settings.manage_dns:
            mode = self.collection_mgr.api.get_sync().dns.what()
            if mode == "bind":
                self.check_bind_bin(status)
                self.check_service(status, "named")
            elif mode == "dnsmasq" and not self.settings.manage_dhcp:
                self.check_dnsmasq_bin(status)
                self.check_service(status, "dnsmasq")

        mode = self.collection_mgr.api.get_sync().tftpd.what()
        if mode == "in_tftpd":
            self.check_tftpd_dir(status)
        elif mode == "tftpd_py":
            self.check_ctftpd_dir(status)

        self.check_service(status, "cobblerd")

        self.check_bootloaders(status)
        self.check_for_wget_curl(status)
        self.check_rsync_conf(status)
        self.check_iptables(status)
        self.check_yum(status)
        self.check_debmirror(status)
        self.check_for_ksvalidator(status)
        self.check_for_default_password(status)
        self.check_for_unreferenced_repos(status)
        self.check_for_unsynced_repos(status)
        self.check_for_cman(status)

        return status
Esempio n. 8
0
    def createrepo_walker(self, repo, dirname: str, fnames):
        """
        Used to run createrepo on a copied Yum mirror.

        :param repo: The repository object to run for.
        :param dirname: The directory to run in.
        :param fnames: Not known what this is for.
        """
        if os.path.exists(dirname) or repo.breed == RepoBreeds.RSYNC:
            utils.remove_yum_olddata(dirname)

            # add any repo metadata we can use
            mdoptions = []
            origin_path = os.path.join(dirname, ".origin")
            repodata_path = os.path.join(origin_path, "repodata")

            if os.path.isfile(os.path.join(repodata_path, "repomd.xml")):
                rd = self.librepo_getinfo(origin_path)

                if "group" in rd:
                    groupmdfile = rd['group']['location_href']
                    mdoptions.append("-g %s" %
                                     os.path.join(origin_path, groupmdfile))
                if "prestodelta" in rd:
                    # need createrepo >= 0.9.7 to add deltas
                    if utils.get_family() in ("redhat", "suse"):
                        cmd = "/usr/bin/rpmquery --queryformat=%{VERSION} createrepo"
                        createrepo_ver = utils.subprocess_get(cmd)
                        if not createrepo_ver[0:1].isdigit():
                            cmd = "/usr/bin/rpmquery --queryformat=%{VERSION} createrepo_c"
                            createrepo_ver = utils.subprocess_get(cmd)
                        if utils.compare_versions_gt(createrepo_ver, "0.9.7"):
                            mdoptions.append("--deltas")
                        else:
                            self.logger.error(
                                "this repo has presto metadata; you must upgrade createrepo to >= 0.9.7 "
                                "first and then need to resync the repo through Cobbler."
                            )

            blended = utils.blender(self.api, False, repo)
            flags = blended.get("createrepo_flags", "(ERROR: FLAGS)")
            try:
                cmd = "createrepo %s %s %s" % (" ".join(mdoptions), flags,
                                               pipes.quote(dirname))
                utils.subprocess_call(cmd)
            except:
                utils.log_exc()
                self.logger.error("createrepo failed.")
            del fnames[:]  # we're in the right place
Esempio n. 9
0
def regen_ss_file():
    """
    This is only used for Kerberos auth at the moment. It identifies XMLRPC requests from Apache that have already been
    cleared by Kerberos.
    """
    ssfile = "/var/lib/cobbler/web.ss"
    with open("/dev/urandom", 'rb') as fd:
        data = fd.read(512)

    with open(ssfile, 'wb', 0o660) as fd:
        fd.write(binascii.hexlify(data))

    http_user = "******"
    family = utils.get_family()
    if family == "debian":
        http_user = "******"
    elif family == "suse":
        http_user = "******"
    os.lchown("/var/lib/cobbler/web.ss", pwd.getpwnam(http_user)[2], -1)
Esempio n. 10
0
 def __init__(self, collection_mgr, logger=None):
     """
     Constructor
     """
     # self.collection_mgr   = collection_mgr
     # self.api      = collection_mgr.api
     # self.settings = collection_mgr.settings()
     if logger is None:
         logger = clogger.Logger()
     self.logger = logger
     self.family = utils.get_family()
     if self.family == "debian":
         self.hardlink = "/usr/bin/hardlink"
         self.hardlink_args = "-f -p -o -t -v /var/www/cobbler/distro_mirror /var/www/cobbler/repo_mirror"
     elif self.family == "suse":
         self.hardlink = "/usr/bin/hardlink"
         self.hardlink_args = "-f -v /var/www/cobbler/distro_mirror /var/www/cobbler/repo_mirror"
     else:
         self.hardlink = "/usr/sbin/hardlink"
         self.hardlink_args = "-c -v /var/www/cobbler/distro_mirror /var/www/cobbler/repo_mirror"
     self.hardlink_cmd = "%s %s" % (self.hardlink, self.hardlink_args)