diff options
author | Stefan K. Berg <stefan.k.berg@ericsson.com> | 2016-01-22 13:15:02 +0100 |
---|---|---|
committer | Stefan Berg <sfb@consultron.com> | 2016-01-29 13:59:46 +0100 |
commit | 191776c93f9a82379c8efed2d568b4cd29aba612 (patch) | |
tree | 2927425121a144f8ec293a3967ace51591f20c27 /build | |
parent | b4f76f954b20c8725dfe30b0bee79f38230d23b8 (diff) |
Select closest Fuel mirror as measured by ping
Select the (hopefully) geographically closest Fuel mirror to speed
up the build time.
Change-Id: I586d90ae58a9c22b1cf60df1bdb907c0e97486fa
Signed-off-by: Stefan K. Berg <stefan.k.berg@ericsson.com>
(cherry picked from commit 49ccd1f337d09cc84b168afd970acaa2aaceff25)
Diffstat (limited to 'build')
-rw-r--r-- | build/Makefile | 2 | ||||
-rwxr-xr-x | build/select_closest_fuel_mirror.py | 35 |
2 files changed, 36 insertions, 1 deletions
diff --git a/build/Makefile b/build/Makefile index 5ba8259bd..550f360f9 100644 --- a/build/Makefile +++ b/build/Makefile @@ -49,7 +49,7 @@ export MIRROR_UBUNTU_URL := $(shell ./f_isoroot/f_repobuild/select_ubuntu_repo.s export MIRROR_UBUNTU := $(shell echo "$(MIRROR_UBUNTU_URL)" | cut -d'/' -f3 ) export MIRROR_UBUNTU_ROOT := $(shell echo -n '/' ; echo "$(MIRROR_UBUNTU_URL)" | cut -d'/' -f4-) -export LATEST_MIRROR_ID_URL := http://mirror.seed-us1.fuel-infra.org +export LATEST_MIRROR_ID_URL := http://$(shell ./select_closest_fuel_mirror.py) export MIRROR_MOS_UBUNTU := $(shell echo "$(LATEST_MIRROR_ID_URL)" | cut -d'/' -f3) export LATEST_TARGET_UBUNTU := $(shell curl -sSf "$(MIRROR_MOS_UBUNTU)/mos-repos/ubuntu/8.0.target.txt" | head -1) diff --git a/build/select_closest_fuel_mirror.py b/build/select_closest_fuel_mirror.py new file mode 100755 index 000000000..0fdc69eac --- /dev/null +++ b/build/select_closest_fuel_mirror.py @@ -0,0 +1,35 @@ +#!/usr/bin/python +############################################################################## +# Copyright (c) 2016 Ericsson AB and others. +# stefan.k.berg@ericsson.com +# jonas.bjurel@ericsson.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# Select closest fuel mirror based on latency measured with ping. +# Failsafe: The us1 mirror + +from subprocess import Popen,PIPE +import re +from operator import itemgetter + +mirrors = [ "us1", "cz1" ] +FNULL = open('/dev/null', 'w') +try: + re_avg = re.compile(r'.* = [^/]*/([^/]*).*') + + pingtime = {} + for mirror in mirrors: + fqdn = "mirror.seed-"+mirror+".fuel-infra.org" + pingtime[fqdn] = 0 + pipe = Popen("ping -c 3 " + fqdn + " | tail -1",shell = True, stdout=PIPE, stderr=FNULL) + avg = pipe.communicate()[0] + pipe.stdout.close() + pingtime[fqdn] = float(re_avg.split(avg)[1]) + + print sorted(pingtime.items(), key=itemgetter(1))[0][0] +except: + print "mirror.seed-"+mirrors[0]+".fuel-infra.org" |