Add mk libraries

Change-Id: I829b299b6329e8f4d4424c89717d432513d1eece
diff --git a/src/com/mirantis/mk/ssl.groovy b/src/com/mirantis/mk/ssl.groovy
new file mode 100644
index 0000000..504e5d3
--- /dev/null
+++ b/src/com/mirantis/mk/ssl.groovy
@@ -0,0 +1,43 @@
+package com.mirantis.mk
+
+/**
+ *
+ * SSL functions
+ *
+ */
+
+/**
+ * Ensure entry in SSH known hosts
+ *
+ * @param url   url of remote host
+ */
+def ensureKnownHosts(url) {
+    uri = new URI(url)
+    port = uri.port ?: 22
+
+    sh "test -f ~/.ssh/known_hosts && grep ${uri.host} ~/.ssh/known_hosts || ssh-keyscan -p ${port} ${uri.host} >> ~/.ssh/known_hosts"
+}
+
+/**
+ * Execute command with ssh-agent
+ *
+ * @param cmd   Command to execute
+ */
+def runSshAgentCommand(cmd) {
+    sh(". ~/.ssh/ssh-agent.sh && ${cmd}")
+}
+
+/**
+ * Setup ssh agent and add private key
+ *
+ * @param credentialsId Jenkins credentials name to lookup private key
+ */
+def prepareSshAgentKey(credentialsId) {
+    c = getSshCredentials(credentialsId)
+    sh("test -d ~/.ssh || mkdir -m 700 ~/.ssh")
+    sh('pgrep -l -u $USER -f | grep -e ssh-agent\$ >/dev/null || ssh-agent|grep -v "Agent pid" > ~/.ssh/ssh-agent.sh')
+    sh("echo '${c.getPrivateKey()}' > ~/.ssh/id_rsa_${credentialsId} && chmod 600 ~/.ssh/id_rsa_${credentialsId}")
+    runSshAgentCommand("ssh-add ~/.ssh/id_rsa_${credentialsId}")
+}
+
+return this;