From c93e346286938b7f972bac00d704f9e0fe80500b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= <valtri@civ.zcu.cz>
Date: Thu, 31 Dec 2020 00:59:04 +0100
Subject: [PATCH] Move all deployments into subdirectory + support none
 deployment type

---
 README.md                                             | 2 +-
 deploy.tf                                             | 2 +-
 {hadoop-hdfs => deployments/hadoop-hdfs}/ctx.yaml     | 0
 {hadoop-hdfs => deployments/hadoop-hdfs}/plugin.py    | 0
 {hadoop-hdfs => deployments/hadoop-hdfs}/site.pp.tmpl | 0
 {hadoop => deployments/hadoop}/ctx.yaml               | 0
 {hadoop => deployments/hadoop}/plugin.py              | 2 +-
 {hadoop => deployments/hadoop}/site.pp.tmpl           | 0
 deployments/none/ctx.yaml                             | 7 +++++++
 orchestrate.py                                        | 6 +++---
 10 files changed, 13 insertions(+), 6 deletions(-)
 rename {hadoop-hdfs => deployments/hadoop-hdfs}/ctx.yaml (100%)
 rename {hadoop-hdfs => deployments/hadoop-hdfs}/plugin.py (100%)
 rename {hadoop-hdfs => deployments/hadoop-hdfs}/site.pp.tmpl (100%)
 rename {hadoop => deployments/hadoop}/ctx.yaml (100%)
 rename {hadoop => deployments/hadoop}/plugin.py (95%)
 rename {hadoop => deployments/hadoop}/site.pp.tmpl (100%)
 create mode 100644 deployments/none/ctx.yaml

diff --git a/README.md b/README.md
index abf1d64..3da0c6a 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
 
 Build Hadoop cluster in OpenStack with Terraform.
 
-Primary goal of this project is to build Hadoop cluster. But the most part is generic - Hadoop deployment can be replaced by implementing different deployment type (providing user-data and optionally implementing plugin for orchestration).
+Primary goal of this project is to build Hadoop cluster. But the most part is generic - the Hadoop deployment can be skipped, or replaced by implementing different deployment type (see *deployments* directory).
 
 # Requirements
 
diff --git a/deploy.tf b/deploy.tf
index ada9f02..4cf61ab 100644
--- a/deploy.tf
+++ b/deploy.tf
@@ -12,7 +12,7 @@ data "template_file" "user_data_common" {
 }
 
 data "template_file" "user_data" {
-	template = file("${var.type}/ctx.yaml")
+	template = file("deployments/${var.type}/ctx.yaml")
 }
 
 data "template_cloudinit_config" "user_data" {
diff --git a/hadoop-hdfs/ctx.yaml b/deployments/hadoop-hdfs/ctx.yaml
similarity index 100%
rename from hadoop-hdfs/ctx.yaml
rename to deployments/hadoop-hdfs/ctx.yaml
diff --git a/hadoop-hdfs/plugin.py b/deployments/hadoop-hdfs/plugin.py
similarity index 100%
rename from hadoop-hdfs/plugin.py
rename to deployments/hadoop-hdfs/plugin.py
diff --git a/hadoop-hdfs/site.pp.tmpl b/deployments/hadoop-hdfs/site.pp.tmpl
similarity index 100%
rename from hadoop-hdfs/site.pp.tmpl
rename to deployments/hadoop-hdfs/site.pp.tmpl
diff --git a/hadoop/ctx.yaml b/deployments/hadoop/ctx.yaml
similarity index 100%
rename from hadoop/ctx.yaml
rename to deployments/hadoop/ctx.yaml
diff --git a/hadoop/plugin.py b/deployments/hadoop/plugin.py
similarity index 95%
rename from hadoop/plugin.py
rename to deployments/hadoop/plugin.py
index c018b32..b86c171 100644
--- a/hadoop/plugin.py
+++ b/deployments/hadoop/plugin.py
@@ -23,7 +23,7 @@ class ComponentHadoop:
         if action == 'files':
             if not self.args.dry_run:
                 template = None
-                with open('%s/site.pp.tmpl' % self.config['type'], 'r') as f:
+                with open('deployments/%s/site.pp.tmpl' % self.config['type'], 'r') as f:
                     template = string.Template(f.read())
                 if template:
                     print('-> site.pp')
diff --git a/hadoop/site.pp.tmpl b/deployments/hadoop/site.pp.tmpl
similarity index 100%
rename from hadoop/site.pp.tmpl
rename to deployments/hadoop/site.pp.tmpl
diff --git a/deployments/none/ctx.yaml b/deployments/none/ctx.yaml
new file mode 100644
index 0000000..174b751
--- /dev/null
+++ b/deployments/none/ctx.yaml
@@ -0,0 +1,7 @@
+#cloud-config
+
+merge_type:
+ - name: list
+   settings: [append]
+ - name: dict
+   settings: [recurse_array]
diff --git a/orchestrate.py b/orchestrate.py
index a74b103..06c7d67 100755
--- a/orchestrate.py
+++ b/orchestrate.py
@@ -55,9 +55,9 @@ user = config['image_user']
 t = config.get('type', None)
 
 print('== plugin ==')
-if t and os.path.exists('%s/plugin.py' % t):
-    print('-> %s/plugin.py' % t)
-    plugin = importlib.import_module('%s.plugin' % t)
+if t and os.path.exists('deployments/%s/plugin.py' % t):
+    print('-> deployments/%s/plugin.py' % t)
+    plugin = importlib.import_module('deployments.%s.plugin' % t)
     Component = getattr(plugin, 'Component')
     component = Component(args, config, hosts)
 else:
-- 
GitLab