#!/usr/bin/env python

import os
import sys
import yaml

workdir = os.environ.get('WORKDIR', '/tmp/nodepool')
main = 'nodepool.yaml'
images = 'images.yaml'
labels = 'labels.yaml'


def merge():
    conf = yaml.safe_load(file(os.path.join(workdir, main), 'r'))
    images_conf = yaml.safe_load(file(os.path.join(workdir, images), 'r'))
    labels_conf = yaml.safe_load(file(os.path.join(workdir, labels), 'r'))

    for provider in images_conf:
        for defined_provider in conf['providers']:
            if provider['provider'] == defined_provider['name']:
                defined_provider['images'] = provider['images']

    conf['labels'] = labels_conf['labels']
    return yaml.dump(conf, default_flow_style=False)


if __name__ == '__main__':
    if len(sys.argv) < 2:
        print "Please provide the target filename"
        sys.exit(1)
    else:
        try:
            out = merge()
        except Exception as err:
            print err
            sys.exit(1)

        file(os.path.join(workdir, sys.argv[1]), 'w').write(out)

@@ -404,16 +404,177 @@
  'r'))%0A%0A
+    for defined_provider in conf%5B'providers'%5D:%0A        # This makes sure all defined providers have an 'images' section%0A        defined_provider%5B'images'%5D = %5B%5D%0A%0A
     for 

fix adding new providers