summaryrefslogtreecommitdiffstats
path: root/cobbler/api.py
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@mdehaan.rdu.redhat.com>2007-08-31 17:37:53 -0400
committerMichael DeHaan <mdehaan@mdehaan.rdu.redhat.com>2007-08-31 17:37:53 -0400
commit677f54d3bcdc58ccc2ebf87973c156bf2836ec9a (patch)
tree756be290a4f8d64550976cd34fa2538a88da8c87 /cobbler/api.py
parent7b5da0bf400c2a09137c3fb7ff4d96f22750e612 (diff)
downloadthird_party-cobbler-677f54d3bcdc58ccc2ebf87973c156bf2836ec9a.tar.gz
third_party-cobbler-677f54d3bcdc58ccc2ebf87973c156bf2836ec9a.tar.xz
third_party-cobbler-677f54d3bcdc58ccc2ebf87973c156bf2836ec9a.zip
Added "cobbler repo auto-add" feature which can discover all the repos
the cobbler server has configured in yum and set them up to be mirrored automagically.
Diffstat (limited to 'cobbler/api.py')
-rw-r--r--cobbler/api.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/cobbler/api.py b/cobbler/api.py
index 6268283..6b22d30 100644
--- a/cobbler/api.py
+++ b/cobbler/api.py
@@ -121,6 +121,41 @@ class BootAPI:
"""
return self._config.new_repo(is_subobject=is_subobject)
+ def auto_add_repos(self):
+ """
+ Import any repos this server knows about and mirror them.
+ Credit: Seth Vidal.
+ """
+ try:
+ import yum
+ except:
+ raise CX(_("yum is not installed"))
+
+ version = yum.__version__
+ (a,b,c) = version.split(".")
+ version = a* 1000 + b*100 + c
+ if version < 324:
+ raise CX(_("need yum > 3.2.4 to proceed"))
+
+ base = yum.YumBase()
+ base.doRepoSetup()
+ repos = base.repos.listEnabled()
+ if len(repos) == 0:
+ raise CX(_("no repos enabled/available -- giving up."))
+
+ for repo in repos:
+ url = repo.urls[0]
+ cobbler_repo = self.new_repo()
+ auto_name = repo.name.replace(" ","")
+ # FIXME: probably doesn't work for yum-rhn-plugin ATM
+ cobbler_repo.set_mirror(url)
+ cobbler_repo.set_name(auto_name)
+ print "auto adding: %s (%s)" % (auto_name, url)
+ self._config.repos().add(cobbler_repo,with_copy=True)
+
+ print "run cobbler reposync to apply changes"
+ return True
+
def check(self):
"""
See if all preqs for network booting are valid. This returns