Support a "mirror" method of apt-get
apt-get supports a "mirror" method that will automatically select a closest mirror based on geographical location. So extend URI library to handle repository sources with mirror:// Change-Id: I7b8018af50e431614d0d5c87ad3f1c8bad94e4d9 Closes-Bug: #1669751
This commit is contained in:
parent
e1af023451
commit
ae1c80f8fb
@ -4,7 +4,13 @@ require 'net/http'
|
||||
require 'open-uri'
|
||||
require 'uri'
|
||||
|
||||
Puppet::Parser::Functions::newfunction(:url_available, :doc => <<-EOS
|
||||
module URI
|
||||
# Define 'mirror:' scheme
|
||||
class MIRROR < HTTP; end
|
||||
@@schemes['MIRROR'] = MIRROR
|
||||
end
|
||||
|
||||
Puppet::Parser::Functions::newfunction(:url_available, :arity => -2, :doc => <<-EOS
|
||||
The url_available function attempts to make a http request to a url and throws
|
||||
a puppet error if the URL is unavailable. The url_available function can take
|
||||
up to two paramters. The first paramter is the URL which is required and can be
|
||||
@ -39,8 +45,7 @@ url_available({ 'uri' => 'http://www.google.com',
|
||||
|
||||
EOS
|
||||
) do |argv|
|
||||
url = argv[0]
|
||||
http_proxy = argv[1]
|
||||
url, http_proxy = argv
|
||||
threads_count = 16
|
||||
Thread.abort_on_exception=true
|
||||
|
||||
@ -54,12 +59,8 @@ EOS
|
||||
|
||||
# check the type of url being passed, if hash look for the uri key
|
||||
if url.instance_of? Hash
|
||||
if url.has_key?('uri')
|
||||
uri = url['uri']
|
||||
end
|
||||
if url.has_key?('proxy')
|
||||
http_proxy = url['proxy']
|
||||
end
|
||||
uri = url.fetch 'uri', nil
|
||||
http_proxy = url.fetch 'proxy', nil
|
||||
elsif url.instance_of? String
|
||||
uri = url
|
||||
else
|
||||
|
@ -7,6 +7,7 @@ describe 'url_available' do
|
||||
http://archive.ubuntu.com/ubuntu/
|
||||
http://mirror.fuel-infra.org/mos/ubuntu/
|
||||
http://apt.postgresql.org/pub/repos/apt/
|
||||
http://mirrors.ubuntu.com/mirrors.txt
|
||||
)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user