Merge "Retrieving node services without ugrade condition"
diff --git a/src/com/mirantis/mk/Galera.groovy b/src/com/mirantis/mk/Galera.groovy
index d48cfc3..5a15823 100644
--- a/src/com/mirantis/mk/Galera.groovy
+++ b/src/com/mirantis/mk/Galera.groovy
@@ -17,7 +17,9 @@
  */
 
 def getWsrepParameters(env, target, parameters=[], print=false) {
-    result = []
+    def salt = new com.mirantis.mk.Salt()
+    def common = new com.mirantis.mk.Common()
+    result = [:]
     out = salt.runSaltProcessStep(env, "${target}", "mysql.status", [], null, false)
     outlist = out['return'][0]
     resultYaml = outlist.get(outlist.keySet()[0]).sort()
@@ -30,12 +32,12 @@
     if (parameters == [] || parameters == ['']) {
         result = resultYaml
     } else {
-        for (key in parameters) {
-            value = resultYaml[key]
+        for (String param in parameters) {
+            value = resultYaml[param]
             if (value instanceof String && value.isBigDecimal()) {
                 value = value.toBigDecimal()
             }
-            result = ["${key}": value] + result
+            result[param] = value
         }
     }
     return result
@@ -217,13 +219,27 @@
     }
 }
 
-def getGaleraLastShutdownNode(env) {
+/** Returns last shutdown node of Galera cluster
+@param env      Salt Connection object or pepperEnv
+@param nodes    List of nodes to check only (defaults to []). If not provided, it will check all nodes.
+                Use this parameter if the cluster splits to several components and you only want to check one fo them.
+@return status  ip address or hostname of last shutdown node
+*/
+
+def getGaleraLastShutdownNode(env, nodes = []) {
     def salt = new com.mirantis.mk.Salt()
     def common = new com.mirantis.mk.Common()
-    members = ''
+    members = []
     lastNode = [ip: '', seqno: -2]
     try {
-        members = salt.getReturnValues(salt.getPillar(env, "I@galera:master", "galera:master:members"))
+        if (nodes) {
+            nodes = salt.getIPAddressesForNodenames(env, nodes)
+            for (node in nodes) {
+                members = [host: "${node.get(node.keySet()[0])}"] + members
+            }
+        } else {
+            members = salt.getReturnValues(salt.getPillar(env, "I@galera:master", "galera:master:members"))
+        }
     } catch (Exception er) {
         common.errorMsg('Could not retrieve members list')
         return 'I@galera:master'
diff --git a/src/com/mirantis/mk/Salt.groovy b/src/com/mirantis/mk/Salt.groovy
index b1ae4a3..7688c0e 100644
--- a/src/com/mirantis/mk/Salt.groovy
+++ b/src/com/mirantis/mk/Salt.groovy
@@ -1196,3 +1196,33 @@
         return false
     }
 }
+
+/**
+* Finds out IP address of the given node or a list of nodes
+*
+* @param saltId     Salt Connection object or pepperEnv (the command will be sent using the selected method)
+* @param nodes      Targeted node hostnames to be checked (String or List of strings)
+* @param useGrains  If the, the value will be taken from grains. If false, it will be taken from 'hostname' command.
+* @return Map       Return result Map in format ['nodeName1': 'ipAdress1', 'nodeName2': 'ipAdress2', ...]
+*/
+
+def getIPAddressesForNodenames(saltId, nodes = [], useGrains = true) {
+    result = [:]
+
+    if (nodes instanceof String) {
+        nodes = [nodes]
+    }
+
+    if (useGrains) {
+        for (String node in nodes) {
+            ip = getReturnValues(getGrain(saltId, node, "fqdn_ip4"))["fqdn_ip4"][0]
+            result[node] = ip
+        }
+    } else {
+        for (String node in nodes) {
+            ip = getReturnValues(cmdRun(saltId, node, "hostname -i")).readLines()[0]
+            result[node] = ip
+        }
+    }
+    return result
+}
\ No newline at end of file