ceph pipelines

Change-Id: Ib732e266646c5ffc8c2552198ff8b67827629fb2
diff --git a/ceph-add-node.groovy b/ceph-add-node.groovy
new file mode 100644
index 0000000..c6d2ea2
--- /dev/null
+++ b/ceph-add-node.groovy
@@ -0,0 +1,76 @@
+/**
+ *
+ * Add Ceph node to existing cluster
+ *
+ * Requred parameters:
+ *  SALT_MASTER_URL             URL of Salt master
+ *  SALT_MASTER_CREDENTIALS     Credentials to the Salt API
+ *  HOST                        Host (minion id) to be added
+ *  HOST_TYPE                   Type of Ceph node to be added. Valid values are mon/osd/rgw
+ *
+ */
+
+common = new com.mirantis.mk.Common()
+salt = new com.mirantis.mk.Salt()
+orchestrate = new com.mirantis.mk.Orchestrate()
+def python = new com.mirantis.mk.Python()
+
+def pepperEnv = "pepperEnv"
+
+node("python") {
+
+    // create connection to salt master
+    python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
+
+    matches = ["osd", "mon", "rgw"]
+    def found = false
+    for (s in matches) {
+        if (HOST_TYPE.toLowerCase() == s) {
+            found = true
+        }
+    }
+
+    if (!found) {
+            common.errorMsg("No such HOST_TYPE was found. Please insert one of these types: mon/osd/rgw")
+        break
+    }
+
+    if (HOST_TYPE.toLowerCase() != 'osd') {
+
+        // enforce crushmap `crushtool -c /etc/ceph/crushmap -o /etc/ceph/crushmap.compiled; ceph osd setcrushmap -i /etc/ceph/crushmap.compiled`
+        stage('Launch VMs') {
+            salt.enforceState(pepperEnv, 'I@salt:control', 'salt.control', true)
+
+            // wait till the HOST appears in salt-key on salt-master
+            salt.minionPresent(pepperEnv, 'I@salt:master', HOST)
+        }
+    }
+
+    // run basic states
+    stage('Install infra') {
+        orchestrate.installFoundationInfraOnTarget(pepperEnv, HOST)
+    }
+
+    if (HOST_TYPE.toLowerCase() == 'osd') {
+
+        // Install Ceph osd
+        stage('Install Ceph OSD') {
+            orchestrate.installCephOsd(pepperEnv, HOST)
+        }
+    } else if (HOST_TYPE.toLowerCase() == 'mon') {
+        // Install Ceph mon
+        stage('Install Ceph MON') {
+            salt.enforceState(pepperEnv, 'I@ceph:common', 'ceph.common', true)
+            // install Ceph Mons
+            salt.enforceState(pepperEnv, 'I@ceph:mon', 'ceph.mon', true)
+            if (salt.testTarget(pepperEnv, 'I@ceph:mgr')) {
+                salt.enforceState(pepperEnv, 'I@ceph:mgr', 'ceph.mgr', true)
+            }
+        }
+    } else if (HOST_TYPE.toLowerCase() == 'rgw') {
+        // Install Ceph rgw
+        stage('Install Ceph RGW') {
+            salt.enforceState(pepperEnv, 'I@ceph:radosgw', ['keepalived', 'haproxy', 'ceph.radosgw'], true)
+        }
+    }
+}