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
3f01bb9d23
commit
c8b04173d9
|
@ -4,7 +4,13 @@ require 'net/http'
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
require '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
|
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
|
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
|
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
|
EOS
|
||||||
) do |argv|
|
) do |argv|
|
||||||
url = argv[0]
|
url, http_proxy = argv
|
||||||
http_proxy = argv[1]
|
|
||||||
threads_count = 16
|
threads_count = 16
|
||||||
Thread.abort_on_exception=true
|
Thread.abort_on_exception=true
|
||||||
|
|
||||||
|
@ -54,12 +59,8 @@ EOS
|
||||||
|
|
||||||
# check the type of url being passed, if hash look for the uri key
|
# check the type of url being passed, if hash look for the uri key
|
||||||
if url.instance_of? Hash
|
if url.instance_of? Hash
|
||||||
if url.has_key?('uri')
|
uri = url.fetch 'uri', nil
|
||||||
uri = url['uri']
|
http_proxy = url.fetch 'proxy', nil
|
||||||
end
|
|
||||||
if url.has_key?('proxy')
|
|
||||||
http_proxy = url['proxy']
|
|
||||||
end
|
|
||||||
elsif url.instance_of? String
|
elsif url.instance_of? String
|
||||||
uri = url
|
uri = url
|
||||||
else
|
else
|
||||||
|
|
|
@ -7,6 +7,7 @@ describe 'url_available' do
|
||||||
http://archive.ubuntu.com/ubuntu/
|
http://archive.ubuntu.com/ubuntu/
|
||||||
http://mirror.fuel-infra.org/mos/ubuntu/
|
http://mirror.fuel-infra.org/mos/ubuntu/
|
||||||
http://apt.postgresql.org/pub/repos/apt/
|
http://apt.postgresql.org/pub/repos/apt/
|
||||||
|
http://mirrors.ubuntu.com/mirrors.txt
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue