Hi,

there is a new feature in trunk, the idea of which came up on the CentOS
mirror mailing list.  I just committed it to trunk:
http://svn.mirrorbrain.org/viewvc/mirrorbrain?view=revision&revision=8217
A review would be appreciated.


It works like this. Yum issues a request with appended query arguments like
?release=5.5&arch=x86_64&repo=os and expects a simple, plain text list of
mirror URLs, with the URLs pointing to the base of the requested repository.

Now, a mapping can be configured from the query arguments to a directory on the
server plus a file that is used as indicator of the mirror having the
repository or not.

In the below example, I configured some common mappings for (parts of) a CentOS
file tree:

  MirrorBrainYumDir release=(4|4\.8|5|5\.5) 
repo=(os|extras|addons|updates|centosplus|contrib) arch=i586    $1/$2/i386    
repodata/repomd.xml
  MirrorBrainYumDir release=(4|4\.8|5|5\.5) 
repo=(os|extras|addons|updates|centosplus|contrib) arch=x86_64  $1/$2/x86_64  
repodata/repomd.xml


The syntax of the new directive is:

  MirrorBrainYumDir 
     Specify query arguments mapping to a directory that must have a certain 
file.
  Syntax: 
     arg1=<regexp> [ arg2=<regexp> ... ] <basedir> <mandatory_file>
  Parts of basedir can be substituted with query arguments $1-$9.
  Patterns are forced to be anchored to start and end for security reasons.


In the snippet below, I'm requesting different repositories and it looks
just as it should. (The server always returns mirror.netcologne.de first
because the IP is in the same AS.)


 # curl -H "X-forwarded-for: 87.79.142.30" 
'http://centos/?release=5&arch=x86_64&repo=os'
http://mirror.netcologne.de/centos/5/os/x86_64/
http://ftp.hosteurope.de/mirror/centos.org/5/os/x86_64/
http://centos.intergenia.de/5/os/x86_64/
 # curl -H "X-forwarded-for: 87.79.142.30" 
'http://centos/?release=4&arch=i586&repo=updates'
http://mirror.netcologne.de/centos/4/updates/i386/
http://ftp.hosteurope.de/mirror/centos.org/4/updates/i386/
http://centos.intergenia.de/4/updates/i386/


Helpful is that symlinks in the file tree are automatically handled;
thus, looking up a file in the database works regardless of whether one
of the query arguments points to a symlink. That's the case in the
CentOS tree, e.g.:
lrwxrwxrwx  1 root root    3 Nov 11 22:35 4 -> 4.8

Maybe the functionality can be also used for other clients than Yum.

Peter

Attachment: pgp8QXBGHgU8k.pgp
Description: PGP signature

Reply via email to