ci/deploy.sh: yum install --skip-broken
[fuel.git] / build / select_closest_fuel_mirror.py
1 #!/usr/bin/python
2 ##############################################################################
3 # Copyright (c) 2016 Ericsson AB and others.
4 # stefan.k.berg@ericsson.com
5 # jonas.bjurel@ericsson.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # Select closest fuel mirror based on latency measured with ping.
13 # Failsafe: The us1 mirror
14
15 from subprocess import Popen,PIPE
16 import re
17 from operator import itemgetter
18
19 mirrors = [ "us1", "cz1" ]
20 FNULL = open('/dev/null', 'w')
21 try:
22     re_avg = re.compile(r'.* = [^/]*/([^/]*).*')
23
24     pingtime = {}
25     for mirror in mirrors:
26         fqdn = "mirror.seed-"+mirror+".fuel-infra.org"
27         pingtime[fqdn] = 0
28         pipe = Popen("ping -c 3 " + fqdn + " | tail -1",shell = True, stdout=PIPE, stderr=FNULL)
29         avg  = pipe.communicate()[0]
30         pipe.stdout.close()
31         pingtime[fqdn] = float(re_avg.split(avg)[1])
32
33     print sorted(pingtime.items(), key=itemgetter(1))[0][0]
34 except:
35     print "mirror.seed-"+mirrors[0]+".fuel-infra.org"