change salt - getNodeProvider
Change-Id: I7e7cf6c855e1e477843f536434769147c6d07692
diff --git a/src/com/mirantis/mk/Salt.groovy b/src/com/mirantis/mk/Salt.groovy
index 5973184..a1781cf 100644
--- a/src/com/mirantis/mk/Salt.groovy
+++ b/src/com/mirantis/mk/Salt.groovy
@@ -575,12 +575,22 @@
* @param name Name of the VM (for ex. ctl01)
* @return Salt minion ID of KVM node hosting 'name' VM
*/
-def getNodeProvider(saltId, name) {
- def kvm = getKvmMinionId(saltId)
- return getReturnValues(getPillar(saltId, "${kvm}", "salt:control:cluster:internal:node:${name}:provider"))
+def getNodeProvider(saltId, nodeName) {
+ def salt = new com.mirantis.mk.Salt()
+ def common = new com.mirantis.mk.Common()
+ def kvms = salt.getMinions(saltId, 'I@salt:control')
+ for (kvm in kvms) {
+ try {
+ vms = salt.getReturnValues(salt.runSaltProcessStep(saltId, kvm, 'virt.list_domains', [], null, true))
+ if (vms.toString().contains(nodeName)) {
+ return kvm
+ }
+ } catch (Exception er) {
+ common.infoMsg("${nodeName} not present on ${kvm}")
+ }
+ }
}
-
/**
* Test if there are any minions to target
* @param saltId Salt Connection object or pepperEnv (the command will be sent using the selected method)
diff --git a/src/com/mirantis/mk/Virsh.groovy b/src/com/mirantis/mk/Virsh.groovy
index a866fa3..d972d91 100644
--- a/src/com/mirantis/mk/Virsh.groovy
+++ b/src/com/mirantis/mk/Virsh.groovy
@@ -54,17 +54,17 @@
try {
salt.cmdRun(master, "${nodeProvider}*", "virsh snapshot-delete ${target}.${domain} --metadata ${snapshotName}")
} catch (Exception e) {
- common.warningMsg('Snapshot ${snapshotName} for ${target}.${domain} does not exist or failed to be removed')
+ common.warningMsg("Snapshot ${snapshotName} for ${target}.${domain} does not exist or failed to be removed")
}
try {
salt.runSaltProcessStep(master, "${nodeProvider}*", 'file.remove', ["${path}/${target}.${domain}.${snapshotName}.qcow2"], null, true)
} catch (Exception e) {
- common.warningMsg('Snapshot ${snapshotName} qcow2 file for ${target}.${domain} does not exist or failed to be removed')
+ common.warningMsg("Snapshot ${snapshotName} qcow2 file for ${target}.${domain} does not exist or failed to be removed")
}
try {
salt.runSaltProcessStep(master, "${nodeProvider}*", 'file.remove', ["${path}/${target}.${domain}.xml"], null, true)
} catch (Exception e) {
- common.warningMsg('Dumpxml file for ${target}.${domain} does not exist or failed to be removed')
+ common.warningMsg("Dumpxml file for ${target}.${domain} does not exist or failed to be removed")
}
}
@@ -87,7 +87,7 @@
liveSnapshotAbsent(master, nodeProvider, target, snapshotName, path)
salt.runSaltProcessStep(master, "${nodeProvider}*", 'virt.start', ["${target}.${domain}"], null, true)
} catch (Exception er) {
- common.infoMsg('No rollback for ${target}.${domain} was executed. Dumpxml file not present.')
+ common.infoMsg("No rollback for ${target}.${domain} was executed. Dumpxml file not present.")
}
}
@@ -109,17 +109,17 @@
try {
salt.cmdRun(master, "${nodeProvider}*", "virsh snapshot-delete ${target}.${domain} --metadata ${snapshotName}")
} catch (Exception e) {
- common.warningMsg('Snapshot ${snapshotName} for ${target}.${domain} does not exist or failed to be removed')
+ common.warningMsg("Snapshot ${snapshotName} for ${target}.${domain} does not exist or failed to be removed")
}
try {
salt.runSaltProcessStep(master, "${nodeProvider}*", 'file.remove', ["${path}/${target}.${domain}.${snapshotName}.qcow2"], null, true)
} catch (Exception e) {
- common.warningMsg('Snapshot ${snapshotName} qcow2 file for ${target}.${domain} does not exist or failed to be removed')
+ common.warningMsg("Snapshot ${snapshotName} qcow2 file for ${target}.${domain} does not exist or failed to be removed")
}
try {
salt.runSaltProcessStep(master, "${nodeProvider}*", 'file.remove', ["${path}/${target}.${domain}.xml"], null, true)
} catch (Exception e) {
- common.warningMsg('Dumpxml file for ${target}.${domain} does not exist or failed to be removed')
+ common.warningMsg("Dumpxml file for ${target}.${domain} does not exist or failed to be removed")
}
} catch (Exception e) {
common.errorMsg("The live snapshoted VM ${target}.${domain} failed to be merged, trying to fix it")