Joker integration and some joker fixes
This commit is contained in:
parent
ae752109dd
commit
12e6ad74e0
@ -1,6 +1,5 @@
|
|||||||
from nodes import NodesDict,Node
|
from nodes import NodesDict, Node
|
||||||
#from os import remove
|
#from os import remove
|
||||||
import os
|
|
||||||
|
|
||||||
PETYA_ENV_KEY = "-----BEGIN RSA PRIVATE KEY-----\n\
|
PETYA_ENV_KEY = "-----BEGIN RSA PRIVATE KEY-----\n\
|
||||||
MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI\n\
|
MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI\n\
|
||||||
@ -32,9 +31,10 @@ NE5OgEXk2wVfZczCZpigBKbKZHNYcelXtTt/nP3rsCuGcM4h53s=\n\
|
|||||||
|
|
||||||
#TMP_PATH="/tmp/%s"
|
#TMP_PATH="/tmp/%s"
|
||||||
|
|
||||||
|
|
||||||
class Joker():
|
class Joker():
|
||||||
|
|
||||||
def __init__(self, key = PETYA_ENV_KEY, *args, **kwargs):
|
def __init__(self, key=PETYA_ENV_KEY, *args, **kwargs):
|
||||||
|
|
||||||
self.default_key = key
|
self.default_key = key
|
||||||
|
|
||||||
@ -43,8 +43,6 @@ class Joker():
|
|||||||
self.name = "EntryPoint"
|
self.name = "EntryPoint"
|
||||||
#self.setKey()
|
#self.setKey()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# def __del__(self):
|
# def __del__(self):
|
||||||
# if (self.keyPath):
|
# if (self.keyPath):
|
||||||
# # look at this.
|
# # look at this.
|
||||||
@ -52,7 +50,7 @@ class Joker():
|
|||||||
# print "os.remove(self.keyPath)"
|
# print "os.remove(self.keyPath)"
|
||||||
|
|
||||||
def addNode(self, name, host, port, user):
|
def addNode(self, name, host, port, user):
|
||||||
self.entryPoint = Node(name, host, port);
|
self.entryPoint = Node(name, host, port)
|
||||||
self.entryPoint.assignCredential(user, self.default_key, None)
|
self.entryPoint.assignCredential(user, self.default_key, None)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -64,14 +62,28 @@ class Joker():
|
|||||||
|
|
||||||
def discover(self):
|
def discover(self):
|
||||||
result = []
|
result = []
|
||||||
discoveryData = self.entryPoint.discovery()
|
|
||||||
|
|
||||||
|
ep = self.entryPoint
|
||||||
|
discoveryData = ep.discovery()
|
||||||
|
|
||||||
for node in discoveryData:
|
for node in discoveryData:
|
||||||
result.append(self.genStub(discoveryData[node], discoveryData[node], self.default_key , "vagrant", None, "ssh -i " + "%%PATH_TO_KEY%%" + " -p " + str(self.entryPoint.accessPort) + " -q " + self.entryPoint.user + "@" + self.entryPoint.hostName + " nc -q0 " + discoveryData[node] + " 22"))
|
proxy_command = ("ssh" +
|
||||||
|
" -i %%PATH_TO_KEY%%" +
|
||||||
|
" -p {0}".format(ep.accessPort) +
|
||||||
|
" -q {0}@{1}".format(ep.user, ep.hostName) +
|
||||||
|
" nc -q0 {0} 22".format(discoveryData[node]))
|
||||||
|
|
||||||
|
result.append(
|
||||||
|
self.genStub(hostname=discoveryData[node],
|
||||||
|
ip=discoveryData[node],
|
||||||
|
port=ep.accessPort,
|
||||||
|
user="vagrant",
|
||||||
|
key=self.default_key,
|
||||||
|
proxycommand=proxy_command))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
joker = Joker(PETYA_ENV_KEY)
|
if __name__ == '__main__':
|
||||||
joker.addNode("controller1", "172.18.66.112", 2301, "vagrant");
|
joker = Joker(PETYA_ENV_KEY)
|
||||||
print joker.discover()
|
joker.addNode("controller1", "172.18.66.112", 2301, "vagrant")
|
||||||
|
print joker.discover()
|
||||||
|
@ -79,13 +79,12 @@ class Node():
|
|||||||
if self.debug is True:
|
if self.debug is True:
|
||||||
print debugData
|
print debugData
|
||||||
|
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
# install arp-scan on node
|
# install arp-scan on node
|
||||||
self.runCommand(
|
self.runCommand(
|
||||||
"[ ! -x arp-scan ] && sudo apt-get --force-yes -y install arp-scan")
|
"which arp-scan || sudo apt-get --force-yes -y install arp-scan")
|
||||||
self.setUniqData()
|
self.setUniqData()
|
||||||
self.debugLog("Unit data is " + self.getUniqData());
|
self.debugLog("Unit data is " + self.getUniqData())
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def infect(self):
|
def infect(self):
|
||||||
@ -118,13 +117,12 @@ class Node():
|
|||||||
# except SSHException:
|
# except SSHException:
|
||||||
# raise "Unknown private key format"
|
# raise "Unknown private key format"
|
||||||
|
|
||||||
|
|
||||||
def setProxyCommand(self, proxyCommand):
|
def setProxyCommand(self, proxyCommand):
|
||||||
self.proxyCommand = proxyCommand
|
self.proxyCommand = proxyCommand
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
if self.connected is True:
|
if self.connected is True:
|
||||||
raise assertionError(self.connected is True)
|
raise AssertionError(self.connected is True)
|
||||||
try:
|
try:
|
||||||
print self.hostName, " ", self.accessPort, " ", self.user, " "
|
print self.hostName, " ", self.accessPort, " ", self.user, " "
|
||||||
self.ssh.connect(self.hostName, self.accessPort, self.user,
|
self.ssh.connect(self.hostName, self.accessPort, self.user,
|
||||||
@ -143,7 +141,7 @@ class Node():
|
|||||||
|
|
||||||
def runCommand(self, command):
|
def runCommand(self, command):
|
||||||
if (command == ""):
|
if (command == ""):
|
||||||
assertionError(command == "")
|
AssertionError(command == "")
|
||||||
|
|
||||||
if (self.connected is False):
|
if (self.connected is False):
|
||||||
self.connect()
|
self.connect()
|
||||||
@ -166,7 +164,7 @@ class Node():
|
|||||||
|
|
||||||
self.__discovery__()
|
self.__discovery__()
|
||||||
for n in self.discovery_data:
|
for n in self.discovery_data:
|
||||||
( node['ip'], node['hwaddr'], _) = n.split("\t")
|
(node['ip'], node['hwaddr'], _) = n.split("\t")
|
||||||
self.neighbours[node['hwaddr']] = node['ip']
|
self.neighbours[node['hwaddr']] = node['ip']
|
||||||
|
|
||||||
self.neighbours[self.getUniqData()] = self.hostName
|
self.neighbours[self.getUniqData()] = self.hostName
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
|
import tempfile
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -71,6 +72,15 @@ class NodeClient(object):
|
|||||||
private_key=None, proxy_command=None):
|
private_key=None, proxy_command=None):
|
||||||
super(NodeClient, self).__init__()
|
super(NodeClient, self).__init__()
|
||||||
self.use_sudo = (username != 'root')
|
self.use_sudo = (username != 'root')
|
||||||
|
|
||||||
|
if proxy_command and proxy_command.find('%%PATH_TO_KEY%%') != -1:
|
||||||
|
self._pkey_file = tempfile.NamedTemporaryFile(suffix='.key')
|
||||||
|
self._pkey_file.write(private_key)
|
||||||
|
self._pkey_file.flush()
|
||||||
|
|
||||||
|
proxy_command = proxy_command.replace('%%PATH_TO_KEY%%',
|
||||||
|
self._pkey_file.name)
|
||||||
|
|
||||||
sock = paramiko.ProxyCommand(proxy_command) if proxy_command else None
|
sock = paramiko.ProxyCommand(proxy_command) if proxy_command else None
|
||||||
|
|
||||||
self.shell = SshShell(
|
self.shell = SshShell(
|
||||||
@ -80,6 +90,7 @@ class NodeClient(object):
|
|||||||
password=password,
|
password=password,
|
||||||
private_key=private_key,
|
private_key=private_key,
|
||||||
missing_host_key=spur.ssh.MissingHostKey.accept,
|
missing_host_key=spur.ssh.MissingHostKey.accept,
|
||||||
|
connect_timeout=5,
|
||||||
sock=sock)
|
sock=sock)
|
||||||
|
|
||||||
def run(self, command, *args, **kwargs):
|
def run(self, command, *args, **kwargs):
|
||||||
@ -148,12 +159,22 @@ class JokerNodeDiscovery(object):
|
|||||||
j = joker.Joker(default_key=private_key)
|
j = joker.Joker(default_key=private_key)
|
||||||
count = 0
|
count = 0
|
||||||
for node in parse_nodes_info(initial_nodes):
|
for node in parse_nodes_info(initial_nodes):
|
||||||
j.add_node('node%d' % count,
|
j.addNode('node%d' % count,
|
||||||
node['host'],
|
node['host'],
|
||||||
node['port'],
|
node['port'],
|
||||||
node['username'])
|
node['username'])
|
||||||
|
|
||||||
nodes = j.discover()
|
nodes = []
|
||||||
|
for j_node_info in j.discover():
|
||||||
|
node = dict(
|
||||||
|
name=j_node_info['name'],
|
||||||
|
host=j_node_info['ip'],
|
||||||
|
port=j_node_info['port'],
|
||||||
|
username=j_node_info['user'],
|
||||||
|
private_key=j_node_info['key'],)
|
||||||
|
# proxy_command=j_node_info['proxy_command'])
|
||||||
|
node = dict((k, v) for k, v in node.iteritems() if v)
|
||||||
|
nodes.append(node)
|
||||||
|
|
||||||
return nodes
|
return nodes
|
||||||
|
|
||||||
@ -164,7 +185,7 @@ python_re = re.compile('(/?([^/]*/)*)python[0-9.]*')
|
|||||||
class OpenstackDiscovery(object):
|
class OpenstackDiscovery(object):
|
||||||
logger = logging.getLogger('rubick.discovery')
|
logger = logging.getLogger('rubick.discovery')
|
||||||
|
|
||||||
node_discovery_klass = SimpleNodeDiscovery
|
node_discovery_klass = JokerNodeDiscovery
|
||||||
|
|
||||||
def test_connection(self, initial_nodes, private_key):
|
def test_connection(self, initial_nodes, private_key):
|
||||||
d = self.node_discovery_klass()
|
d = self.node_discovery_klass()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user