Skip to content

Commit

Permalink
Merge pull request #1301 from jmaas/master
Browse files Browse the repository at this point in the history
Add proxy support for get-loaders, signature update and reposync.
  • Loading branch information
jmaas committed Oct 19, 2014
2 parents a000ae5 + a6fb446 commit af7f119
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 42 deletions.
12 changes: 1 addition & 11 deletions cobbler/action_dlcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,7 @@ def run(self, force=False):
)

proxies = {}
if "HTTP_PROXY" in os.environ:
proxies['http'] = os.environ["HTTP_PROXY"]

if "HTTPS_PROXY" in os.environ:
proxies['https'] = os.environ["HTTPS_PROXY"]

if "FTP_PROXY" in os.environ:
proxies['ftp'] = os.environ["FTP_PROXY"]

if len(proxies) == 0:
proxies = None
proxies['http'] = self.settings.proxy_url_ext

for src, dst in files:
if os.path.exists(dst) and not force:
Expand Down
50 changes: 26 additions & 24 deletions cobbler/action_reposync.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import os
import os.path
import urlgrabber

HAS_YUM = True
try:
Expand Down Expand Up @@ -416,37 +417,38 @@ def yum_sync(self, repo):

repodata_path = os.path.join(dest_path, "repodata")

if not os.path.exists("/usr/bin/wget"):
utils.die(self.logger, "no /usr/bin/wget found, please install wget")

# grab repomd.xml and use it to download any metadata we can use
if repo.proxy == '':
cmd2 = "/usr/bin/wget -q %s/repodata/repomd.xml -O %s/repomd.xml" % (repo_mirror, temp_path)
else:
cmd2 = "/bin/env http_proxy=%s /usr/bin/wget -q %s/repodata/repomd.xml -O %s/repomd.xml" % (repo.proxy, repo_mirror, temp_path)
rc = utils.subprocess_call(self.logger, cmd2)
if rc == 0:
# create our repodata directory now, as any extra metadata we're
# about to download probably lives there
if not os.path.isdir(repodata_path):
os.makedirs(repodata_path)
rmd = yum.repoMDObject.RepoMD('', "%s/repomd.xml" % (temp_path))
for mdtype in rmd.repoData.keys():
# don't download metadata files that are created by default
if mdtype not in ["primary", "primary_db", "filelists", "filelists_db", "other", "other_db"]:
mdfile = rmd.getData(mdtype).location[1]
cmd3 = "/usr/bin/wget -q %s/%s -O %s/%s" % (repo_mirror, mdfile, dest_path, mdfile)
utils.subprocess_call(self.logger, cmd3)
if rc != 0:
utils.die(self.logger, "wget failed")
proxies = {}
proxies['http'] = self.settings.proxy_url_ext

# now run createrepo to rebuild the index
src = repo_mirror + "/repodata/repomd.xml"
dst = temp_path + "/repomd.xml"
try:
urlgrabber.grabber.urlgrab(src, filename=dst, proxies=proxies)
except:
utils.die("failed to fetch %s" % src)

# create our repodata directory now, as any extra metadata we're
# about to download probably lives there
if not os.path.isdir(repodata_path):
os.makedirs(repodata_path)
rmd = yum.repoMDObject.RepoMD('', "%s/repomd.xml" % (temp_path))
for mdtype in rmd.repoData.keys():
# don't download metadata files that are created by default
if mdtype not in ["primary", "primary_db", "filelists", "filelists_db", "other", "other_db"]:
mdfile = rmd.getData(mdtype).location[1]
src = repo_mirror + "/" + mdfile
dst = dest_path + "/" + mdfile
try:
urlgrabber.grabber.urlgrab(src, filename=dst, proxies=proxies)
except:
utils.die("failed to fetch %s" % src)

# now run createrepo to rebuild the index
if repo.mirror_locally:
os.path.walk(dest_path, self.createrepo_walker, repo)

# create the config file the hosts will use to access the repository.

self.create_local_file(dest_path, repo)

# ====================================================================================
Expand Down
6 changes: 4 additions & 2 deletions cobbler/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import random
import tempfile
import time
import urllib2
import urlgrabber

from cobbler import action_acl
from cobbler import action_buildiso
Expand Down Expand Up @@ -577,7 +577,9 @@ def get_signatures(self):
def signature_update(self, logger):
try:
tmpfile = tempfile.NamedTemporaryFile()
response = urllib2.urlopen(self.settings().signature_url)
proxies = {}
proxies['http'] = self.settings().proxy_url_ext
response = urlgrabber.grabber.urlopen(self.settings().signature_url, proxies=proxies)
sigjson = response.read()
tmpfile.write(sigjson)
tmpfile.flush()
Expand Down
2 changes: 1 addition & 1 deletion cobbler/item_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
["kernel_options", {}, '<<inherit>>', "Kernel Options", True, "Ex: selinux=permissive", 0, "dict"],
["kernel_options_post", {}, '<<inherit>>', "Kernel Options (Post Install)", True, "Ex: clocksource=pit noapic", 0, "dict"],
["autoinstall_meta", {}, '<<inherit>>', "Automatic Installation Metadata", True, "Ex: dog=fang agent=86", 0, "dict"],
["proxy", "", None, "Proxy", True, "Proxy URL", 0, "str"],
["proxy", "SETTINGS:proxy_url_int", "<<inherit>>", "Proxy", True, "Proxy URL", 0, "str"],
["repos", [], '<<inherit>>', "Repos", True, "Repos to auto-assign to this profile", [], "list"],
["comment", "", "", "Comment", True, "Free form text description", 0, "str"],
["virt_auto_boot", "SETTINGS:virt_auto_boot", '<<inherit>>', "Virt Auto Boot", True, "Auto boot this VM?", 0, "bool"],
Expand Down
2 changes: 1 addition & 1 deletion cobbler/item_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
["mirror_locally", True, 0, "Mirror locally", True, "Copy files or just reference the repo externally?", 0, "bool"],
["priority", 99, 0, "Priority", True, "Value for yum priorities plugin, if installed", 0, "int"],
["yumopts", {}, 0, "Yum Options", True, "Options to write to yum config file", 0, "dict"],
["proxy", "", 0, "Proxy information", True, "ex: http://example.com:8080", [], "str"]
["proxy", "SETTINGS:proxy_url_ext", "<<inherit>>", "Proxy information", True, "ex: http://example.com:8080", [], "str"]
]


Expand Down
2 changes: 1 addition & 1 deletion cobbler/item_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
["kernel_options_post", {}, 0, "Kernel Options (Post Install)", True, "Ex: clocksource=pit noapic", 0, "dict"],
["autoinstall_meta", {}, 0, "Automatic Installation Template Metadata", True, "Ex: dog=fang agent=86", 0, "dict"],
["enable_gpxe", "SETTINGS:enable_gpxe", 0, "Enable gPXE?", True, "Use gPXE instead of PXELINUX for advanced booting options", 0, "bool"],
["proxy", "<<inherit>>", 0, "Proxy", True, "Proxy URL", 0, "str"],
["proxy", "<<inherit>>", 0, "Internal Proxy", True, "Internal proxy URL", 0, "str"],
["netboot_enabled", True, 0, "Netboot Enabled", True, "PXE (re)install this machine at next boot?", 0, "bool"],
["autoinstall", "<<inherit>>", 0, "Automatic Installation Template", True, "Path to automatic installation template", 0, "str"],
["comment", "", 0, "Comment", True, "Free form text description", 0, "str"],
Expand Down
11 changes: 9 additions & 2 deletions config/cobbler/settings
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ replicate_repo_rsync_options: "-avzH"
# always write DHCP entries, regardless if netboot is enabled
always_write_dhcp_entries: 0

# include other snippets
include: [ "/etc/cobbler/settings.d/*.settings" ]
# external proxy - used by: get-loaders, reposync, signature update
# eg: proxy_url_ext: "http://192.168.1.1:8080"
proxy_url_ext: ""

# internal proxy - used by systems to reach cobbler for kickstarts
# eg: proxy_url_int: "http://10.0.0.1:8080"
proxy_url_int: ""

# include other configuration snippets
include: [ "/etc/cobbler/settings.d/*.settings" ]

0 comments on commit af7f119

Please sign in to comment.