From b05468107f6bbb82153d244acb0c72be47a81e94 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Fri, 2 Nov 2007 10:29:40 -0400 Subject: In the process of making all repositories templates so we can apply the values of --server-override to them and make cobbler servers easier to migrate also. This will result in the removal of --local-filename from cobbler repos. --- cobbler/action_litesync.py | 6 +- cobbler/action_reposync.py | 14 ++--- cobbler/action_sync.py | 138 ++++++++++++++++++++++++++++++--------------- 3 files changed, 105 insertions(+), 53 deletions(-) (limited to 'cobbler') diff --git a/cobbler/action_litesync.py b/cobbler/action_litesync.py index a1f9eea..a35d16c 100644 --- a/cobbler/action_litesync.py +++ b/cobbler/action_litesync.py @@ -78,11 +78,13 @@ class BootLiteSync: raise CX(_("error in profile lookup")) # rebuild profile_list YAML file in webdir self.sync.write_listings() + # rebuild the yum configuration files for any attached repos + self.sync.retemplate_yum_repos(obj,is_profile) # add profiles/$name YAML file in webdir self.sync.write_profile_file(profile) # generate kickstart for kickstarts/$name/ks.cfg in webdir self.sync.validate_kickstart_for_specific_profile(profile) - + def remove_single_profile(self, name): # rebuild profile_list YAML file in webdir self.sync.write_listings() @@ -99,6 +101,8 @@ class BootLiteSync: # rebuild system_list file in webdir self.sync.regen_ethers() # /etc/ethers, for dnsmasq & rarpd self.sync.regen_hosts() # /var/lib/cobbler/cobbler_hosts, pretty much for dnsmasq + # rebuild the yum configuration files for any attached repos + self.sync.retemplate_yum_repos(obj,is_profile) self.sync.write_listings() # write the PXE and YAML files for the system self.sync.write_all_system_files(system) diff --git a/cobbler/action_reposync.py b/cobbler/action_reposync.py index d49efd1..fdd9c3a 100644 --- a/cobbler/action_reposync.py +++ b/cobbler/action_reposync.py @@ -224,16 +224,14 @@ class RepoSync: def create_local_file(self, repo, dest_path, output=True): """ Two uses: - (A) Create local files that can be used with yum on provisioned clients to make use of thisi mirror. - (B) Create a temporary file for yum to feed into reposync + (A) output=True, Create local files that can be used with yum on provisioned clients to make use of thisi mirror. + (B) output=False, Create a temporary file for yum to feed into yum for mirroring """ - # FIXME: the output case will generate repo configuration files which are usable + # the output case will generate repo configuration files which are usable # for the installed systems. They need to be made compatible with --server-override - # which means that we should NOT replace @@server@@ except in a dynamically generated - # post script that runs on each file we wget, and replace it there. Until then - # installed repos may require a host file setting that allows them to find the - # main server address used for the initial mirroring. We can clean this up :) + # which means they are actually templates, which need to be rendered by a cobbler-sync + # on per profile/system basis. if output: fname = os.path.join(dest_path,"config.repo") @@ -246,7 +244,7 @@ class RepoSync: if output: # see note above: leave as @@server@@ and fix in %post of kickstart when # we generate the stanza - line = "baseurl=http://%s/cobbler/repo_mirror/%s\n" % (self.settings.server, repo.name) + line = "baseurl=http://${server}/cobbler/repo_mirror/%s\n" % (repo.name) config_file.write(line) else: line = "baseurl=%s\n" % repo.mirror diff --git a/cobbler/action_sync.py b/cobbler/action_sync.py index 75e5389..76ad5b9 100644 --- a/cobbler/action_sync.py +++ b/cobbler/action_sync.py @@ -362,8 +362,8 @@ class BootSync: ksmeta = meta["ks_meta"] del meta["ks_meta"] meta.update(ksmeta) # make available at top level - meta["yum_repo_stanza"] = self.generate_repo_stanza(g) - meta["yum_config_stanza"] = self.generate_config_stanza(g) + meta["yum_repo_stanza"] = self.generate_repo_stanza(g,True) + meta["yum_config_stanza"] = self.generate_config_stanza(g,True) meta["kickstart_done"] = self.generate_kickstart_signal(g, None) meta["kernel_options"] = utils.hash_to_string(meta["kernel_options"]) kfile = open(kickstart_path) @@ -410,56 +410,60 @@ class BootSync: return buf - def generate_repo_stanza(self, profile): - # returns the line of repo additions (Anaconda supports in FC-6 and later) that adds - # the list of repos to things that Anaconda can install from. This corresponds - # will replace "TEMPLATE::yum_repo_stanza" in a cobbler kickstart file. + def generate_repo_stanza(self, obj, is_profile=True): + + """ + Automatically attaches yum repos to profiles/systems in kickstart files + that contain the magic $yum_repo_stanza variable. + """ + buf = "" - blended = utils.blender(self.api, False, profile) - repos = blended["repos"] - for r in repos: - repo = self.repos.find(name=r) - if repo is None: - continue - http_url = "http://%s/cblr/repo_mirror/%s" % (blended["server"], repo.name) - buf = buf + "repo --name=%s --baseurl=%s\n" % (repo.name, http_url) - distro = profile.get_conceptual_parent() + blended = utils.blender(self.api, False, obj) - # tack on all the install source repos IF there is more than one. - # this is basically to support things like RHEL5 split trees - # if there is only one, then there is no need to do this. - if len(distro.source_repos) > 1: - for r in distro.source_repos: - base = r[1].split("/")[-1].replace(".repo","") - buf = buf + "repo --name=%s --baseurl=%s\n" % (base, r[1]) + # for all yum repo templates we have rendered rendered ... + globpath = os.path.join(self.settings.webdir, "repos_profile", blended["name"], "*") + configs = glob.glob(globpath) + + # add a yum configuration line that makes the kickstart use them ... + for c in configs: + name = c.split("/")[-1].replace(".repo","") + url = c.replace(self.settings.webdir, "%s/cobbler" % blended["server"]) + buf = buf + "repo --name=%s --baseurl=%s\n" % (name, url) return buf - def generate_config_stanza(self, profile): - # returns the line in post that would configure yum to use repos added with "cobbler repo add" - blended = utils.blender(self.api, False,profile) - repos = blended["repos"] - buf = "" - for r in repos: - repo = self.repos.find(name=r) - if repo is None: - continue - repo.local_filename = repo.local_filename.replace(".repo","") - if not (repo.local_filename is None) and not (repo.local_filename == ""): - buf = buf + "wget http://%s/cblr/repo_mirror/%s/config.repo --output-document=/etc/yum.repos.d/%s.repo\n" % (blended["server"], repo.name, repo.local_filename) + def generate_config_stanza(self, obj, is_profile=True): + + """ + Add in automatic to configure /etc/yum.repos.d on the remote system + if the kickstart file contains the magic $yum_config_stanza. + """ - # now install the core repos - distro = profile.get_conceptual_parent() if self.settings.yum_core_mirror_from_server: - for r in distro.source_repos: - short = r[0].split("/")[-1] - buf = buf + "wget %s --output-document=/etc/yum.repos.d/%s\n" % (r[0], short) + return + + if is_profile: + urlseg = "repos_profile" + else: + urlseg = "repos_system" + + distro = obj.get_conceptual_parent() + if not is_profile: + distro = distro.get_conceptual_parent() - # if there were any core repos, install the voodoo to disable the OS public core - # location -- FIXME: should probably run sed on the files, rather than rename them. - if len(distro.source_repos) > 0: - for x in ["fedora-core", "CentOS-Base"] : - buf = buf + "test -e /etc/yum.repos.d/%s.repo && mv /etc/yum.repos.d/%s.repo /etc/yum.repos.d/disabled-%s\n" % (x,x,x) + blended = utils.blender(self.api, False, obj) + globpath = os.path.join(self.settings.webdir, "repos_profile", blended["name"], "*") + configs = glob.glob(globpath) + + # for each kickstart template we have rendered ... + for c in configs: + + name = c.split("/")[-1].replace(".repo","") + url = c.replace(self.settings.webdir, "%s/cobbler" % blended["server"]) + buf = buf + "repo --name=%s --baseurl=%s\n" % (name, url) + + # add the line to create the yum config file on the target box + buf = buf + "wget http://%s/cblr/%s/%s/%s/config.repo --output-document=/etc/yum.repos.d/%s.repo\n" % (blended["server"], urlseg, blended["name"], name) return buf @@ -613,11 +617,57 @@ class BootSync: self.write_distro_file(d) for p in self.profiles: + self.retemplate_yum_repos(p,True) self.write_profile_file(p) for system in self.systems: + self.retemplate_yum_repos(system,False) self.write_all_system_files(system) + def retemplate_yum_repos(self,obj,is_profile): + # FIXME: blender could use caching for performance + # FIXME: make stanza generation code load stuff from the right place + """ + Yum repository management files are in self.settings.webdir/repo_mirror/$name/config.repo + and also potentially in listed in the source_repos structure of the distro object, however + these files have server URLs in them that must be templated out. This function does this. + """ + blended = utils.blender(self.api, False, obj) + + if is_profile: + outseg = "repos_profile" + else: + outseg = "repos_system" + + confdir = os.path.join(self.settings.webdir, outseg) + shutil.rmtree(confdir, ignore_errors=True, onerror=None) + + input_files = [] + + # tack on all the install source repos IF there is more than one. + # this is basically to support things like RHEL5 split trees + # if there is only one, then there is no need to do this. + if len(blended["source_repos"]) > 1: + for r in blended["source_repos"]: + input_files.append(r) + + for repo in blended["repos"]: + input_files.append(os.path.join(self.settings.webdir, "repo_mirror", repo, "config.repo")) + + for infile in input_files: + dispname = infile.split("/")[-1].replace(".repo","") + outdir = os.path.join(confdir, outseg, blended["name"]) + self.mkdir(outdir) + try: + infile_h = open(infile) + except: + raise CX(_("cobbler reposync needs to be run on repo (%s) first" % dispname)) + infile_data = infile_h.read() + infile_h.close() + outfile = os.path.join(outdir, "config.repo") + self.apply_template(infile_data, blended, outfile) + + def write_all_system_files(self,system): profile = system.get_conceptual_parent() -- cgit