コード例 #1
0
ファイル: new.py プロジェクト: LapwingOrg/sponson
    def _save_config(self):
        """
        Save container configuration to disk,
        both in the container and on the host.

        This is to allow the firewall setup to work later,
        and to record any mounts, slices or other changes.

        The host copy of the configuration file
        is always the last build container,
        to match what is set up in the systemd unit file.
        """
        host_conf_file = os.path.join(ETC_CONTAINER_CONF_DIR,
                                      "{}.yaml".format(self.name))
        container_conf_file = os.path.join(self.path,
                                           host_conf_file.lstrip("/"))

        conf_data = configfile.merge(self.runtime_config, self.all_config)

        conf_data["container"]["name"] = self.name
        conf_data["container"]["version"] = self.version

        configfile.write_config_file(conf_data, host_conf_file)
        configfile.write_config_file(conf_data, container_conf_file)
コード例 #2
0
ファイル: dnf.py プロジェクト: LapwingOrg/sponson
    def setup(self):
        """
        Setup DNF builder.
        """
        dnf_conf = Conf()

        dnf_conf.debuglevel = 10
        dnf_conf.logdir = self.log_path

        dnf_conf.assumeyes = True

        dnf_conf.installroot = self.image_path
        pdir = os.path.join(self.image_path, "var", "lib", "dnf")
        dnf_conf.persistdir = pdir
        dnf_conf.cachedir = os.path.join(pdir, "cache")
        dnf_conf.keepcache = not self.cleanall

        dnf_conf.releasever = str(self.config["releasever"])

        for arch in ("arch", "basearch"):
            dnf_conf.substitutions[arch] = self.config["architecture"]

        for conf in ("proxy", "proxy_username", "proxy_password"):
            if conf in self.runtime:
                setattr(dnf_conf, conf, self.runtime[conf])

        self.dnf_builder = Base(dnf_conf)
        self.dnf_builder.read_all_repos()

        all_repos = self.config["repo"].get("*", False)
        runtime_all_repos = self.runtime["repo"].get("*", False)

        for repo_name, repo in self.dnf_builder.repos.items():
            repo_conf = None
            if all_repos or runtime_all_repos:
                repo_conf = configfile.merge(self.config["repo"].get("*", {}),
                                             self.runtime["repo"].get("*", {}))

                if repo_conf.get("baseurl"):
                    del repo_conf["baseurl"]

            if (repo_name in self.config["repo"] or
                    repo_name in self.runtime["repo"]):
                merge_conf = configfile.merge(
                    self.config["repo"].get(repo_name, {}),
                    self.runtime["repo"].get(repo_name, {}))

                if not merge_conf:
                    continue

                if repo_conf:
                    repo_conf = configfile.merge(merge_conf, repo_conf)
                else:
                    repo_conf = merge_conf

            if repo_conf:
                if "baseurl" in repo_conf:
                    repo.baseurl = repo_conf["baseurl"]
                    # Explicitly remove these as
                    # they can override the baseurl settings
                    repo.mirrorlist = None
                    repo.metalink = None
                if "enabled" in repo_conf:
                    if not repo_conf["enabled"]:
                        repo.disable()
                    else:
                        repo.enable()
                else:
                    repo.enable()

        # If the RPM DBs aren't initialised,
        # hawkey doesn't fill the sack correctly and fails.
        # But we don't want to overwrite any already setup RPM DBs.
        rpm_path = os.path.join(self.image_path, "var", "lib", "rpm")
        if not os.path.exists(rpm_path):
            self.dnf_builder.ts.ts.initDB()

        self.dnf_builder.fill_sack()