Make sure to use only up-to-date mirrors
[fuel.git] / build / f_isoroot / f_repobuild / opnfv_mirror_conf.py
1 #!/usr/bin/env python
2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 # mskalski@mirantis.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 import os
11 import yaml
12
13 current_snapshot =  os.environ["LATEST_TARGET_UBUNTU"]
14 mos_version = os.environ['MOS_VERSION']
15 openstack_version = os.environ['OPENSTACK_VERSION']
16 mos_ubuntu = os.environ['MIRROR_MOS_UBUNTU']
17 mos_ubuntu_root = os.environ['MIRROR_MOS_UBUNTU_ROOT']
18 mirror_ubuntu = os.environ['MIRROR_UBUNTU_URL']
19 if os.environ.get('BUILD_FUEL_PLUGINS'):
20   plugins = os.environ['BUILD_FUEL_PLUGINS']
21 else:
22   plugins = os.environ['PLUGINS']
23
24
25 configuration_file = open('fuel-mirror/contrib/fuel_mirror/etc/config.yaml').read()
26 conf = yaml.load(configuration_file)
27 conf['pattern_dir'] = '.'
28 conf['openstack_version'] = openstack_version
29 conf['mos_version'] = mos_version
30
31 with open('opnfv-config.yaml', 'w') as outfile:
32   outfile.write( yaml.dump(conf, default_flow_style=False) )
33
34 pattern_file = open('fuel-mirror/contrib/fuel_mirror/data/ubuntu.yaml').read()
35 pattern = yaml.load(pattern_file)
36 pattern['mos_baseurl'] = "http://{}{}".format(mos_ubuntu, mos_ubuntu_root)
37 pattern['ubuntu_baseurl'] = mirror_ubuntu
38 for group in pattern['groups']['mos']:
39   group['uri'] = pattern['mos_baseurl']
40 for group in pattern['groups']['ubuntu']:
41   group['uri'] = pattern['ubuntu_baseurl']
42
43 for plugin in plugins.split():
44   path = "../{}/packages.yaml".format(plugin)
45   if os.path.isfile(path):
46     f = open(path).read()
47     plugin_yaml = yaml.load(f)
48     plugin_set = set(plugin_yaml['packages'])
49     main_set = set(pattern['packages'])
50     new_packages = plugin_set - main_set
51     print "Plugin {} require new packages: {}".format(plugin, ', '.join(new_packages))
52     pattern['packages'] = pattern['packages'] + list(new_packages)
53
54 pattern['requirements']['ubuntu'] = pattern['packages']
55
56 with open('ubuntu.yaml', 'w') as outfile:
57   outfile.write( yaml.safe_dump(pattern, default_flow_style=False) )