summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Holland <william.holland@codethink.co.uk>2015-09-30 22:00:06 +0100
committerWill Holland <william.holland@codethink.co.uk>2015-09-30 22:00:06 +0100
commita7a3fc9a072979785d3a8695d4b1971f60a83be6 (patch)
treeccdecbac179e5cc366770e6fe1bd358b8d268b33
parent4c9f352090f363f468f27458462c277308f2ab82 (diff)
downloadorchestration-a7a3fc9a072979785d3a8695d4b1971f60a83be6.tar.gz
Add configure which will configure pipelines
-rw-r--r--source/configure.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/source/configure.py b/source/configure.py
new file mode 100644
index 0000000..914fc43
--- /dev/null
+++ b/source/configure.py
@@ -0,0 +1,74 @@
+def fetch_config():
+ ''' fetch config from remote repo '''
+ import subprocess, os
+ # if dir exists remove it
+ if os.path.isdir('ciatconfig'):
+ subprocess.call(['rm', '-rf', 'ciatconfig'])
+ CONFIG_URL = "ssh://git@cu010-trove.codethink.com/cu010-trove/br6/ciatconfig"
+ cmd = ['git','clone',CONFIG_URL]
+ return subprocess.call(cmd)
+
+def validate_config(config,*keys):
+ ''' raise an exception if the dictionary is not as expected '''
+ for key in keys:
+ config[key]
+
+def load_slave_type_configs():
+ ''' load the slave type configs to know which slaves to connect to'''
+ import yaml, os
+ slave_types = []
+ for slavetype in os.listdir('ciatconfig/slave-types'):
+ if not slavetype.endswith('.yaml'): continue
+ with open(slavetype, 'r') as f:
+ config = yaml.load(f)
+ validate_config(config, 'name','arch')
+ slave_types.append(config)
+ return slave_types
+
+def load_pipline_configs():
+ ''' load the pipelines '''
+ import yaml, os
+ pipelines = []
+ for pipeline in os.listdir('ciatconfig/pipelines'):
+ if not pipeline.endswith('.yaml'): continue
+ with open(pipeline, 'r') as f:
+ config = yaml.load(f)
+ validate_config(config,
+ 'name',
+ 'candidate-refs',
+ 'slave-type',
+ 'clusters',
+ 'steps')
+ pipelines.append(config)
+ return pipelines
+
+def get_categories():
+ ''' given a list of pipelines, return a list of their categories '''
+ global pipelines
+ categories = []
+ for pipeline in pipelines:
+ categories += pipeline.categories
+ return categories
+
+def get_columns():
+ ''' given a list of pipelines, return a list of their categories '''
+ global pipelines
+ columns = []
+ for pipeline in pipelines:
+ columns += pipeline.columns
+ return columns
+
+def configure():
+ from ciatlib.master import pipeline_from_dict
+ global slave_types
+ global pipelines
+ fetch_exit_val = fetch_config()
+ if fetch_exit_val: exit(fetch_exit_val)
+ slave_types = load_slave_type_configs()
+ pipeline_configs = load_pipeline_config()
+ pipelines = []
+ for pipeline in pipeline_configs:
+ pipelines.append(pipeline_from_dict(pipeline))
+
+if __name__ == '__main__':
+ configure()