From b59f69257b043212522b3c4fff946bd68068879a Mon Sep 17 00:00:00 2001 From: "Sergey V. Yudin" Date: Thu, 6 Aug 2015 14:32:48 +0000 Subject: [PATCH] Move user-defined extra networks from dnsmasq.template to astute Now Multiple Cluster Networks implented by manual modification of dnsmasq.template inside container. With this approach user-difened networks will be overwritten by puppet when docker container will be restarted. We going to create astute section EXTRA_ADMIN_NETWORKS which will contaion all additional networks used for dhcp. For backward compatibility we going to execute script which will create this section from dnsmasq.template Closes-Bug: #1473483 Change-Id: I287e717cd6b1c70e62ddcdd09aee421805862d37 --- packages/rpm/module.mk | 1 + packages/rpm/specs/extra_nets_from_cobbler.py | 76 +++++++++++++++++++ packages/rpm/specs/fuel-docker-images.spec | 15 +++- 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100755 packages/rpm/specs/extra_nets_from_cobbler.py diff --git a/packages/rpm/module.mk b/packages/rpm/module.mk index 53d437509..d82fefcd1 100644 --- a/packages/rpm/module.mk +++ b/packages/rpm/module.mk @@ -110,6 +110,7 @@ $(BUILD_DIR)/packages/rpm/fuel-docker-images.done: \ mkdir -p $(SANDBOX)/tmp/SOURCES && \ sudo cp -r $(BUILD_DIR)/docker/$(DOCKER_ART_NAME) $(SANDBOX)/tmp/SOURCES && \ (cd $(BUILD_DIR)/docker && sudo tar czf $(SANDBOX)/tmp/SOURCES/fuel-images-sources.tar.gz sources utils) && \ + sudo cp $(SOURCE_DIR)/packages/rpm/specs/extra_nets_from_cobbler.py $(SANDBOX)/tmp/SOURCES && \ sudo cp $(SOURCE_DIR)/packages/rpm/specs/fuel-docker-images.spec $(SANDBOX)/tmp && \ sudo chroot $(SANDBOX) rpmbuild --nodeps --define "_topdir /tmp" -ba /tmp/fuel-docker-images.spec cp $(SANDBOX)/tmp/RPMS/*/fuel-docker-images-*.rpm $(BUILD_DIR)/packages/rpm/RPMS/x86_64 diff --git a/packages/rpm/specs/extra_nets_from_cobbler.py b/packages/rpm/specs/extra_nets_from_cobbler.py new file mode 100755 index 000000000..8209bd0c1 --- /dev/null +++ b/packages/rpm/specs/extra_nets_from_cobbler.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python +# +# Copyright 2015 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# This script is supposed to be executed only during the upgrade of +# fuel-docker-images package. Script will merge values added manually +# to implement "multiple cluster networks" with current astute +# settings and will print result to stdout. +# +# It will work only if dnsmasq.template was modified stictly according +# to documentation and modified lines matches pattern: +# dhcp-range=,,,,[] +# dhcp-option=net:,option:router, +# dhcp-boot=net:,pxelinux.0,boothost, +# +# Starting from 7.0 we will handle this feature by puppet manifests +# parsing section EXTRA_ADMIN_NETWORKS from astute.yaml + +from collections import defaultdict +import yaml +import re +import sys + + +# This nets autogenerated by puppet according to networking settings +# of admin network. We will ignore them. +IGNORED_NETS = ['6', 'internal'] +OPTS_PLAIN = ['dhcp-range'] +OPTS_NAMED = ['dhcp-option', 'dhcp-boot'] +OPTS = OPTS_PLAIN + OPTS_NAMED +nets = defaultdict(dict) + +for line in sys.stdin: + if re.match('^({0})\s*=[^#]*'.format('|'.join(OPTS)), line): + option_name, _, option_value = re.split('(=|#)', line)[:3] + option_name = option_name.strip() + option_value = option_value.strip() + net_name = option_value.split(',')[0] + net_value = option_value.split(',')[1:] + if option_name in OPTS_NAMED: + try: + net_name = net_name.split(':')[1] + except: + continue + if net_name in IGNORED_NETS: + continue + if option_name == 'dhcp-range': + if net_name in IGNORED_NETS: + continue + nets[net_name].update({'dhcp_pool_start': net_value[0]}) + nets[net_name].update({'dhcp_pool_end': net_value[1]}) + nets[net_name].update({'netmask': net_value[2]}) + if option_name == 'dhcp-option': + nets[net_name].update({'dhcp_gateway': net_value[1]}) + if option_name == 'dhcp-boot': + nets[net_name].update({'ipaddress': net_value[2]}) + +###merge networks from dnsmasq with astute +astute = yaml.safe_load(open('/etc/fuel/astute.yaml')) +astute['EXTRA_ADMIN_NETWORKS'] = {} +for net in nets: + astute['EXTRA_ADMIN_NETWORKS'][net] = nets[net] + +print yaml.safe_dump(astute, default_flow_style=False) diff --git a/packages/rpm/specs/fuel-docker-images.spec b/packages/rpm/specs/fuel-docker-images.spec index 6212fc89a..d4a2c8a22 100644 --- a/packages/rpm/specs/fuel-docker-images.spec +++ b/packages/rpm/specs/fuel-docker-images.spec @@ -10,6 +10,7 @@ License: Apache 2.0 BuildRoot: %{_tmppath}/%{name}-%{version} Source0: fuel-images.tar.lrz Source1: fuel-images-sources.tar.gz +Source2: extra_nets_from_cobbler.py URL: http://mirantis.com Requires: docker-io Requires: lrzip @@ -36,9 +37,21 @@ rm -rf %{buildroot} rm -f /var/www/nailgun/docker/images/fuel-images.tar lrzip -d -o /var/www/nailgun/docker/images/fuel-images.tar /var/www/nailgun/docker/images/fuel-images.tar.lrz +if [ "$1" = "2" ]; then + #upgrade script execution + tmpfile=`mktemp /tmp/extra_nets_from_cobbler_XXXXXX.py` + cat < ${tmpfile} +%include %{SOURCE2} +EOF + umask 0177 + cp /etc/fuel/astute.yaml /etc/fuel/astute.yaml.bak + dockerctl shell cobbler cat /etc/cobbler/dnsmasq.template | python ${tmpfile} > /etc/fuel/astute.yaml.tmp + rm -f ${tmpfile} + mv /etc/fuel/astute.yaml.tmp /etc/fuel/astute.yaml +fi + %files %defattr(-,root,root) /var/www/nailgun/docker/images/fuel-images.tar.lrz /var/www/nailgun/docker/sources/* /var/www/nailgun/docker/utils/* -