From 1bffa972d0759bc23d3b4ecb93fc4a43b850f6f0 Mon Sep 17 00:00:00 2001 From: alexz Date: Sun, 22 Nov 2015 20:52:15 +0200 Subject: [PATCH] utils.build: added helpers functions * rsync_inject allows to rsync custom directoies into chroot * runtime_uuid allows save runtime_uuid to yaml file Change-Id: I5ae438756823c0370b0bccfde6fb3f353315b191 Implements: blueprint dynamically-build-bootstrap --- fuel_agent/utils/build.py | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/fuel_agent/utils/build.py b/fuel_agent/utils/build.py index d7d43a9..0e854c7 100644 --- a/fuel_agent/utils/build.py +++ b/fuel_agent/utils/build.py @@ -772,3 +772,43 @@ def get_installed_packages(chroot): '-f="${Package} ${Version};;"') pkglist = filter(None, out.split(';;')) return dict([pkgver.split() for pkgver in pkglist]) + + +def rsync_inject(src, dst): + """Recursively copy the src to dst using full source paths + + Example: suppose the source directory looks like + src/etc/myconfig + src/usr/bin/myscript + + rsync_inject('src', '/tmp/chroot') + + copies src/etc/myconfig to /tmp/chroot/etc/myconfig, + and src/usr/bin/myscript to /tmp/chroot/usr/bin/myscript, + respectively + + """ + utils.makedirs_if_not_exists(os.path.dirname(dst)) + LOG.debug('Rsync files from %s to: %s', src, dst) + utils.execute('rsync', '-rlptDKv', src + '/', + dst + '/', logged=True) + + +def dump_runtime_uuid(uuid, config): + """Save runtime_uuid into yaml file + + Simple uuid variable to identify bootstrap. + Variable will be hard-coded into config yaml file, in build-time + :param uuid: + :param config: yaml file + :return: + """ + data = {} + utils.makedirs_if_not_exists(os.path.dirname(config)) + if os.path.isfile(config): + with open(config, 'r') as f: + data = yaml.load(f) + data['runtime_uuid'] = uuid + LOG.debug('Save runtime_uuid:%s to file: %s', uuid, config) + with open(config, 'wt') as f: + yaml.safe_dump(data, stream=f, encoding='utf-8')